基本上我在 上創建了我的本體Protégé,并且我已經驗證了我的查詢正在作業并回傳真實值但是一旦我在我的 jsp 檔案上可視化它們,我的查詢回傳空值我試圖調查并跟蹤我的錯誤一周但是找不到錯誤。
這是我讀取本體檔案的代碼。
public static List<String> executeQueryOneColumn(ServletContext context, String queryString) {
List<String> values = new ArrayList<>();
Model model = FileManager.get().loadModel(context.getRealPath("/") "/resources/LolOnto1.owl");
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
System.out.println(results);
while (results.hasNext()) {
QuerySolution solution = results.nextSolution();
Resource x = solution.getResource("x");
values.add(x.getLocalName());
}
} finally {
qexec.close();
}
return values;
}
這就是我執行 SparQL 查詢以檢索已存盤在我自己的檔案中的資訊的地方。
@WebServlet(name = "QueryChampions", urlPatterns = {"/QueryChampions"})
public class QueryChampions extends HttpServlet {
Logger logger = LoggerFactory.getLogger(QueryChampions.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String champion = request.getParameter("champion");
String ori = request.getParameter("origin");
String queryString = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
"PREFIX owl: <http://www.w3.org/2002/07/owl#>"
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"
"PREFIX lol: <http://www.LeagueOfLegends.ema/LolOntology#>"
" "
"SELECT * "
"WHERE "
"{ "
" ?Champion lol:comesFrom ?origins "
"}";
queryString = String.format(queryString, champion, ori);
List<List<String>> rows = com.lol.champions.OwlReaderUtil.executeQueryTwoColumn(getServletContext(), queryString);
System.out.println(rows);
request.setAttribute("results", rows);
request.setAttribute("champion", champion);
request.setAttribute("origin", ori);
request.getRequestDispatcher("/StandardSearch").forward(request, response);
}
}
我嘗試在我的 web 應用程式的 jsp 檔案中列出它們。
<tr><th>Champion</th><th>Origin</th></tr>
<c:forEach items="${results}" var="row" >
<tr>
<c:forEach items="${row}" var="v" >
<td>
${v}
</td>
</c:forEach>
</tr>
</c:forEach>
</table>
uj5u.com熱心網友回復:
問題與我的executeOneColumn函式有關,因為我正在傳遞getResource("x")并且在我的 SparQl 查詢中我得到了?Championand ?Origins,所以如果我想得到 ,x我需要將所需元素之一重命名為x.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/427033.html
上一篇:在SQL中組合兩個幾乎相同的行
