Search code examples
apachesparqlrdfrdfsfuseki

SPARQL query to find only one value using the attribute


I need to get the only the English value from my rdfs:label tag

Here is my sample RDF

<rdfs:label rdf:datatype="&xsd;string">English</rdfs:label>
<rdfs:label xml:lang="fr">French</rdfs:label>
<rdfs:label xml:lang="it">Italy</rdfs:label>

I am currently using Apache Jena Fuseki server to perform the SPARQL query. When I tried to get the rdfs:label it return me all three values.

Thanks in advance


Solution

  • You can filter by the language tag you desire in your result. A couple of ways to do this in SPARQL:

    SELECT ?label
    WHERE {
       ?s rdfs:label ?label .
       FILTER (lang(?label) = "en")
    }
    

    ...or use SPARQL's langMatches:

    SELECT ?label
    WHERE {
       ?s rdfs:label ?label .
       FILTER langMatches(lang(?label), "en")
    }