How to match exact string literals in SPARQL?

I have this request. It corresponds to everything that has "South" in its name. But I need only one whose foaf:nameprecisely "south".

SELECT Distinct ?TypeLabel 
WHERE
{
    ?a     foaf:name   "South" .
    ?a     rdf:type    ?Type .
    ?Type  rdfs:label  ?TypeLabel .
}
+3
source share
3 answers

(Breaking comments for this)

Data problems

The problem is the data, not your request. If you use the following query:

SELECT DISTINCT ?a 
WHERE { 
    ?a foaf:name "Imran Khan" . 
}

You find (as you say) "Imran Khan Nezy". But looking at the dbpedia entry for Imran Khan , you will see both:

foaf:name "Imran Khan Niazy"
foaf:name "Imran Khan"

This is because RDF allows you to reuse properties.

Cause

"" (, " " ). , ( "-", "" ) ( " ", " ()" ) .

, (, http://dbpedia.org/ontology/MusicalWork ).

, DBpedia , . , , .

+4

, ... , , :

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

FILTER xsd, . ... !

+4

This query must match literal South, not literals, containing Southas a substring. For partial matches, you go to FILTER, for example. REGEX(). In this sense, your query engine is broken - what query engine are you working with?

+3
source

Source: https://habr.com/ru/post/1740132/


All Articles