SPARQL endpoint
The Nomenclature SPARQL query editor allows exploration of the dataset and output in a variety of formats.
The queries listed below are provided as examples to get you started using SPARQL. Find a query in the list and click Try the query to open it in the SPARQL endpoint. From there, you can modify it as needed and click Run to launch the query.
- 1 Concept hierarchy
- 2 Concept creation and modification dates
- 3 Sources and contributors
- 4 Image References
- 5 Labels
- 6 Notes and definitions
- 7 Full-Text Search (FTS)
- 8 Counting
1 Concept hierarchy
1.1 Top concepts (Categories)
Find the top-level concepts (Categories) of Nomenclature. This query returns concepts that include property skos:topConceptOf and displays the ID and the preferred terms ( skos:prefLabel ).
SELECT ?id ?prefLabel {
?id skos:topConceptOf nom: ;
skos:prefLabel ?prefLabel
FILTER(lang(?prefLabel)= "en")
}
ORDER BY ?prefLabel
1.2 Top 3 Levels
Hierarchy relations are expressed with skos:narrower (linking a concept to its child concepts) and with skos:broader (linking a concept to its single parent concept). This query returns the Nomenclature Categories (top-level concepts), their classes (second-level concepts), and their subclasses (third-level concepts), and displays the ID as well as the preferred term (skos:prefLabel).
SELECT * {
?id skos:topConceptOf nom: ;
skos:prefLabel ?prefLabel;
skos:narrower ?idLv2.
?idLv2 skos:prefLabel ?prefLabelLv2;
skos:narrower ?idLv3.
?idLv3 skos:prefLabel ?prefLabelLv3
FILTER(lang(?prefLabel)= "en" && lang(?prefLabelLv2)= "en" && lang(?prefLabelLv3)= "en")
}
ORDER BY ?prefLabel
1.3 Direct children of a concept
This query returns the children (direct conenction only) for a single Nomenclature concept, e.g. nom:12838 (Category 08: Communication Objects). It returns the children URIs and their preferred terms in English and French (each concept is guaranteed to have exactly one English and one French preferred term).
SELECT * {
?id skos:broader nom:12838; skos:prefLabel ?prefLabelEn, ?prefLabelFr.
FILTER(lang(?prefLabelEn) = 'en')
FILTER(lang(?prefLabelFr) = 'fr')
}
1.4 All descendants of a concept
This query returns all descendants (direct and indirect children) of a single Nomenclature concept, e.g. nom:12838 (Category 08: Communication Objects). The property path uses inverse ( ^ ) and multiple occurrences ( + ) of skos:broader. It returns the descendant URIs and their preferred terms.
SELECT * {
nom:12838 (^skos:broader)+ ?descendant.
?descendant skos:prefLabel ?prefLabel.
FILTER(lang(?prefLabel) = 'en')
}
1.5 All concepts hierarchical display
This query can be used to display all of the Nomenclature hierarchy, for example in a browse interface. The display is sorted hierarchically by preferred term (from Category to Tertiary term), in ascending alphabetical order. By default this query includes English terms displayed in inverted order, but it can be altered to display other languages or natural order.
To try this query, copy and paste the text below into the SPARQL endpoint.
PREFIX nom: <https://nomenclature.info/nom/>
PREFIX nomo: <https://nomenclature.info/nom/ontology/>
PREFIX nomLang: <https://nomenclature.info/nom/lang/>
PREFIX nomLevel: <https://nomenclature.info/nom/level/>
PREFIX luc: <http://www.ontotext.com/connectors/lucene#>
PREFIX luc-index: <http://www.ontotext.com/connectors/lucene/instance#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT
?category
?class
?subclass
?primaryTerm
?secondaryTerm
?tertiaryTerm
{
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 6 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL{?invLabelUri nomo:invertedFormOf ?prefLabelUri; skosxl:literalForm ?invLabel}
BIND(COALESCE(?invLabel,?prefLabel) AS ?tertiaryTerm)
?id skos:broader ?parent1.
?parent1 skosxl:prefLabel ?parentLabelUri1.
?parentLabelUri1 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel1 .
OPTIONAL{?invParentLabelUri1 nomo:invertedFormOf ?parentLabelUri1; skosxl:literalForm ?invParentLabel1}
BIND(COALESCE(?invParentLabel1,?parentLabel1) AS ?secondaryTerm)
?parent1 skos:broader ?parent2.
?parent2 skosxl:prefLabel ?parentLabelUri2.
?parentLabelUri2 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel2 .
OPTIONAL{?invParentLabelUri2 nomo:invertedFormOf ?parentLabelUri2; skosxl:literalForm ?invParentLabel2}
BIND(COALESCE(?invParentLabel2,?parentLabel2) AS ?primaryTerm)
?parent2 skos:broader ?parent3.
?parent3 skosxl:prefLabel ?parentLabelUri3.
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4.
?parent4 skosxl:prefLabel ?parentLabelUri4.
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5.
?parent5 skosxl:prefLabel ?parentLabelUri5.
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 5 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL{?invLabelUri nomo:invertedFormOf ?prefLabelUri; skosxl:literalForm ?invLabel}
BIND(COALESCE(?invLabel,?prefLabel) AS ?secondaryTerm)
?id skos:broader ?parent2.
?parent2 skosxl:prefLabel ?parentLabelUri2.
?parentLabelUri2 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel2 .
OPTIONAL{?invParentLabelUri2 nomo:invertedFormOf ?parentLabelUri2; skosxl:literalForm ?invParentLabel2}
BIND(COALESCE(?invParentLabel2,?parentLabel2) AS ?primaryTerm)
?parent2 skos:broader ?parent3.
?parent3 skosxl:prefLabel ?parentLabelUri3.
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4.
?parent4 skosxl:prefLabel ?parentLabelUri4.
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5.
?parent5 skosxl:prefLabel ?parentLabelUri5.
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 4 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL{?invLabelUri nomo:invertedFormOf ?prefLabelUri; skosxl:literalForm ?invLabel}
BIND(COALESCE(?invLabel,?prefLabel) AS ?primaryTerm)
?id skos:broader ?parent3.
?parent3 skosxl:prefLabel ?parentLabelUri3.
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4.
?parent4 skosxl:prefLabel ?parentLabelUri4.
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5.
?parent5 skosxl:prefLabel ?parentLabelUri5.
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 3 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?id skos:broader ?parent4.
?parent4 skosxl:prefLabel ?parentLabelUri4.
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5.
?parent5 skosxl:prefLabel ?parentLabelUri5.
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 2 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?class .
?id skos:broader ?parent5.
?parent5 skosxl:prefLabel ?parentLabelUri5.
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{?id skos:inScheme nom:;
skosxl:prefLabel ?prefLabelUri; schema:isPartOf/schema:position 1 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?category .
}
}
ORDER BY ?category ?class ?subclass ?primaryTerm ?secondaryTerm ?tertiaryTerm
2 Concept creation and modification dates
Concept creation date is expressed with dct:created and concept modification date is expressed with dct:modified.
2.1 Last modified concept
This query returns the most recently modified concept. This can include new concepts as well as concepts that have had any significant (e.g. change to preferred terms) or insignificant change (e.g. typo fix in a definition). The query returns the concept ID, modification date, and preferred term.
SELECT * {
?id a skos:Concept;
dct:modified ?modifDate;
skos:prefLabel ?prefLabel.
FILTER(lang(?prefLabel) = "en")
}
ORDER BY DESC(?modifDate)
LIMIT 1
2.2 Count modified concepts
This query counts concepts that were modified since their creation. This includes concepts that have had any significant (e.g. change to preferred terms) or insignificant change (e.g. typo fix in a definition).
SELECT (COUNT(?modifDate) AS ?count) {
[] a skos:Concept;
dct:created ?creationDate;
dct:modified ?modifDate
FILTER(?modifDate > ?creationDate)
}
2.3 Count created and modified concepts per year
This query counts the number of new concepts as well as modified concepts and groups them by year. This can include new concepts or concepts that have had any significant (e.g. change to preferred terms) or insignificant change (e.g. typo fix in a definition).
SELECT ?year (COUNT(?modified) AS ?countModified) (COUNT(?created) AS ?countCreated) {
{
?modified a skos:Concept;
dct:modified ?modifDate
BIND( year(?modifDate) AS ?year )
}
UNION
{
?created a skos:Concept;
dct:created ?creationDate
BIND( year(?creationDate) AS ?year )
}
}
GROUP BY ?year
ORDER BY ?year
2.4 All changes within a date range
This query returns new concepts and existing concepts that have had any kind of modification This query returns new concepts and existing concepts that have had any significant (e.g. change to preferred terms) or insignificant change (e.g. typo fix in a definition) between e.g. January 1, 2018 and December 31, 2021. It returns the concept ID, preferred term, and latest modification date.
SELECT * {
?id a skos:Concept;
dct:modified ?modifDate;
skos:prefLabel ?prefLabel.
FILTER(lang(?prefLabel) = "en")
FILTER(?modifDate >= "2018-01-01T00:00:00"^^xsd:dateTime && ?modifDate <= "2021-12-31T23:59:59"^^xsd:dateTime)
}
ORDER BY DESC(?modifDate)
2.5 Significant changes within a date range
This query returns new concepts, moved concepts, merged concepts, deprecated concepts, and concepts that have had changes to their preferred term in any language between two dates, e.g. July 26, 2018 and December 31, 2021. It returns the ID, preferred term, change type, change details, and modification date.
SELECT ?id ?prefLabel ?revisionType ?desc ?modifDate {
VALUES (?revisionType) {
("Addition - Concept"@en)
("Deletion - Concept"@en)
("Move"@en)
("Merge"@en)
("Addition - Preferred term"@en)
("Deletion - Preferred term"@en)
("Update - Preferred term"@en)
}
?id a skos:Concept;
rdfs:label ?prefLabel;
skos:changeNote ?revision.
?revision rdfs:label ?revisionType;
dc:description ?desc;
cs:createdDate ?modifDate.
FILTER(?modifDate >= "2018-07-26T00:00:00"^^xsd:dateTime && ?modifDate <= "2021-12-31T23:59:59"^^xsd:dateTime)
FILTER(lang(?prefLabel)="en")
FILTER(lang(?revisionType)="en")
FILTER(lang(?desc)="en")
}
ORDER BY DESC(?modifDate)
3 Sources and contributors
3.1 Term sources
This query returns the term sources for all preferred terms in Nomenclature. Each term source is listed only once. It displays the Zotero link, full citation, count, and term source URI.
SELECT (COUNT(*) AS ?count) ?termSource ?zotero ?biblio
{
?id skosxl:prefLabel/schema:citation ?termSource.
?termSource schema:url ?zotero;
dct:bibliographicCitation ?biblio.
FILTER(lang(?biblio) = "en")
}
GROUP BY ?termSource ?zotero ?biblio
3.2 Term contributors
This query returns the term contributors for all preferred terms in Nomenclature. Each term contributor is listed only once. It returns the number of contributors, their URI, names in English and French, and nicknames.
SELECT (COUNT(*) AS ?count) ?contrib ?nameEn ?nameFr ?nickname
{
?id skosxl:prefLabel/dct:contributor ?contrib.
?contrib foaf:name ?nameEn,?nameFr;
foaf:nick ?nickname.
FILTER(lang(?nameEn) = "en")
FILTER(lang(?nameFr) = "fr")
}
GROUP BY ?contrib ?nameEn ?nameFr ?nickname
3.3 Bibliographic citations
This query returns all bibliographic citations for all concepts. It returns the citation, concept ID, and bibliographic citation ID.
SELECT * {
?id schema:citation ?citation
OPTIONAL{?citation dct:bibliographicCitation ?biblio FILTER(lang(?biblio)="en")}
}
3.4 Definition sources
This query returns the sources of a definition. It displays the Zotero link and full citation, as well as returns the count and definition source URI.
SELECT (COUNT(*) AS ?count) ?defSource ?zotero ?biblio
{
?id skos:definition/schema:citation ?defSource.
?defSource schema:url ?zotero;
dct:bibliographicCitation ?biblio.
FILTER(lang(?biblio) = "en")
}
GROUP BY ?defSource ?zotero ?biblio
4 Image References
4.1 Count images
This query returns the number of images found in Nomenclature.
SELECT (COUNT(*) AS ?images) {[] a skos:Concept; schema:image []}
4.2 Count concepts with images
This query returns the number of concepts in Nomenclature that include images.
SELECT (COUNT(?id) AS ?concepts)
{
?id a skos:Concept;
schema:image/schema:position 1.
}
4.3 Images for a concept
This query returns all images associated with a concept, e.g. nom:11695 (blimp). It returns the preferred term, URL of the image, original URL of the image source, and credit line for the image.
SELECT * {
nom:11695 schema:image ?imageUri;
skos:prefLabel ?prefLabel.
?imageUri a schema:ImageObject;
schema:contentUrl ?image;
schema:creditText ?imageSource;
dct:source ?imageOriginal.
FILTER(lang(?prefLabel) = "en")
}
5 Labels
5.1 Concepts search by label
This query returns concepts whose preferred term contains a string, e.g. "wagon" (case insensitive). It displays the concept ID and label.
However, the REGEX() and CONTAINS() functions are inefficient. They should only be used for exploratory querying and especially not in the backend of a production system. In such cases, use full-text search (FTS) instead; see the section 07 below.
SELECT ?id ?prefLabel
{
?id skos:prefLabel ?prefLabel .
FILTER(REGEX(?prefLabel,"wagon","i"))
}
5.2 Any term (and parent)
This query returns all concepts, in all languages, with preferred terms, alternative terms, and hidden terms (in any language) containing a string, e.g. "cabinet" (case insensitive). It displays the concept ID, preferred terms, alternative terms, hidden terms, and parents’ preferred terms in all languages.
SELECT * {
?id skos:prefLabel|skos:altLabel|skos:hiddenLabel ?anyLabel;
skos:prefLabel ?prefLabel;
skos:broader/skos:prefLabel ?broaderLabel
FILTER(REGEX(?anyLabel,"cabinet","i"))
FILTER(lang(?prefLabel) = 'en' && lang(?broaderLabel) = 'en')
}
5.3 Labels by language
This query returns what languages are used in structured labels (skosxl:Label) and their frequency.
SELECT ?lang (COUNT(*) AS ?count) {
[] a skosxl:Label;
dct:language/skos:notation ?lang
} GROUP BY ?lang ORDER BY DESC(?count)
5.4 Inverted and natural form (using custom property)
This query returns the inverted and natural forms of Nomenclature terms containing a string, e.g. "struct" (case insensitive). This query uses the custom property nomo:invertedFormOf (as opposed to dct:type as in the query below). In order to provide a comprehensive list of search results, single-word terms are included even though these are not included in nomo:invertedFormOf. The inverted form can be found in both English and Canadian English. Inverted forms are available for the bottom three levels (primary, secondary, and tertiary terms), but are not included for the top three levels (categories, classes, and subclasses). The query displays the concept ID, natural order term, and inverted order term.
SELECT ?id ?natural ?inverted {
?id skosxl:prefLabel ?prefLabel .
?prefLabel skosxl:literalForm ?natural .
OPTIONAL{
?altLabel nomo:invertedFormOf ?prefLabel ;
skosxl:literalForm ?inverted .
}
FILTER(CONTAINS(LCASE(?natural), "struct"))
FILTER(langMatches(lang(?natural),'en'))
}
5.5 Inverted and natural form (using dct:type)
This query returns the inverted and natural forms of Nomenclature terms containing a string, e.g. "struct" (case insensitive). An alternative term ( altLabel ) that has the type (dct:type) "inverted term" (aat:300404672) is the inverted form of the preferred term ( prefLabel ). In order to provide a comprehensive list of search results, single-word terms are included even though these are not tagged as "inverted terms". The inverted form can be found in both English and Canadian English. Inverted forms are available for the bottom three levels (primary, secondary, and tertiary terms), but are not included for the top three levels (categories, classes, and subclasses). Note that, compared to the previous solution, this query requires the users control for the language of the inverted terms. This query displays the concept ID, natural order term, and inverted order term.
SELECT ?id ?natural ?inverted {
?id skosxl:prefLabel ?prefLabel .
?prefLabel skosxl:literalForm ?natural .
OPTIONAL{
?id skosxl:altLabel ?altLabel .
?altLabel dct:type aat:300404672;
skosxl:literalForm ?inverted .
FILTER(langMatches(lang(?inverted),'en'))
}
FILTER(CONTAINS(LCASE(?natural), "struct"))
FILTER(langMatches(lang(?natural),'en'))
}
5.6 Inverted form, Canadian variant
This query returns Nomenclature terms containing a string, e.g. "armo" (case insensitive). An alternative term (altLabel) that has the type (dct:type) "inverted term" (aat:300404672) is the inverted form of the preferred term (prefLabel). In order to provide a comprehensive list of search results, the English term is included when there is no Canadian English term, and single-word terms are included even though these are not tagged "inverted term". Inverted forms are available for the bottom three levels (primary, secondary, and tertiary terms), but are not included for the top three levels (categories, classes, and subclasses). The query displays concept ID, term, level, and level name.
SELECT distinct ?id ?display ?levelNum ?levelName
{
?id skos:inScheme nom:;
skos:prefLabel|skos:altLabel|skos:hiddenLabel ?anyLabel;
skos:prefLabel ?prefEn;
schema:isPartOf ?level.
FILTER(REGEX(?anyLabel,"armo","i"))
?level schema:position ?levelNum;
skos:prefLabel ?levelName.
FILTER(lang(?levelName) = "en")
FILTER(lang(?prefEn) = "en")
OPTIONAL{
?id skos:prefLabel ?prefEnCa
FILTER(lang(?prefEnCa) = "en-ca")
}
OPTIONAL{
?id skosxl:altLabel ?alt.
?alt dct:type aat:300404672;
skosxl:literalForm ?invEnCa .
FILTER(lang(?invEnCa) = "en-ca")
}
OPTIONAL{
?id skosxl:altLabel ?alt.
?alt dct:type aat:300404672;
skosxl:literalForm ?invEn .
FILTER(lang(?invEn) = "en")
}
BIND(COALESCE(?invEnCa,?prefEnCa,?invEn,?prefEn) AS ?display)
BIND(str(?display) AS ?literal)
} ORDER BY ?literal
5.7 Labels by language
This query returns all preferred terms in Canadian English (en-CA). It returns the ID and preferred term.
SELECT * {
?id skos:prefLabel ?prefLabel.
FILTER(langMatches(lang(?prefLabel), "en-CA"))
}
This query can be modified to search for preferred terms in any language:
enfor English (International) (mandatory): beware, this will return a lot of conceptsen-CAfor English (Canadian) (optional)frfor French (International) (mandatory): beware, this will return a lot of conceptsfr-CAfor French (Canadian) (optional)crfor Cree (Syllabics) (optional)cr-Latnfor Cree (Latin script) (optional)iufor Inuktitut (Syllabics) (optional)iu-Latnfor Inuktitut (Latin script) (optional)esfor Spanish (optional)
6 Notes and definitions
6.1 Scope notes
This query searches for scope notes that contain a string, e.g. "dress", and returns the ID, preferred term, parent, and note.
SELECT * {
?id skos:scopeNote ?scopeNote;
skos:prefLabel ?prefLabel;
skos:broader ?parent.
FILTER(lang(?scopeNote) = 'en' && CONTAINS(LCASE(?scopeNote), "dress"))
FILTER(lang(?prefLabel) = 'en')
}
6.2 Definitions
This query searches for definitions that contain a string, e.g. "dress", and returns the ID, preferred term, parent, and definition.
SELECT * {
?id skos:prefLabel ?prefLabel;
skos:broader ?parent;
skos:definition ?def.
?def dct:language nomLang:en;
rdf:value ?value.
FILTER(CONTAINS(LCASE(?value), "dress"))
FILTER(lang(?prefLabel) = 'en')
}
6.3 Scope notes and definitions
This query searches for scope notes or definitions that contain a string, e.g. "dress", and returns the ID, preferred term, parent, note, definition, and URIs.
SELECT * {
{
?id skos:scopeNote ?scopeNote;
skos:prefLabel ?prefLabel;
skos:broader ?parent.
FILTER(lang(?scopeNote) = "en" && CONTAINS(LCASE(?scopeNote), "dress"))
} UNION {
?id skos:definition ?def;
skos:prefLabel ?prefLabel;
skos:broader ?parent .
?def rdf:value ?defText .
FILTER(lang(?defText) = "en" && CONTAINS(LCASE(?defText), "dress"))
}
FILTER(lang(?prefLabel)="en")
}
6.4 skos:notation
This query searches for the skos:notation (Parks Canada Descriptive and Visual Dictionary code) e.g. "02-00147", and returns the ID, preferred term, and parent.
SELECT * {
?id skos:notation "02-00147".
?id dc:identifier ?conceptId;
skos:prefLabel ?prefLabel;
skos:broader ?parent.
FILTER(lang(?prefLabel) = "en")
}
6.5 All data about a concept
This complex query returns all data about a concept, e.g. nom:1090 (chair). It returns sub-objects representing structured labels, structured definitions, structured position (the number determining the position of the concept within the hierarchy), images, etc. It also includes concept revisions (skos:changeNote) but not the detailed data about these revisions.
describe ?id ?relatedId {
BIND(nom:1090 AS ?id)
?id schema:position|skosxl:prefLabel|skosxl:altLabel|skos:definition|schema:image ?relatedId
}
7 Full-Text Search (FTS)
While searching for strings in a text is possible using pure SPARQL functions such as CONTAINS() and REGEX() , it is not recommended to do this in a production system because this operation is extremely ineffective. First, it would need to retrieve from the database all the text fields, and then, against each of which, it would apply the search criterion.
Instead, the use of Jena Full Text Search (available only in English) is recommended. This extension to ARQ combines SPARQL and full text search via Lucene. It gives applications the ability to perform indexed full text searches within SPARQL queries. The full text search indexes the required textual fields, as well as quickly and efficiently matches them against a user query.
The query string syntax conforms to the underlying Lucene (available only in English), nested in a SPARQL query.
The URI of the text extension property function is http://jena.apache.org/text#query, more conveniently written as:
PREFIX text: <http://jena.apache.org/text#>
... text:query ...
Syntax
The following forms are all legal:
?s text:query 'word' # query
?s text:query ('word' 10) # with limit on results
?s text:query (rdfs:label 'word') # query specific property if multiple
?s text:query (rdfs:label 'protégé' 'lang:fr') # restrict search to French
(?s ?score) text:query 'word' # query capturing also the score
(?s ?score ?literal) text:query 'word' # ... and original literal value
(?s ?score ?literal ?g) text:query 'word' # ... and the graph
Query search words are case insensitive (e.g. "Chair" matches "chair" and vice versa). UPPERCASE is reserved for boolean operators such as AND and OR . The default behaviour for multi-term queries is to search for any of the search terms. For example, the search query medical chair will find all concepts containing either the term "medical" or "chair"; however, concepts that include both terms will be ranked higher.
Using the operator AND(e.g.medical AND chair) will search for both terms. Always surround the query string with ( ) if more than a single term or phrase are involved.
Phrase search is performed using quotes around the desired sequence. For example, the search query "medical chair" will search for exactly these two terms in this order. Don't forget that the search query is embedded in SPARQL, so you need to escape the quotes (e.g.''' "medical chair" ''').
Wildcard queries search for parts of terms (e.g. *brace* , will match "orthopedic brace", "vambrace", and "bracelet").
Many more advanced queries are possible. Refer to the section on query syntax in the Lucene documentation.
7.1 FTS indexes
The following properties are indexed:
skos:prefLabel (default)skos:altLabelskos:hiddenLabelskos:scopeNoteskos:definition/rdf:value
7.2 FTS by preferred term
This FTS query searches for a string in luc-index:prefLabel index, e.g. "chair". It returns concept ID and preferred term.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel
{
?id text:query "chair" ;
a skos:Concept, schema:CreativeWork, crm:E55_Type ;
skos:prefLabel ?prefLabel .
FILTER(lang(?prefLabel)="en")
}
7.3 FTS for all labels
This FTS query searches in all labels index (preferred, alternative, and hidden terms), for a string, e.g. "chair". It returns the concept ID, preferred terms, original literal value, and score.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel ?literal ?score
{
(?id ?score ?literal) text:query (skos:prefLabel skos:altLabel skos:hiddenLabel "chair") .
?id a skos:Concept, schema:CreativeWork, crm:E55_Type ;
skos:prefLabel ?prefLabel .
FILTER(lang(?prefLabel)="en")
}
Note that this query returns more results than the previous one because it searches in more fields.
7.4 FTS for all text
This FTS query searches in all text index for a string, e.g. "chair". It returns the concept ID, preferred terms, definition, note, original literal value, and score.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel ?definition ?scopeNote ?literal ?score
{
{
(?id ?score ?literal) text:query (skos:prefLabel skos:altLabel skos:hiddenLabel skos:scopeNote "chair") .
?id a skos:Concept, schema:CreativeWork, crm:E55_Type .
}
UNION
{
(?def ?score ?literal) text:query (rdf:value "chair") .
?id skos:definition ?def .
}
?id skos:prefLabel ?prefLabel .
FILTER(lang(?prefLabel)="en")
OPTIONAL {
?id skos:definition/rdf:value ?definition .
FILTER(lang(?definition)="en")
}
OPTIONAL {
?id skos:scopeNote ?scopeNote .
FILTER(lang(?scopeNote)="en")
}
}
This query returns even more results than the two previous queries, as it searches most text fields: altLabel , hiddenLabel , and definition .
7.5 FTS phrase query
This phrase query searches for a particular sequence of terms in the text, e.g. “child’s chair”. The query string should be quoted in double quotes. Note how backward slash is used to escape the double quotes.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel ?literal ?score
{
(?id ?score ?literal) text:query (skos:prefLabel "\"child's chair\"") .
?id a skos:Concept, schema:CreativeWork, crm:E55_Type ;
skos:prefLabel ?prefLabel .
FILTER(lang(?prefLabel)="en")
}
Please note that Nomenclature also includes inverted terms as altLabel , e.g. "chair, child's", so that phrase search can be done with skos:altLabel.
7.6 Combined FTS and RDF search
This query combines the graph structure and the FTS index. It is very useful as it allows to combine the speed and efficiency of the FTS with all the information in the structure of the Knowledge Graph
For example, assuming that most chairs are in "Category 02: Furnishings" ( nom:967 ), it might be interesting to search for chairs outside of that category.
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX nom: <https://nomenclature.info/nom/>
PREFIX nomLevel: <https://nomenclature.info/nom/level/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel ?literal ?categoryLabel
{
{
(?id ?score ?literal) text:query (skos:prefLabel skos:altLabel skos:hiddenLabel skos:scopeNote "chair") .
?id a skos:Concept, schema:CreativeWork, crm:E55_Type .
}
UNION
{
(?def ?score ?literal) text:query (rdf:value "chair") .
?id skos:definition ?def .
}
?id skos:prefLabel ?prefLabel ;
skos:broader+ ?category .
nomLevel:1 skos:member ?category .
?category skos:prefLabel ?categoryLabel .
FILTER(?category != nom:967) # Category 02: Furnishings
FILTER(lang(?prefLabel)="en")
FILTER(lang(?categoryLabel)="en")
}
The query allows us to find concepts such as "altar chair" (nom:13109) and "electric chair" (nom:10051).
7.7 FTS by preferred term, sorted case insensitively
In auto-complete applications, user input is often treated in a case-insensitive way. The FTS index includes all terms lower-cased and stemmed, so it already takes care of case-insensitive processing in FILTERing. The results should also be sorted in a case-insensitive way. Here is an example query:
PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX text: <http://jena.apache.org/text#>
SELECT ?id ?prefLabel
{
?id text:query "chair" ;
a skos:Concept, schema:CreativeWork, crm:E55_Type ;
skos:prefLabel ?prefLabel .
FILTER(lang(?prefLabel)="en")
}
ORDER BY ASC(LCASE(?prefLabel))
7.8 Search result hierarchical display
This query searches for a string (e.g. “chair”) and displays the search result hierarchically by preferred term (from Category to Tertiary term), in ascending alphabetical order. By default this query includes English terms displayed in inverted order, but it can be altered to display other languages or natural order.
To try this query, copy and paste the text below into the SPARQL endpoint (opens in a new window).
PREFIX nom: <https://nomenclature.info/nom/>
PREFIX nomo: <https://nomenclature.info/nom/ontology/>
PREFIX nomLang: <https://nomenclature.info/nom/lang/>
PREFIX nomLevel: <https://nomenclature.info/nom/level/>
PREFIX text: <http://jena.apache.org/text#>
PREFIX schema: <http://schema.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX skosxl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT
?category
?class
?subclass
?primaryTerm
?secondaryTerm
?tertiaryTerm
{
VALUES ?q {"chair"}
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 6 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL {
?invLabelUri nomo:invertedFormOf ?prefLabelUri ;
skosxl:literalForm ?invLabel
}
BIND(COALESCE(?invLabel, ?prefLabel) AS ?tertiaryTerm)
?id skos:broader ?parent1 .
?parent1 skosxl:prefLabel ?parentLabelUri1 .
?parentLabelUri1 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel1 .
OPTIONAL {
?invParentLabelUri1 nomo:invertedFormOf ?parentLabelUri1 ;
skosxl:literalForm ?invParentLabel1
}
BIND(COALESCE(?invParentLabel1, ?parentLabel1) AS ?secondaryTerm)
?parent1 skos:broader ?parent2 .
?parent2 skosxl:prefLabel ?parentLabelUri2 .
?parentLabelUri2 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel2 .
OPTIONAL {
?invParentLabelUri2 nomo:invertedFormOf ?parentLabelUri2 ;
skosxl:literalForm ?invParentLabel2
}
BIND(COALESCE(?invParentLabel2, ?parentLabel2) AS ?primaryTerm)
?parent2 skos:broader ?parent3 .
?parent3 skosxl:prefLabel ?parentLabelUri3 .
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4 .
?parent4 skosxl:prefLabel ?parentLabelUri4 .
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5 .
?parent5 skosxl:prefLabel ?parentLabelUri5 .
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 5 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL {
?invLabelUri nomo:invertedFormOf ?prefLabelUri ;
skosxl:literalForm ?invLabel
}
BIND(COALESCE(?invLabel, ?prefLabel) AS ?secondaryTerm)
?id skos:broader ?parent2 .
?parent2 skosxl:prefLabel ?parentLabelUri2 .
?parentLabelUri2 dct:language nomLang:en ;
skosxl:literalForm ?parentLabel2 .
OPTIONAL {
?invParentLabelUri2 nomo:invertedFormOf ?parentLabelUri2 ;
skosxl:literalForm ?invParentLabel2
}
BIND(COALESCE(?invParentLabel2, ?parentLabel2) AS ?primaryTerm)
?parent2 skos:broader ?parent3 .
?parent3 skosxl:prefLabel ?parentLabelUri3 .
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4 .
?parent4 skosxl:prefLabel ?parentLabelUri4 .
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5 .
?parent5 skosxl:prefLabel ?parentLabelUri5 .
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 4 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?prefLabel .
OPTIONAL {
?invLabelUri nomo:invertedFormOf ?prefLabelUri ;
skosxl:literalForm ?invLabel
}
BIND(COALESCE(?invLabel, ?prefLabel) AS ?primaryTerm)
?id skos:broader ?parent3 .
?parent3 skosxl:prefLabel ?parentLabelUri3 .
?parentLabelUri3 dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?parent3 skos:broader ?parent4 .
?parent4 skosxl:prefLabel ?parentLabelUri4 .
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5 .
?parent5 skosxl:prefLabel ?parentLabelUri5 .
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 3 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?subclass .
?id skos:broader ?parent4 .
?parent4 skosxl:prefLabel ?parentLabelUri4 .
?parentLabelUri4 dct:language nomLang:en ;
skosxl:literalForm ?class .
?parent4 skos:broader ?parent5 .
?parent5 skosxl:prefLabel ?parentLabelUri5 .
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 2 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?class .
?id skos:broader ?parent5 .
?parent5 skosxl:prefLabel ?parentLabelUri5 .
?parentLabelUri5 dct:language nomLang:en ;
skosxl:literalForm ?category .
}
UNION
{
?id text:query (skos:prefLabel skos:altLabel skos:hiddenLabel ?q) ;
skos:inScheme nom: ;
skosxl:prefLabel ?prefLabelUri ;
schema:isPartOf/schema:position 1 .
?prefLabelUri dct:language nomLang:en ;
skosxl:literalForm ?category .
}
}
ORDER BY ?category ?class ?subclass ?primaryTerm ?secondaryTerm ?tertiaryTerm
8 Counting
Counting resources of a particular type in the graph is traditionally done using the COUNT() SPARQL aggregation function (see the next query). However, this is inefficient and should never be used in a production system with a high load.
For this reason, the important counts have been pre-computed and stored in the semantic dataset description (the VOID graph). This graph is available at https://nomenclature.info/.well-known/voidand is loaded in the repository for online querying. Further queries will display pre-computed counts by using so-called "partitions" (subsets of triples of the dataset).
8.1 Count entities per type
This query counts the number of entities per rdf:type. It returns all the types present in the repository.
SELECT (COUNT(*) AS ?count) ?type {
?e rdf:type ?type .
}
GROUP BY ?type
ORDER BY DESC(?count)
8.2 Count concepts
This query displays the number of concepts (from VOID).
SELECT * {
<https://nomenclature.info/dataset> void:classPartition [ void:class skos:Concept;
void:entities ?conceptsCount ]
}
8.3 Count images
This query displays the number of images (from VOID).
SELECT * {
<https://nomenclature.info/dataset> void:classPartition [ void:class schema:ImageObject;
void:entities ?imagesCount ]
}
8.4 Count terms
This query displays the number of terms (labels) (from VOID).
SELECT * {
<https://nomenclature.info/dataset> void:classPartition [ void:class skosxl:Label;
void:entities ?termsCount ]
}
8.5 Count terms by language
This query displays how many terms there are for each language (from VOID). It uses the VOID Extensions ontology ( vext: ).
SELECT * {
<https://nomenclature.info/dataset> vext:languagePartition [ vext:language ?lang;
void:triples ?termsCount ]
}
8.6 Count co-references per domain
This query displays how many co-references are present (from VOID). It uses class void:Linkset. The count is broken down by target dataset and void:linkPredicate (exactMatch or closeMatch). void:target lists both datasets that are linked (<https://nomenclature.info/dataset> and the external dataset), but only the external one is returned to avoid clutter.
SELECT * {
?linkset a void:Linkset;
rdfs:label ?linksetLabel;
void:linkPredicate ?linkPredicate;
void:triples ?triplesCount;
void:target ?dataset
FILTER(?dataset != <https://nomenclature.info/dataset>)
# ?dataset rdfs:label ?datasetLabel FILTER(lang(?datasetLabel)="en")
} ORDER BY DESC(?triplesCount)
8.7 Count deprecated concepts
This query returns the number of deprecated concepts (from VOID).
SELECT * {
<https://nomenclature.info/dataset> void:propertyPartition
[void:property owl:deprecated; void:triples ?deprecatedCount]
}