DBpedia SPARQL Querying for a specific rdfs:label
Asked Answered
I

2

11

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'" .
}
Ichthyic answered 20/1, 2012 at 22:20 Comment(0)
M
16

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)
}
Molybdenous answered 21/1, 2012 at 0:50 Comment(1)
I believe your first query has the triple pattern duplicated.Lonilonier
C
7

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

Callous answered 24/3, 2016 at 2:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.