This query returns the use cases (categories) declared for a given entity (a Space or Maintained Resource), together with the concrete examples attached to each use case. Only the latest valid version of each use case definition is considered.
Get use cases with examples for a resource
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix dct: <http://purl.org/dc/terms/> prefix schema: <http://schema.org/> prefix np: <http://www.nanopub.org/nschema#> prefix npa: <http://purl.org/nanopub/admin/> prefix npx: <http://purl.org/nanopub/x/> prefix gen: <https://w3id.org/kpxl/gen/terms/> prefix nt: <https://w3id.org/np/o/ntemplate/> select ?usecase ?usecase_label ?comment ?topic ?topic_label ?examples_multi_iri ?examples_label_multi (?usecase as ?usecase_ref) ?np ("^" as ?np_label) where { { select ?usecase (iri(strafter(max(concat(str(?date), " ", str(?np0))), " ")) as ?np) where { graph npa:graph { ?np0 npx:hasNanopubType gen:UseCase . ?np0 npa:hasValidSignatureForPublicKeyHash ?pubkey . filter not exists { ?npi npx:invalidates ?np0 ; npa:hasValidSignatureForPublicKeyHash ?pubkey . } filter not exists { ?np0 npx:hasNanopubType npx:ExampleNanopub . } ?np0 dct:created ?date . ?np0 np:hasAssertion ?a0 . } values ?_entity_multi_iri {} graph ?a0 { ?usecase rdfs:subClassOf gen:UseCase . ?usecase gen:isUseCaseFor ?_entity_multi_iri . } } group by ?usecase } graph npa:graph { ?np np:hasAssertion ?a . ?np np:hasPublicationInfo ?pi . } optional { graph ?a { ?usecase rdfs:label ?usecase_label . } } optional { graph ?a { ?usecase rdfs:comment ?comment . } } optional { graph ?a { ?usecase schema:about ?topic . } } optional { graph ?pi { ?topic nt:hasLabelFromApi ?topic_label . } } optional { { select ?usecase (group_concat(str(?example); separator=" ") as ?examples_multi_iri) (group_concat(?exlabel_esc; separator="\n") as ?examples_label_multi) where { { select ?usecase ?example (coalesce(min(?exl), str(?example)) as ?exlabel) where { graph npa:graph { ?exnp npx:hasNanopubType gen:UseCase . ?exnp npa:hasValidSignatureForPublicKeyHash ?expubkey . filter not exists { ?exnpi npx:invalidates ?exnp ; npa:hasValidSignatureForPublicKeyHash ?expubkey . } filter not exists { ?exnp npx:hasNanopubType npx:ExampleNanopub . } ?exnp np:hasAssertion ?exa . } graph ?exa { ?example rdf:type ?usecase . } optional { graph ?exa { ?example rdfs:label ?exl . } } } group by ?usecase ?example } bind(replace(replace(str(?exlabel), "\\\\", "\\\\\\\\"), "[\r\n]+", "\\\\n") as ?exlabel_esc) } group by ?usecase } } } order by ?usecase_label