SPARQL filter lang 'en' gives other languages

Funmatica picture Funmatica · Sep 11, 2012 · Viewed 14.5k times · Source

The following SPARQL query doesn't get the results I want because they are in other languages than English, regardless of the filter lang 'en' (see filters in query).

Results of the query :

"Никола́й Ива́нович Буха́рин"@en    "Никола́й Буха́рин"@en  "Nikolai Bukharin"@en
"Gamal Abdel Nasser Hussein"@en     "جمال عبد الناصر"@en    "Gamal Abdel Nasser"@en

I looked at the DBpedia page and I saw that there is the English version of the names, but I don't see why the filter doesn't work !!!

Can someone help me with that ?

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/property/>
SELECT DISTINCT ?person ?birthname ?nameExact ?label
where {

     ?person rdf:type dbpedia-owl:Person .
     ?person rdfs:label ?label .
     OPTIONAL { ?person dbpedia-owl:birthName ?birthname . }
     OPTIONAL { ?person dbpprop:name ?nameExact . }

     FILTER (lang(?birthname) = 'en')
     FILTER (lang(?label) = 'en')
     FILTER (lang(?nameExact) = 'en')

}
LIMIT 300

Answer

user6312556 picture user6312556 · May 10, 2016

Be carefull to prefixes you must use the same in declaration and query (dbo -> dbo, not dbo -> dbpedia-owl)

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>

SELECT DISTINCT ?person ?birthname ?nameExact ?label
where {

     ?person rdf:type dbo:Person .
     ?person rdfs:label ?label .
     OPTIONAL { ?person dbo:birthName ?birthname . }
     OPTIONAL { ?person dbp:name ?nameExact . }

     FILTER (lang(?birthname) = 'en')
     FILTER (lang(?label) = 'en')
     FILTER (lang(?nameExact) = 'en')

}

LIMIT 300