SPARQL 选择可选语言
我有一些如下所示的三元组:
test:thing rdfs:label "Non-Language Label"
test:thing rdfs:label "English Label"@en
test:thing rdfs:label "French Label"@fr
我想形成一个 sparql 查询,为我提供“非语言标签”和“法语标签”(如果存在)。
我试过了,但不起作用:
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'))
}
}
提前致谢!
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
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'))
}
}
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我根本不明白为什么你需要
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 fortest:thing
with every non/french labelledtest: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
If you want the two labels separately then you could do something like:
检查文字语言的最简单方法是使用 lang() 函数。使用它,您的查询可以写为:
The easiest way to check the language of literals is to use the lang() function. Using this, your query can be written as: