В образце набора данных RDF есть записи owl#NamedIndividual
, сгруппированные по owl#Class
, и настраиваемое отношение с именем IsMemberOf
. Когда я пытаюсь получить список результатов, разделенных по типу, это работает хорошо, но в тот момент, когда я добавляю способ получения соответствующих IsMemberOf
результатов, я не получаю ожидаемых результатов.
Вот три запроса SPARQL 1.1, которые я дал Virtuoso (образец набора данных ниже):
Запрос 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-запрос?
sparql
и завершающий;
запутают людей, которые ожидают увидеть SPARQL. Вы также можете удалить их и делать все, что вы здесь делали, через интерфейс SPARQL -http://virtuoso-host:port/sparql/
- person TallTed   schedule 30.09.2015