选择查询内的 SPARQL 实体列表

发布于 2024-09-03 16:48:05 字数 945 浏览 6 评论 0原文

在下面的 DBpedia 查询中,有没有办法将 UNION 合并为单个模式?

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  {res:Spain prop:language ?language} 
    UNION
  {res:France prop:language ?language}
    UNION
  {res:Italy prop:language ?language}
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

SPARQL 规范 提到了一些有关 RDF 集合的内容,但我没有真正理解它所描述的内容。看起来以下语法应该有效,但事实并非如此。

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  (res:Spain res:France res:Italy) prop:language ?language
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

有没有办法在 SELECT 查询中定义像这样的 URI 列表(或“多重集”或“包”)?

In the following DBpedia query, is there a way to consolidate the UNIONs into a single pattern?

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  {res:Spain prop:language ?language} 
    UNION
  {res:France prop:language ?language}
    UNION
  {res:Italy prop:language ?language}
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

The SPARQL spec mentions something about RDF collections but I don't really understand what it's describing. It seemed like the following syntax should work, but it didn't.

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  (res:Spain res:France res:Italy) prop:language ?language
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

Is there a way to define a list (or "multiset", or "bag") of URIs like this inside a SELECT query?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

束缚m 2024-09-10 16:48:05

在SPARQL 1.1中你可以做

SELECT DISTINCT ?language ?label 
WHERE {
  ?country prop:language ?language .
  ?language rdfs:label ?label .
  VALUES ?country { res:Spain res:France res:Italy }
  FILTER langMatches(lang(?label), "en") 
}

In SPARQL 1.1 you can do

SELECT DISTINCT ?language ?label 
WHERE {
  ?country prop:language ?language .
  ?language rdfs:label ?label .
  VALUES ?country { res:Spain res:France res:Italy }
  FILTER langMatches(lang(?label), "en") 
}
硪扪都還晓 2024-09-10 16:48:05

简单的回答:不。

(res:Spain res:France res:Italy) prop:language ?language

表示“包含西班牙、法国和意大利的列表具有语言的匹配”,即列表本身具有语言。

你可以这样做:

?country prop:language ?language . ?language rdfs:label ?label . 
FILTER ( ?country == res:Spain || ?country == res:France || ?country == res:Italy )

这更短,但可能更慢。

(我感觉 SPARQL 1.1 有一个“IN”功能,但我在草稿中没有看到它)

Simple answer: no.

(res:Spain res:France res:Italy) prop:language ?language

means 'match where a list containing Spain, France and Italy has a language', i.e. the list itself has a language.

You could do:

?country prop:language ?language . ?language rdfs:label ?label . 
FILTER ( ?country == res:Spain || ?country == res:France || ?country == res:Italy )

which is shorter, but may be slower.

(I had a feeling SPARQL 1.1 had an 'IN' feature, but I don't see it in the drafts)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文