rdfskos

How to do the concept search in SKOS?


I created an ontology using SKOS and it includes two concepts, concept1 and concept2. And I added one preferred label Temperature Sensor, and three alternative labels Temperature@en, Temp@en and T@en into the concept1.

What I expect is when I send a request to a target concept containing Temp, T or Temperature, the SKOS will respond with a same concept Temperature Sensor (which are defined in preferred label).

How can I achieve this? Is it possible to achieve this using SKOS? Part of rdf file is shown as below.

<skos:Concept rdf:about="TemperatureSensor">    
<skos:altLabel xml:lang="en">T</skos:altLabel>    
<skos:altLabel xml:lang="en">Temp</skos:altLabel>    
<skos:altLabel xml:lang="en">Temperature</skos:altLabel>     
<skos:prefLabel xml:lang="en">TemperatureSensor</skos:prefLabel>      
<skos:inScheme rdf:resource="conceptSchemeSensors"/></skos:Concept>

Solution

  • The data you provided isn't complete; it's missing some prefix declarations, and it uses relative IRIs but doesn't define a base IRI. Here's some complete data we can use:

    <rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:skos="http://www.w3.org/2004/02/skos/core#">
      <skos:Concept rdf:about="http://stackoverflow.com/q/27958866/1281433/TemperatureSensor">
        <skos:altLabel xml:lang="en">T</skos:altLabel>
        <skos:altLabel xml:lang="en">Temp</skos:altLabel>
        <skos:altLabel xml:lang="en">Temperature</skos:altLabel>
        <skos:prefLabel xml:lang="en">TemperatureSensor</skos:prefLabel>
        <skos:inScheme rdf:resource="http://stackoverflow.com/q/27958866/1281433/conceptSchemeSensors"/>
      </skos:Concept>
    </rdf:RDF>
    

    Here's a SPARQL query that we can run over that same data. It retrieves all the concepts, their preferred labels, and their alternative labels. Then it uses coalesce to take any of the preferred labels, and if there are none of those, any of the alternative labels for the concept.

    prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    prefix skos:  <http://www.w3.org/2004/02/skos/core#>
    prefix : <http://stackoverflow.com/q/27958866/1281433/>
    
    select ?concept (coalesce(sample(?prefLabel),sample(?altLabel)) as ?label) where {
      ?concept skos:altLabel ?altLabel ;
               skos:prefLabel ?prefLabel .
    }
    group by ?concept
    
    -----------------------------------------------
    | concept            | label                  |
    ===============================================
    | :TemperatureSensor | "TemperatureSensor"@en |
    -----------------------------------------------