10

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'" .
}
Ben Companjen
  • 1,305
  • 9
  • 24
Sam
  • 1,231
  • 2
  • 12
  • 16

2 Answers2

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)
}
ip.
  • 3,126
  • 5
  • 29
  • 41
6

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

guerda
  • 21,229
  • 25
  • 89
  • 139
scotthenninger
  • 3,613
  • 1
  • 12
  • 23