简单的 SPARQL 查询没有 return 任何结果
Simple SPARQL query does not return any results
我刚起床,运行 Blazegraph 处于嵌入式模式。我加载了一些示例三元组,并能够使用 "select all" 查询检索它们:
SELECT * WHERE { ?s ?p ?o }
此查询 returns 我所有的示例三元组:
[s=<<<http://github.com/jschmidt10#person_Thomas>, <http://github.com/jschmidt10#hasAge>, "30"^^<http://www.w3.org/2001/XMLSchema#int>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://github.com/jschmidt10#hasLastName>, "Test">>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://www.w3.org/2002/07/owl#sameAs>, <http://github.com/jschmidt10#person_Thomas>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<http://github.com/jschmidt10#person_Thomas>;p=<http://github.com/jschmidt10#hasAge>;o="30"^^<http://www.w3.org/2001/XMLSchema#int>]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://github.com/jschmidt10#hasLastName>;o="Test"]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://www.w3.org/2002/07/owl#sameAs>;o=<http://github.com/jschmidt10#person_Thomas>]
接下来我尝试针对特定主题进行简单查询:
SELECT * WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }
此查询没有产生任何结果。我对 URI 的查询似乎有 none 个有效。当我查询文字时(例如 ?s ?p "Test"
),我能够得到结果。
我用来创建查询的 API 是 BigdataSailRepositoryConnection.prepareQuery().
执行和生成查询的代码片段 (Scala):
val props = BasicRepositoryProvider.getProperties("./graph.jnl")
val sail = new BigdataSail(props)
val repo = new BigdataSailRepository(sail)
repo.initialize()
val query = "SELECT ?p ?o WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }"
val cxn = repo.getConnection
cxn.begin()
var res = cxn.
prepareTupleQuery(QueryLanguage.SPARQL, query).
evaluate()
while (res.hasNext) println(res.next)
cxn.close()
repo.shutDown()
你检查过你填充数据库的方式了吗?您的字符可能会被奇怪地编码,或者看起来您的对象中可能有多余的括号。
从打印语句来看,您的 URI 正在打印额外的尖括号。您可能正在使用:
val subject = valueFactory.createURI("<http://some.url/some/entity>")
什么时候应该这样做(没有尖括号):
val subject = valueFactory.createURI("http://some.url/some/entity")
我刚起床,运行 Blazegraph 处于嵌入式模式。我加载了一些示例三元组,并能够使用 "select all" 查询检索它们:
SELECT * WHERE { ?s ?p ?o }
此查询 returns 我所有的示例三元组:
[s=<<<http://github.com/jschmidt10#person_Thomas>, <http://github.com/jschmidt10#hasAge>, "30"^^<http://www.w3.org/2001/XMLSchema#int>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://github.com/jschmidt10#hasLastName>, "Test">>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<<<http://github.com/jschmidt10#person_Tommy>, <http://www.w3.org/2002/07/owl#sameAs>, <http://github.com/jschmidt10#person_Thomas>>>;p=blaze:history:added;o="2017-01-15T16:11:15.909Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>]
[s=<http://github.com/jschmidt10#person_Thomas>;p=<http://github.com/jschmidt10#hasAge>;o="30"^^<http://www.w3.org/2001/XMLSchema#int>]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://github.com/jschmidt10#hasLastName>;o="Test"]
[s=<http://github.com/jschmidt10#person_Tommy>;p=<http://www.w3.org/2002/07/owl#sameAs>;o=<http://github.com/jschmidt10#person_Thomas>]
接下来我尝试针对特定主题进行简单查询:
SELECT * WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }
此查询没有产生任何结果。我对 URI 的查询似乎有 none 个有效。当我查询文字时(例如 ?s ?p "Test"
),我能够得到结果。
我用来创建查询的 API 是 BigdataSailRepositoryConnection.prepareQuery().
执行和生成查询的代码片段 (Scala):
val props = BasicRepositoryProvider.getProperties("./graph.jnl")
val sail = new BigdataSail(props)
val repo = new BigdataSailRepository(sail)
repo.initialize()
val query = "SELECT ?p ?o WHERE { <http://github.com/jschmidt10#person_Thomas> ?p ?o }"
val cxn = repo.getConnection
cxn.begin()
var res = cxn.
prepareTupleQuery(QueryLanguage.SPARQL, query).
evaluate()
while (res.hasNext) println(res.next)
cxn.close()
repo.shutDown()
你检查过你填充数据库的方式了吗?您的字符可能会被奇怪地编码,或者看起来您的对象中可能有多余的括号。
从打印语句来看,您的 URI 正在打印额外的尖括号。您可能正在使用:
val subject = valueFactory.createURI("<http://some.url/some/entity>")
什么时候应该这样做(没有尖括号):
val subject = valueFactory.createURI("http://some.url/some/entity")