【发布时间】:2015-07-22 14:09:28
【问题描述】:
示例 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> 类下的所有结果都被忽略了。是因为 Virtuoso 中的错误还是我的 SPARQL 查询的形成方式?
【问题讨论】:
-
值得标记 Virtuoso 的 SPASQL -- SPARQL-in-SQL;用于 ODBC、JDBC、ADO.NET、OLE DB 和其他基于 SQL 的连接——查询本身。开头的
sparql和结尾的;会让那些只希望看到 SPARQL 的人感到困惑。你也可以去掉这些,然后通过 SPARQL 接口完成你在此处所做的一切——http://virtuoso-host:port/sparql/