为什么这个 SPARQL 查询会产生错误
Why does this SPARQL query generate an error
我的 ontology IRI 是“http://mycompany.com/ontologies/quality”。我想找到 "Find all subjects with a given object property (hasSolution)"
SELECT ?subject
WHERE { ?subject hasSolution <http://mycompany.com/ontologies/quality#Issue> } LIMIT 10
它导致了这个错误消息:
Caused by: org.openrdf.query.parser.sparql.ast.TokenMgrError: Lexical error at line 8, column 30. Encountered: " " (32), after : "hasSolution"
at org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilderTokenManager.getNextToken(SyntaxTreeBuilderTokenManager.java:3499)
at org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilder.jj_ntk(SyntaxTreeBuilder.java:8861)
我怀疑这里的问题是你如何表达你的谓词 - 它应该是 IRI 形式,或者使用 angle-brackets 像这样:
SELECT ?subject
WHERE {
?subject <http://mycompany.com/ontologies/hasSolution> <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
或者,使用 PREFIX 语句为您提供如下内容:
PREFIX mycoont: <http://mycompany.com/ontologies/>
SELECT ?subject
WHERE
{
?subject mycoont:hasSolution <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
或者,更一般地说,如果您不知道谓词 IRI 到底是什么,您可以将其作为查询的一部分:
SELECT ?subject ?predicate
WHERE {
?subject ?predicate <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
并探索结果 - 返回的 ?predicate 值应该表示为完整的 IRI,或者根据您的查询引擎,表示为某种形式的 prefix:suffix 排列。
在探索结果时,您应该能够 copy-paste 适当的值到您的 WHERE 子句的 ?predicate 三元组中,并从您的 SELECT 子句中删除 ?predicate 三元组。
我的 ontology IRI 是“http://mycompany.com/ontologies/quality”。我想找到 "Find all subjects with a given object property (hasSolution)"
SELECT ?subject
WHERE { ?subject hasSolution <http://mycompany.com/ontologies/quality#Issue> } LIMIT 10
它导致了这个错误消息:
Caused by: org.openrdf.query.parser.sparql.ast.TokenMgrError: Lexical error at line 8, column 30. Encountered: " " (32), after : "hasSolution"
at org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilderTokenManager.getNextToken(SyntaxTreeBuilderTokenManager.java:3499)
at org.openrdf.query.parser.sparql.ast.SyntaxTreeBuilder.jj_ntk(SyntaxTreeBuilder.java:8861)
我怀疑这里的问题是你如何表达你的谓词 - 它应该是 IRI 形式,或者使用 angle-brackets 像这样:
SELECT ?subject
WHERE {
?subject <http://mycompany.com/ontologies/hasSolution> <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
或者,使用 PREFIX 语句为您提供如下内容:
PREFIX mycoont: <http://mycompany.com/ontologies/>
SELECT ?subject
WHERE
{
?subject mycoont:hasSolution <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
或者,更一般地说,如果您不知道谓词 IRI 到底是什么,您可以将其作为查询的一部分:
SELECT ?subject ?predicate
WHERE {
?subject ?predicate <http://mycompany.com/ontologies/quality#Issue>
}
LIMIT 10
并探索结果 - 返回的 ?predicate 值应该表示为完整的 IRI,或者根据您的查询引擎,表示为某种形式的 prefix:suffix 排列。
在探索结果时,您应该能够 copy-paste 适当的值到您的 WHERE 子句的 ?predicate 三元组中,并从您的 SELECT 子句中删除 ?predicate 三元组。