假设我在GraphDB 8.3 Triplestore中进行了以下插入:
PREFIX : <http://example.com/>
insert data { :hello a :word }
和
PREFIX : <http://example.com/>
insert data { graph :farewells { :goodbye a :word }}
现在,如果我问
select * where {
graph ?g {
?s ?p ?o .
}
}
我只会
+--------------------------------+------------------------------+---------------------------------------------------+---------------------------+
| ?g | ?s | ?p | ?o |
+--------------------------------+------------------------------+---------------------------------------------------+---------------------------+
| <http://example.com/farewells> | <http://example.com/goodbye> | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | <http://example.com/word> |
+--------------------------------+------------------------------+---------------------------------------------------+---------------------------+
我显然可以通过以下两种方式获得“单词的三元组”,但是随后不显示命名图成员身份
select * { ?s ?p ?o }
我如何编写一个查询,以同时检索单词的三元组并指示
{ :goodbye a :word }
来自图:farewells
? 最佳答案
在GraphDB中,您可以将pseudographs用于此目的,即。 e。 <http://www.ontotext.com/explicit>
(似乎您没有使用推理)。
试试这个查询:
SELECT * FROM NAMED <http://www.ontotext.com/explicit>
{ GRAPH ?g { ?s ?p ?o } }
结果应为:
+------------------------------------+----------+-----------+-------+
| ?g | ?s | ?p | ?o |
+------------------------------------+----------+-----------+-------+
| <http://www.ontotext.com/explicit> | :hello | rdf:type | :word |
| :farewells | :goodbye | rdf:type | :word |
+------------------------------------+----------+-----------+-------+
为了进行比较,请注意
SELECT * FROM NAMED <http://www.openrdf.org/schema/sesame#nil>
{ GRAPH ?g { ?s ?p ?o } }
只返回
+------------------------------------+----------+-----------+-------+
| ?g | ?s | ?p | ?o |
+------------------------------------+----------+-----------+-------+
| <http://www.ontotext.com/explicit> | :hello | rdf:type | :word |
+------------------------------------+----------+-----------+-------+
关于sparql - 选择所有三元组,如果相关则指示命名图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46436060/