Consider the following extract from the GeoNames database :
@prefix gn: <http://www.geonames.org/ontology#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://sws.geonames.org/690791/>
a gn:Feature ;
gn:featureClass gn:A ;
gn:featureCode gn:A.PCLI ;
gn:alternateName "Україна"@uk , "ܐܘܟܪܢܝܐ"@arc , "Ուկրաինա"@hy , "ウクライナ"@ja , "Úkraína"@is;
gn:name "Ukraine" ;
gn:officialName "Ucraína"@gl , "Ukraine"@fr , "U-crai-na (Ukraine)"@vi , "ཡུ་ཀརེན།"@bo.
So, I'm trying to get the name in a specif language, for example fr
and if it's not available fall back to the default. Moreover, this name can come from any of the three predicates: gn:alternateName
, gn:name
and gn:officialName
.
So for example, for this sample, I expect to recover
----------------
| name |
================
| "Ukraine"@fr |
----------------
But with my current solution :
PREFIX gn: <http://www.geonames.org/ontology#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?name
WHERE {
values ?nameBearing { gn:name gn:alternateName gn:officialName}
values ?countryfc { gn:A.PCLI gn:A.PCLD gn:A.PCLIX }
?loc gn:featureCode ?countryfc;
OPTIONAL
{
?loc ?nameBearing ?nameFR
FILTER(langMatches(lang(?nameFR), "fr"))
}
OPTIONAL
{
?loc ?nameBearing ?nameOTHER
FILTER(langMatches(lang(?nameOTHER), ""))
}
BIND(COALESCE(?nameFR, ?nameOTHER) AS ?name)
}
I get
----------------
| name |
================
| "Ukraine" |
| |
| "Ukraine"@fr |
----------------
probably because the way multiple values for a predicate is evaluated in SPARQL.
So is there any way to "group by ?loc
" and get only values in one language?