Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DBpedia SPARQL Querying for a specific rdfs:label

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'" .
}
like image 263
Sam Avatar asked Jan 20 '12 22:01

Sam


2 Answers

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)
}
like image 197
ip. Avatar answered Oct 28 '22 23:10

ip.


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.)

like image 41
scotthenninger Avatar answered Oct 28 '22 21:10

scotthenninger