[英]what is the best way of querying a RDF model in jena in a generic way? (sparql or using collection and iterators)
[英]What is the best way to make an RDF Model accessible in a JSP view?
我正在編寫一個Java Web應用程序,該應用程序從URI獲取RDF數據並將其存儲在Jena Model對象中。 當前,模型包含普通三元組,一些空白節點,沒有推斷。 (這里已經描述過1 )。 也可以選擇使用芝麻。
數據收集之后,應用程序將以指定的順序顯示一些收集的信息。 有必要僅使用謂詞在模型上構建過濾器,並指定主題和謂詞的過濾器(因為我們將從多個來源收集數據); 在每種情況下,都會顯示對象文字或URI。
從JSP-View通用訪問模型內容的最佳方法是什么(不為每個函數編寫自定義標簽)?
JSP視圖將如下所示:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head></head>
<body>
<img src="${modelBean.model.depictionPred}"/>
Name: <c:out value="${modelBean.model.namePred}"/><br/>
Life dates: <c:out value="${modelBean.model.birthPred}"/>-<c:out value="${modelBean.model.deathPred}"/><br/>
Links: <a href="${modelBean.model.linkPred}">Linktext</a><br/>
...
</body>
</html>
Jena-Servlet收集數據:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ModelBean modelBean = new ModelBean();
Model model = ModelFactory.createDefaultModel();
model.read("http://dbpedia.org/resource/Ludwig_van_Beethoven");
modelBean.setModel(model);
request.setAttribute("modelBean", modelBean);
RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
rd.forward(request, response);
}
Servlet的Sesame-Variant:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ModelBean modelBean = new ModelBean();
URL url = new URL("http://dbpedia.org/resource/Ludwig_van_Beethoven");
URLConnection conn = url.openConnection();
conn.addRequestProperty("Accept", RDFFormat.TURTLE.getDefaultMIMEType());
InputStream is = conn.getInputStream();
try {
Model model = Rio.parse(is, url.toString(), RDFFormat.forMIMEType(conn.getContentType()));
} catch (RDFParseException ex) {
Logger.getLogger(ModelViewTester.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
is.close();
}
modelBean.setModel(model);
request.setAttribute("modelBean", modelBean);
RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
rd.forward(request, response);
}
除了可以通過為bean方法的調用提供參數來實現某些事情(請參閱如何使用JSTL / EL從JSP調用參數化方法 )之外,我擔心您還必須創建自定義標簽,或者需要重新考慮您的訪問策略。
例如,您可以在servlet端提取相關數據,而不是將整個RDF Model
放入響應中,而只是將要顯示在視圖響應中的相關屬性作為單獨的bean屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.