SPARQL select optional with language

后端 未结 3 1467
礼貌的吻别
礼貌的吻别 2021-02-07 04:08

I have some triples that look like this:

test:thing rdfs:label \"Non-Language Label\"
test:thing rdfs:label \"English Label\"@en
test:thing rdfs:label \"French L         


        
3条回答
  •  有刺的猬
    2021-02-07 04:29

    The easiest way to check the language of literals is to use the lang() function. Using this, your query can be written as:

    PREFIX rdfs:  
    PREFIX test:  
    SELECT ?label ?preferredLabel 
    WHERE { 
       test:thing rdfs:label ?label 
       OPTIONAL { 
         test:thing rdfs:label ?preferredLabel . 
         FILTER (lang(?preferredLabel) = "" || lang(?preferredLabel) = "fr") 
       } 
    }
    

提交回复
热议问题