Mar*_*ler 5 rdf sparql graphdb named-graphs
假设我在 GraphDB 8.3 Triplestore 中进行了以下插入:
PREFIX : <http://example.com/>
insert data { :hello a :word }
Run Code Online (Sandbox Code Playgroud)
和
PREFIX : <http://example.com/>
insert data { graph :farewells { :goodbye a :word }}
Run Code Online (Sandbox Code Playgroud)
现在,如果我问
select * where {
graph ?g {
?s ?p ?o .
}
}
Run Code Online (Sandbox Code Playgroud)
我只得到
+--------------------------------+------------------------------+---------------------------------------------------+---------------------------+
| ?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> |
+--------------------------------+------------------------------+---------------------------------------------------+---------------------------+
Run Code Online (Sandbox Code Playgroud)
我显然可以通过以下内容获得“关于单词的三元组”,但随后不会显示命名图成员资格
select * { ?s ?p ?o }
Run Code Online (Sandbox Code Playgroud)
如何编写一个查询来检索有关单词的三元组并指示{ :goodbye a :word }
来自图形的三元组:farewells
?
您可以按照以下方式做一些事情:
SELECT *
WHERE {
{ GRAPH ?g { ?s ?p ?o } }
UNION
{ ?s ?p ?o .
FILTER NOT EXISTS { GRAPH ?g { ?s ?p ?o } }
}
}
Run Code Online (Sandbox Code Playgroud)
联合的第一部分选择命名图中的所有三元组。第二部分获取默认图中的所有三元组,明确排除命名图中出现的模式。
在 GraphDB 中,您可以使用伪图来实现此目的,i.\xe2\x80\x89e。<http://www.ontotext.com/explicit>
(看来你没有使用推理)。
尝试这个查询:
\n\nSELECT * FROM NAMED <http://www.ontotext.com/explicit>\n{ GRAPH ?g { ?s ?p ?o } }\n
Run Code Online (Sandbox Code Playgroud)\n\n结果应该是:
\n\n+------------------------------------+----------+-----------+-------+\n| ?g | ?s | ?p | ?o |\n+------------------------------------+----------+-----------+-------+\n| <http://www.ontotext.com/explicit> | :hello | rdf:type | :word |\n| :farewells | :goodbye | rdf:type | :word |\n+------------------------------------+----------+-----------+-------+\n
Run Code Online (Sandbox Code Playgroud)\n\n为了进行比较,请注意
\n\n+------------------------------------+----------+-----------+-------+\n| ?g | ?s | ?p | ?o |\n+------------------------------------+----------+-----------+-------+\n| <http://www.ontotext.com/explicit> | :hello | rdf:type | :word |\n| :farewells | :goodbye | rdf:type | :word |\n+------------------------------------+----------+-----------+-------+\n
Run Code Online (Sandbox Code Playgroud)\n\n只会返回
\n\n+------------------------------------+----------+-----------+-------+\n| ?g | ?s | ?p | ?o |\n+------------------------------------+----------+-----------+-------+\n| <http://www.ontotext.com/explicit> | :hello | rdf:type | :word |\n+------------------------------------+----------+-----------+-------+\n
Run Code Online (Sandbox Code Playgroud)\n