多语句查询 SPARQL 1.1 property-paths Virtuoso 7.2.X [英] Multiple statements query SPARQL 1.1 property-paths Virtuoso 7.2.X

查看:47
本文介绍了多语句查询 SPARQL 1.1 property-paths Virtuoso 7.2.X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例 RDF 数据集包含按 owl#Class 分组的条目 owl#NamedIndividual 和名为 IsMemberOf 的自定义关系.当我尝试获取按类型分隔的结果列表时,它运行良好,但是当我添加一种方法来获取其对应的 IsMemberOf 时,我没有得到预期的结果.

A sample RDF dataset has entries owl#NamedIndividual grouped by owl#Class and a custom relation named IsMemberOf. When I try to obtain a list of results segregated by their type, it works well but the moment I add a way to obtain their corresponding IsMemberOf I don't get expected results.

这是我给 Virtuoso 的三个 SPARQL 1.1 查询(下面的示例数据集):

Here is three SPARQL 1.1 queries I gave to Virtuoso (sample dataset below):

查询 1

sparql select * from <test>
where {
#If I uncomment the next line I don't get the proper results
#  ?s <IsMemberOf> ?member_of.
  ?s rdfs:label ?name.
  {
    ?s rdf:type/rdfs:subClassOf* <livingthings>.
  } UNION {
    ?s a <rock>.
  }
};

查询 2

sparql select * from <test>
where {
#If I uncomment the next line I get no results at all
#   ?s <IsMemberOf> ?member_of.
    ?s rdfs:label ?name.
    ?s rdf:type/rdfs:subClassOf* <livingthings>.
};

查询 3

sparql select * from <test>
where {
  ?s <IsMemberOf> ?member_of.
  ?s rdfs:label ?name.
  ?s rdf:type <dog>.
#If I replace the previous line with the next line I get no results at all
# ?s rdf:type/rdfs:subClassOf* <livingthings>.
};

数据的分组方式如下:

livingthings
->mammal
--->dog
----->doggy_the_dog
----->fido_the_dog
--->cat
---->katy_the_cat
--->elephant
----->eli_the_elephant
->reptile
--->snake
----->snakey_the_snake
nonlivingthings
->rock
--->rocky_the_rock
--->ralf_the_rock

group_a
->rocky_the_rock
->ralf_the_rock
->snakey_the_snake
->doggy_the_dog
group_b
->fido_the_dog
->katy_the_cat
group_c
->eli_the_elephant

最后是我使用的数据

sparql create silent graph <test>;
sparql insert into graph <test> {
  <nonlivingthings> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <nonlivingthings> <http://www.w3.org/2000/01/rdf-schema#label> "Non-living things".
  <rock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <rock> <http://www.w3.org/2000/01/rdf-schema#label> "Rock".
  <rock> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <nonlivingthings>.
  <rocky_the_rock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <rocky_the_rock> <IsMemberOf> <group_a>.
  <rocky_the_rock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <rock>.
  <rocky_the_rock> <http://www.w3.org/2000/01/rdf-schema#label> "Rocky the rock".
  <ralf_the_rock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <ralf_the_rock> <IsMemberOf> <group_a>.
  <ralf_the_rock> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <rock>.
  <ralf_the_rock> <http://www.w3.org/2000/01/rdf-schema#label> "Ralf the rock".  
  <livingthings> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <livingthings> <http://www.w3.org/2000/01/rdf-schema#label> "Living things".
  <mammal> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <mammal> <http://www.w3.org/2000/01/rdf-schema#label> "Mammal".
  <mammal> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <livingthings>.
  <reptile> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <reptile> <http://www.w3.org/2000/01/rdf-schema#label> "Reptile".
  <reptile> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <livingthings>.
  <dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <dog> <http://www.w3.org/2000/01/rdf-schema#label> "Dog".
  <dog> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <mammal>.
  <cat> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <cat> <http://www.w3.org/2000/01/rdf-schema#label> "Cat".
  <cat> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <mammal>.
  <elephant> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <elephant> <http://www.w3.org/2000/01/rdf-schema#label> "Elephant".
  <elephant> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <mammal>.
  <snake> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class>.
  <snake> <http://www.w3.org/2000/01/rdf-schema#label> "Snake".
  <snake> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <reptile>.
  <snakey_the_snake> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <snakey_the_snake> <IsMemberOf> <group_a>.
  <snakey_the_snake> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <snake>.
  <snakey_the_snake> <http://www.w3.org/2000/01/rdf-schema#label> "Snakey the snake".
  <doggy_the_dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <doggy_the_dog> <IsMemberOf> <group_a>.
  <doggy_the_dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <dog>.
  <doggy_the_dog> <http://www.w3.org/2000/01/rdf-schema#label> "Doggy the dog".
  <fido_the_dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <fido_the_dog> <IsMemberOf> <group_b>.
  <fido_the_dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <dog>.
  <fido_the_dog> <http://www.w3.org/2000/01/rdf-schema#label> "Fido the dog".
  <katy_the_cat> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <katy_the_cat> <IsMemberOf> <group_b>.
  <katy_the_cat> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <cat>.
  <katy_the_cat> <http://www.w3.org/2000/01/rdf-schema#label> "Katy the cat".
  <eli_the_elephant> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#NamedIndividual>.
  <eli_the_elephant> <IsMemberOf> <group_c>.
  <eli_the_elephant> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <elephant>.
  <eli_the_elephant> <http://www.w3.org/2000/01/rdf-schema#label> "Eli the elephant".
};

为什么我取消注释 时只会得到以下不完整的结果?s ?member_of. 在查询一中?

Why do I only get the following incomplet result when I uncomment ?s <IsMemberOf> ?member_of. in query one?

s               member_of   name
rocky_the_rock  group_a     Rocky the rock
ralf_the_rock   group_a     Ralf the rock

类下的所有结果都被排除在外.是因为 Virtuoso 中的错误还是我的 SPARQL 查询的形成方式?

All of the results under the <livingthings> class are left out. Is it because of a bug in Virtuoso or the way my SPARQL query is formed?

推荐答案

当与属性路径混合时,Virtuoso 似乎在查询中奇怪地处理用户定义的关系.

Virtuoso seems to handle user defined relation oddly in a query when mixed with a property path.

这是解决此问题的 Virtuoso 特定方法.

Here is the Virtuoso specific way to address this issue.

查询 1 个答案

sparql select * from <test>
where {
  ?s rdfs:label ?name.
  {
    ?s <IsMemberOf>{1} ?member_of.
    ?s rdf:type/rdfs:subClassOf* <livingthings>.
  } UNION {
    ?s <IsMemberOf>{1} ?member_of.
    ?s a <rock>.
  }
};

查询 2 答案

sparql select * from <test>
where {
    ?s <IsMemberOf>{1} ?member_of.
    ?s rdfs:label ?name.
    ?s rdf:type/rdfs:subClassOf* <livingthings>.
};

为用户定义的关系应用显式属性路径,例如 ?s {1} ?member_of. 给出了预期的结果.

Applying an explicit property path for the user defined relation as such ?s <IsMemberOf>{1} ?member_of. gives the expected results.

在查询一中,行 ?s {1} ?member_of. 应用于每个联合元素内的每个术语.如果不是,则结果不符合预期.它确实解决了问题,但有点荒谬.这就是为什么我将这个问题悬而未决几天,看看是否有人可以对 Virtuoso 中为什么会这样提供合乎逻辑的解释.如果这只是一个错误,我会通过他们的邮件列表与他们联系.

In query one the line ?s <IsMemberOf>{1} ?member_of. is applied to each term inside each union element. If not then the results are not as desired. It does solve the issue but it is a bit nonsensical. That is why I'll leave the question open for a few days to see if anyone can provide logical explanation to why things are that way in Virtuoso. If it's just a bug I'll contact them via their mailing list.

这篇关于多语句查询 SPARQL 1.1 property-paths Virtuoso 7.2.X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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