views:

112

answers:

3

I have this query. It match anything which has "South in its Name". But I only want the one whose foaf:name exactly matches "South"
SELECT Distinct ?TypeLabel Where { ?a foaf:name "South". ?a rdf:type ?Type. ?Type rdfs:label ?TypeLabel. }

+2  A: 

That query should match exactly the literal South and not literals merely containing South as a substring. For partial matches you'd go to FILTER with e.g. REGEX(). Your query engine is broken in this sense - which query engine you are working with?

laalto
Agreed. Something's gone badly wrong.
I am using http://dbpedia.org/snorql. it breaks if we use regex. Given query does not match exactly. Try "Imran Khan" instead of "South" and display matching foaf:names it will also return results like "Imran Khan Niazy".
Taz
as this is DBPedia it's running on Virtuoso under the hood and they no doubt have some of their free text search features turned on - it may not be standard SPARQL behaviour but Virtuoso's SPARQL implementation ain't exactly standard
RobV
+2  A: 

(Breaking out of comments for this)

The issue is the data, not your query. If you search for:

SELECT Distinct ?a Where { ?a foaf:name "Imran Khan". }

You find (as you say) "Imran Khan Niazy". But looking at http://dbpedia.org/snorql/?describe=http://dbpedia.org/resource/Imran_Khan you'll see both:

foaf:name "Imran Khan Niazy"

and

foaf:name "Imran Khan"

(rdf allows repeated use of properties)

"South" had the same issue (album, artist, and oddly 'South Luton'). These are cases where there are both familiar names ("Imran Khan", "South"), and more precise names ("Imran Khan Niazy", "South (album)") for the purposes of correctness or disambiguation.

If you want a more precise match try adding a type (e.g. http://dbpedia.org/ontology/MusicalWork for the album). Be aware that dbpedia derives from wikipedia, and the extraction process isn't perfect. This is an area alive with wonky data, so don't assume your query has gone wrong.

A: 

Hi, a bit late but anyway... I think this is what your looking for:

SELECT Distinct ?TypeLabel Where { 
?a foaf:name ?name . 
?a rdf:type ?Type . 
?Type rdfs:label ?TypeLabel . 
FILTER (?name="South"^^xsd:string)
}

you can use FILTER with the xsd types in order to restrict the result. hope this helps... cheers!

Lucas de Oliveira