Consider the following excerpt 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 a name in a specific language, for example fr, and if it is not available, it returns to default. Moreover, the name may have come from any of the three predicates: gn:alternateName, gn:nameand gn:officialName.
So for example, for this example, I expect recovery
| 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 plural value method for a predicate is evaluated in SPARQL.
So, is there a way to "group by ?loc" and get only values in one language?