SPARQL select optional with language

后端 未结 3 1471
礼貌的吻别
礼貌的吻别 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:42

    I don't see why you need OPTIONAL here at all. Jan's query is failing because there is no shared variable between the outer pattern and the optional so you are trying to calculate the cross product of every label for test:thing with every non/french labelled test:thing which may be huge and why the query processor is failing.

    You simply want something like the following unless I've misunderstood your question

    PREFIX rdfs:  
    SELECT ?label
    WHERE 
    {
       test:thing rdfs:label ?label 
       FILTER(LANG(?label) = "" || LANGMATCHES(LANG(?label), "fr"))
    }
    

    If you want the two labels separately then you could do something like:

    PREFIX rdfs:  
    SELECT ?label ?preferredLabel
    WHERE 
    {
      {
       test:thing rdfs:label ?label . FILTER(LANG(?label) = "")
      }
      UNION
      {
       test:thing rdfs:label ?preferredLabel . FILTER(LANGMATCHES(LANG(?label), "fr"))
      }
    }
    

提交回复
热议问题