我有以下SPARQL查詢:的Java的Apache耶拿SPARQL查詢返回的詞彙錯誤
SELECT ?b ?c WHERE {
ont:http\:\/\/test.com\/test\#com.test.test.test.2.3.4 ?b ?c}
它返回成功返回OpenRDF工作臺2.6.5正確的結果。然而,在我的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(運行查詢其使用耶拿2.6.4 stringQuery);
我試圖改變耶拿版本,並沒有運氣,也無法理解爲什麼查詢是OpenRDF工作臺2.6.5和無效在我的Java查詢(我認爲這可能會做它自己的sanatization):/
幫助將非常感激!
這可以使用< >標誌完成。該查詢應該如下所示: SELECT?b?c WHERE {http://support.microsoft.com/kb/CHS/WEB/Search? – user1829257 2013-03-07 13:57:51