SPARQL选择带语言的可选 [英] SPARQL select optional with language

查看:89
本文介绍了SPARQL选择带语言的可选的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些如下所示的三元组:

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 Label"@fr

我想形成一个sparql查询,该查询为我提供非语言标签"和法语标签"(如果有的话).

I'd like to form a sparql query that gives me the "Non-Language Label" AND the "French Label", if any exists.

我尝试了此操作,但不起作用:

I tried this and it's not working:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
SELECT ?label ?preferredLabel
WHERE {
   test:thing rdfs:label ?label 
   OPTIONAL {
     test:thing rdfs:label ?preferredLabel . 
     FILTER (regex(str(?preferredLabel), '(^|\\\\W)fr', 'i'))
   }
}

提前谢谢!

推荐答案

在这里我根本看不到为什么需要OPTIONAL. Jan的查询失败,因为外部模式与可选模式之间没有共享变量,因此您正在尝试计算test:thing的每个标签与每个标记为test:thing的非/法语的叉积,这可能会很大,以及为什么查询处理器出现故障.

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: <http://www.w3.org/2000/01/rdf-schema#> 
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: <http://www.w3.org/2000/01/rdf-schema#> 
SELECT ?label ?preferredLabel
WHERE 
{
  {
   test:thing rdfs:label ?label . FILTER(LANG(?label) = "")
  }
  UNION
  {
   test:thing rdfs:label ?preferredLabel . FILTER(LANGMATCHES(LANG(?label), "fr"))
  }
}

这篇关于SPARQL选择带语言的可选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆