Skip to main content

Examples for Thesaurus Services

Abstract

Examples for Thesaurus Services

In this section you can find some query templates that can be used or adapted to be used in your application code. You can test the queries with the SPARQL endpoint of one of your projects. We show examples for the following methods:

Get Labels

Query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT ?label
WHERE {
  { <$CONCEPT_URI> skos:prefLabel ?label.} UNION
  { <$CONCEPT_URI> skos:altLabel ?label.} UNION
  { <$CONCEPT_URI> skos:hiddenLabel ?label.}
  FILTER (lang(?label) ="$LANGUAGE")
}
Parameters:
  • $CONCEPT_URI- The URI of the concept to get the labels of.

  • $LANGUAGE - The ISO code for the language of the requested labels.

    If you want to retrieve all labels in all languages, just leave out the FILTER block:

    FILTER (lang(?label) ="$LANGUAGE")
Returns:
  • A list containing all labels of the concept as RDF literals (along with the language information for each label).

Get Definitions

Query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT ?definition
WHERE {
  <$CONCEPT_URI> skos:definition ?definition.
  FILTER (lang(?definition) ="$LANGUAGE")
}
Parameters:
  • $CONCEPT_URI- The URI of the concept to get the definitions of.

  • $LANGUAGE - The ISO code for the language of the requested definition.

    If you want to retrieve all definitions in all languages, just leave out the FILTER block:

    FILTER (lang(?definition) ="$LANGUAGE")
Returns:
  • A list containing all labels of the concept as RDF literals (along with the language information for each label).

Get Relations

Query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
  <$CONCEPT_URI> ?relation ?concept.
FILTER (?relation = skos:broader || ?relation = skos:narrower || ?relation = skos:related )
}
Parameters:
  • $CONCEPT_URI - The URI of the concept to get the semantic relations of.

Returns:
  • A row for each semantic relation of this concept containing the URI of the target concept and the URI of the relation.

Get Top Concepts

Query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT *
WHERE {
  <$CONCEPT_SCHEME_URI> skos:hasTopConcept ?concept.
}
Parameters:
  • $CONCEPT_SCHEME_URI - The URI of the concept scheme to get all top concepts of.

Returns:
  • A list containing the URIs of all top concepts.

Get Concept Suggestions

Query:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?concept ?searchLabel
WHERE {
  { ?concept skos:prefLabel ?searchLabel. } UNION
  { ?concept skos:altLabel ?searchLabel. }
  FILTER (regex(str(?searchLabel), "$LABEL_FRAGMENT", "i"))
  FILTER (lang(?searchLabel) = "$LANGUAGE")
} LIMIT 10
Parameters:
  • $LABEL_FRAGMENT - A String which shall be contained in a label.

  • $LANGUAGE - The language of the labels the suggestion shall be restricted to.

    If you want to retrieve all definitions in all languages, just leave out the FILTER block:

    FILTER (lang(?searchLabel) ="$LANGUAGE")
Returns:
  • A row for each suggestion with the URI of the concept and the label that matched the $LABEL-FRAGMENT parameter

This method is good for autocomplete i.e. to suggest a user possibly matching concepts while he is typing.