SPARQL filter language, if possible, in a multi-value context

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?

+1
source share
1

, ( ):

prefix gn:    <http://www.geonames.org/ontology#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

select ?s ?name ?frenchName ?defaultName where {
  values ?name { gn:alternateName gn:name gn:officialName }
  ?s ?name ?name_
  bind(if(langMatches(lang(?name_),"fr"),?name_,?undef) as ?frenchName)
  bind(if(langMatches(lang(?name_),"fr"),?undef,?name_) as ?defaultName)
}
--------------------------------------------------------------------------------------------------
| s                                 | name             | frenchName   | defaultName              |
==================================================================================================
| <http://sws.geonames.org/690791/> | gn:alternateName |              | "Úkraína"@is             |
| <http://sws.geonames.org/690791/> | gn:alternateName |              | "ウクライナ"@ja               |
| <http://sws.geonames.org/690791/> | gn:alternateName |              | "Ուկրաինա"@hy            |
| <http://sws.geonames.org/690791/> | gn:alternateName |              | "ܐܘܟܪܢܝܐ"@arc            |
| <http://sws.geonames.org/690791/> | gn:alternateName |              | "ї"@uk             |
| <http://sws.geonames.org/690791/> | gn:name          |              | "Ukraine"                |
| <http://sws.geonames.org/690791/> | gn:officialName  |              | "ཡུ་ཀརེན།"@bo            |
| <http://sws.geonames.org/690791/> | gn:officialName  |              | "U-crai-na (Ukraine)"@vi |
| <http://sws.geonames.org/690791/> | gn:officialName  | "Ukraine"@fr |                          |
| <http://sws.geonames.org/690791/> | gn:officialName  |              | "Ucraína"@gl             |
--------------------------------------------------------------------------------------------------

, , . , coalesce (sample (? FrenchName), sample (? DefaultName)), .

& hellip;

+1

All Articles