我想從Java(特別是Jena和ARQ)創建SPARQL查詢。我想讓一個對SPARQL可能一無所知的用戶通過編寫(例如,在Eclipse的控制檯中)他想搜索的單詞來進行查詢。以下代碼給出了我正在尋找的示例。如何將字符串word
插入到查詢中?將字符串插入與Jena的SPARQL查詢
String word="someThingToFind"; // a variable entered by the user who want to request my data
String queryString =
"Select ?a ?b"+
" Where { ...."+
" Filter (regex(?a = ".concat(word)+ "))"+// word is the String variable
" }";
Query query = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();
[參數化SPARQL查詢與JENA]可能的重複(http://stackoverflow.com/questions/9729659/parameterized-sparql-query-with-jena) – RobV
不,我不這麼認爲,因爲我試過這個解決方案,但它沒有工作,即使我試圖連接查詢與我的字符串變量,但它沒有工作。 – jojo
@jojo關閉問題的原因包括:「詢問代碼的問題必須對所解決的問題有最小的理解。**包括嘗試的解決方案,爲什麼他們不工作,以及預期的結果。**」如果您已經嘗試過這是一個已知的解決方案(也就是對另一個問題的答案),你能證明這種嘗試和對此沒有任何作用嗎? –