SPARQL filter language if possible in multiple value context

后端 未结 1 1728
一生所求
一生所求 2021-01-26 23:16

Consider the following extract from the GeoNames database :

@prefix gn:     .
@prefix rdfs:  

        
相关标签:
1条回答
  • 2021-01-27 00:01

    You can start with a query like this that finds name values and partitions them into French names and default (i.e., non-French) names:

    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             |
    --------------------------------------------------------------------------------------------------
    

    That's a start, but sample and coalesce don't seem to work the way we'd want here. E.g., we can't do coalesce(sample(?frenchName),sample(?defaultName)) to get a single name.

    0 讨论(0)
提交回复
热议问题