我有以下 SparQL 查询:
SELECT ?b ?c WHERE {
ont:http\:\/\/test.com\/test\#com.test.test.test.2.3.4 ?b ?c}
成功返回OpenRDF Workbench 2.6.5中的正确结果。但是,在我使用以下代码运行查询时使用Jena 2.6.4的 Java 中
private static ResultSet getQueryResults(String stringQuery, String service) {
Query query = QueryFactory.create(stringQuery);
QueryExecution qexec = QueryExecutionFactory.sparqlService(
service, query);
ResultSet results = qexec.execSelect();
//ResultSetFormatter.out(System.out, results, query);
return results;
}
public static ResultSet getDetails(String ID) {
//we define our sparql query
String sanatizedID = "ont:" + sanitizeString(ID);
String stringQuery = " SELECT ?b ?c WHERE" +
" { " + sanatizedID +
//"{?a"+
" ?b" +
" ?c}";
System.out.println(stringQuery);
//we define our service
String service = "http://test.test.com:8181/test-sesame/repositories/test";
//We write the results of our query into a results set
ResultSet results = getQueryResults(stringQuery, service);
return results;
}
private static String sanitizeString(String s) {
s = s.replace("/", "\\/");
s = s.replace("#", "\\#");
s = s.replace(":", "\\:");
s = s.replace("\"", "\\\"");
return s;
}
我收到以下错误
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Lexical error at line 1, column 871. Encountered: ":" (58), after : "\\"
在线查询查询 = QueryFactory.create(stringQuery);
我已经尝试更改 Jena 版本但没有运气,无法理解为什么查询在 OpenRDF Workbench 2.6.5 中有效,而不是在我的 Java 查询中有效(我认为它可能会自行清理):/
帮助将不胜感激!