DBpedia SPARQL Querying for a specific rdfs:label

11k views Asked by At

Basically I have a query (shown below) which works efficiently. However, I want my search to be more precise where the label is the actual string 'yago' rather than containing the string 'yago'. I want to try to do it without filters if possible as I think using FILTER makes querying DBpedia take longer.

SELECT ?uri ?label 
WHERE {
?uri rdfs:label ?label.
?label bif:contains "'yago'" .
}
2

There are 2 answers

1
ip. On

You can try doing the following if you want to do it without filters:

SELECT ?uri ?label
WHERE {
?uri rdfs:label "Yago"@en .
?uri rdfs:label ?label
}

I not sure though it if it is much faster than the corresponding query with filters:

SELECT ?uri ?label
WHERE {
?uri rdfs:label ?label .
filter(?label="Yago"@en)
}
0
scotthenninger On

A key correction to the original response. If you have an exact match, with the language label, then the following will work:

SELECT ?uri ?label
WHERE {
   ?uri rdfs:label "Yago"@en .
}

If, however, the exact match may not be using what you want, SPARQL supports a standard regex:

SELECT ?uri ?label
WHERE {
   ?uri rdfs:label ?label .
   FILTER regex(str(?label), "yago", "i")
}

...which will match the string regardless of character case, and you can play the usual regex games to get the required string match. (Of course, other string functions, such as STRSTARTS and STRENDS will be more efficient if those meet the desired matching criteria.)