This query returns all terms of a given ontology or vocabulary, irrespective of their type. A term is included if its URI starts with the ontology's namespace or if it declares to be part of the ontology. Only the most recent non-invalidated defining nanopublication is shown per term.
Get the terms of an ontology including via namespace
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix dct: <http://purl.org/dc/terms/> prefix np: <http://www.nanopub.org/nschema#> prefix npa: <http://purl.org/nanopub/admin/> prefix npx: <http://purl.org/nanopub/x/> prefix skos: <http://www.w3.org/2004/02/skos/core#> select ?term (coalesce(min(?labelPlain), min(?labelAny)) as ?term_label) ?class (replace(replace(str(?class), "^.*[/#]", ""), "[_-]", " ") as ?class_label) (coalesce(min(?desc), min(?def), min(?comment)) as ?description) ?np ("^" as ?np_label) where { { select ?term (max(?date) as ?latest) where { { graph npa:graph { ?introNp npx:introduces ?term . filter(strlen(?__ontologyNamespace) > 0 && strstarts(str(?term), ?__ontologyNamespace)) } } union { values ?_ontology_multi_iri {} graph ?introA { ?term dct:isPartOf|dct:partOf ?_ontology_multi_iri . } graph npa:graph { ?introNp np:hasAssertion ?introA ; npx:introduces ?term . } } graph npa:graph { ?introNp npa:hasValidSignatureForPublicKeyHash ?introKey ; dct:created ?date . filter not exists { ?introInv npx:invalidates ?introNp ; npa:hasValidSignatureForPublicKeyHash ?introKey . } } } group by ?term } graph npa:graph { ?np npx:introduces ?term ; dct:created ?latest ; np:hasAssertion ?a ; npa:hasValidSignatureForPublicKeyHash ?pubkey . filter not exists { ?inv npx:invalidates ?np ; npa:hasValidSignatureForPublicKeyHash ?pubkey . } } optional { graph ?a { ?term a ?class . } } optional { graph ?a { ?term rdfs:label ?labelPlain . filter(lang(?labelPlain) = "") } } optional { graph ?a { ?term rdfs:label ?labelAny . } } optional { graph ?a { ?term skos:definition ?def . } } optional { graph ?a { ?term dct:description ?desc . } } optional { graph ?a { ?term rdfs:comment ?comment . } } } group by ?term ?class ?np order by ?class ?term_label