多语句查询 SPARQL 1.1 属性-paths Virtuoso 7.2.X
Multiple statements query SPARQL 1.1 property-paths Virtuoso 7.2.X
示例 RDF 数据集包含按 owl#Class
分组的条目 owl#NamedIndividual
和名为 IsMemberOf
的自定义关系。当我尝试获取按类型分隔的结果列表时,效果很好,但是当我添加一种方法来获取它们相应的 IsMemberOf
时,我没有得到预期的结果。
这是我给 Virtuoso 的三个 SPARQL 1.1 查询(下面的示例数据集):
查询 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 <IsMemberOf> ?member_of.
时只得到以下不完整的结果?
s member_of name
rocky_the_rock group_a Rocky the rock
ralf_the_rock group_a Ralf the rock
<livingthings>
class 下的所有结果都被忽略了。是因为 Virtuoso 中的错误还是我的 SPARQL 查询的形成方式?
很难说到底是什么问题。您显示的查询本身不是合法的 SPARQL(例如,在 SPARQL 中您执行 select ...
,而不是 sparql select ...;
),但这可能是您正在使用的 Virtuoso 界面。另一个可能的问题是 <IsMemberOf>
和类似的是相对 IRI,它们的解析方式在数据加载和查询处理等方面可能有所不同,因此 <IsMemberOf>
不一定是一种情况place 实际上指的是 <IsMemberOf>
在另一个 IRI 中指的同一个 IRI。你真的应该使用绝对 IRI。不知道是不是这里的问题
也就是说,我获取了你的数据并根据 http://example.org/ 解析了 IRI,因此它们都是绝对的,看起来像查询按照您希望的方式工作。例如,运行 以下对 Jena 的查询工作正常。
base <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select * where {
?s <IsMemberOf> ?member_of.
?s rdfs:label ?name.
?s a/rdfs:subClassOf* <livingthings>.
}
-------------------------------------------------------
| s | member_of | name |
=======================================================
| <doggy_the_dog> | <group_a> | "Doggy the dog" |
| <eli_the_elephant> | <group_c> | "Eli the elephant" |
| <fido_the_dog> | <group_b> | "Fido the dog" |
| <katy_the_cat> | <group_b> | "Katy the cat" |
| <snakey_the_snake> | <group_a> | "Snakey the snake" |
-------------------------------------------------------
这是更新后的数据:
<http://example.org/elephant>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Elephant" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/snakey_the_snake>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/snake> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Snakey the snake" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/cat>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Cat" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/mammal>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Mammal" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/livingthings> .
<http://example.org/katy_the_cat>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/cat> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Katy the cat" ;
<http://example.org/IsMemberOf>
<http://example.org/group_b> .
<http://example.org/fido_the_dog>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/dog> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Fido the dog" ;
<http://example.org/IsMemberOf>
<http://example.org/group_b> .
<http://example.org/dog>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Dog" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/eli_the_elephant>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/elephant> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Eli the elephant" ;
<http://example.org/IsMemberOf>
<http://example.org/group_c> .
<http://example.org/reptile>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Reptile" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/livingthings> .
<http://example.org/nonlivingthings>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Non-living things" .
<http://example.org/livingthings>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Living things" .
<http://example.org/doggy_the_dog>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/dog> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Doggy the dog" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/rocky_the_rock>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/rock> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Rocky the rock" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/rock>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Rock" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/nonlivingthings> .
<http://example.org/ralf_the_rock>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/rock> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Ralf the rock" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/snake>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Snake" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/reptile> .
当与 属性 路径混合时,Virtuoso 似乎在查询中奇怪地处理用户定义的关系。
这是解决此问题的 Virtuoso 特定方法。
查询 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 <IsMemberOf>{1} ?member_of.
给出了预期的结果。
在查询一中,行 ?s <IsMemberOf>{1} ?member_of.
应用于每个联合元素内的每个术语。如果不是,则结果不尽如人意。它确实解决了这个问题,但它有点荒谬。这就是为什么我会把这个问题悬而未决几天,看看是否有人可以对 Virtuoso 中的情况提供合乎逻辑的解释。如果这只是一个错误,我会通过他们的邮件列表与他们联系。
示例 RDF 数据集包含按 owl#Class
分组的条目 owl#NamedIndividual
和名为 IsMemberOf
的自定义关系。当我尝试获取按类型分隔的结果列表时,效果很好,但是当我添加一种方法来获取它们相应的 IsMemberOf
时,我没有得到预期的结果。
这是我给 Virtuoso 的三个 SPARQL 1.1 查询(下面的示例数据集):
查询 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 <IsMemberOf> ?member_of.
时只得到以下不完整的结果?
s member_of name
rocky_the_rock group_a Rocky the rock
ralf_the_rock group_a Ralf the rock
<livingthings>
class 下的所有结果都被忽略了。是因为 Virtuoso 中的错误还是我的 SPARQL 查询的形成方式?
很难说到底是什么问题。您显示的查询本身不是合法的 SPARQL(例如,在 SPARQL 中您执行 select ...
,而不是 sparql select ...;
),但这可能是您正在使用的 Virtuoso 界面。另一个可能的问题是 <IsMemberOf>
和类似的是相对 IRI,它们的解析方式在数据加载和查询处理等方面可能有所不同,因此 <IsMemberOf>
不一定是一种情况place 实际上指的是 <IsMemberOf>
在另一个 IRI 中指的同一个 IRI。你真的应该使用绝对 IRI。不知道是不是这里的问题
也就是说,我获取了你的数据并根据 http://example.org/ 解析了 IRI,因此它们都是绝对的,看起来像查询按照您希望的方式工作。例如,运行 以下对 Jena 的查询工作正常。
base <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select * where {
?s <IsMemberOf> ?member_of.
?s rdfs:label ?name.
?s a/rdfs:subClassOf* <livingthings>.
}
-------------------------------------------------------
| s | member_of | name |
=======================================================
| <doggy_the_dog> | <group_a> | "Doggy the dog" |
| <eli_the_elephant> | <group_c> | "Eli the elephant" |
| <fido_the_dog> | <group_b> | "Fido the dog" |
| <katy_the_cat> | <group_b> | "Katy the cat" |
| <snakey_the_snake> | <group_a> | "Snakey the snake" |
-------------------------------------------------------
这是更新后的数据:
<http://example.org/elephant>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Elephant" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/snakey_the_snake>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/snake> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Snakey the snake" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/cat>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Cat" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/mammal>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Mammal" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/livingthings> .
<http://example.org/katy_the_cat>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/cat> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Katy the cat" ;
<http://example.org/IsMemberOf>
<http://example.org/group_b> .
<http://example.org/fido_the_dog>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/dog> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Fido the dog" ;
<http://example.org/IsMemberOf>
<http://example.org/group_b> .
<http://example.org/dog>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Dog" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/mammal> .
<http://example.org/eli_the_elephant>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/elephant> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Eli the elephant" ;
<http://example.org/IsMemberOf>
<http://example.org/group_c> .
<http://example.org/reptile>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Reptile" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/livingthings> .
<http://example.org/nonlivingthings>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Non-living things" .
<http://example.org/livingthings>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Living things" .
<http://example.org/doggy_the_dog>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/dog> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Doggy the dog" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/rocky_the_rock>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/rock> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Rocky the rock" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/rock>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Rock" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/nonlivingthings> .
<http://example.org/ralf_the_rock>
a <http://www.w3.org/2002/07/owl#NamedIndividual> , <http://example.org/rock> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Ralf the rock" ;
<http://example.org/IsMemberOf>
<http://example.org/group_a> .
<http://example.org/snake>
a <http://www.w3.org/2002/07/owl#Class> ;
<http://www.w3.org/2000/01/rdf-schema#label>
"Snake" ;
<http://www.w3.org/2000/01/rdf-schema#subClassOf>
<http://example.org/reptile> .
当与 属性 路径混合时,Virtuoso 似乎在查询中奇怪地处理用户定义的关系。
这是解决此问题的 Virtuoso 特定方法。
查询 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 <IsMemberOf>{1} ?member_of.
给出了预期的结果。
在查询一中,行 ?s <IsMemberOf>{1} ?member_of.
应用于每个联合元素内的每个术语。如果不是,则结果不尽如人意。它确实解决了这个问题,但它有点荒谬。这就是为什么我会把这个问题悬而未决几天,看看是否有人可以对 Virtuoso 中的情况提供合乎逻辑的解释。如果这只是一个错误,我会通过他们的邮件列表与他们联系。