我有一个基于jsp的web应用程序,它使用tomcat作为j2ee服务器,请告诉我实现语义搜索的必要步骤?
我已添加以下代码。
public String queryOntology(String val) throws OWLOntologyCreationException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory dataFactory = manager.getOWLDataFactory();
File ontologyFile = new File("D:\\onto.owl");
OWLOntology psychiatricOntology = manager.loadOntologyFromOntologyDocument(ontologyFile);
//OWLReasoner rStructral = new StructuralReasonerFactory().createReasoner(psychiatricOntology);
OWLReasoner rHermit = new Reasoner.ReasonerFactory().createReasoner(psychiatricOntology);
try {
QueryEngine queryEng = QueryEngine.create(manager, rHermit);
Query query = Query.create("SELECT ?c WHERE { Class(?c) }");
QueryResult result = queryEng.execute(query);
return result.toString();
} catch (QueryParserException ex) {
//return ex.getMessage();
} catch (QueryEngineException ex) {
ex.getMessage();
} finally {
rHermit.dispose();
//rStructral.dispose();
}
return null;
}
上面的代码片段显示了为执行的查询返回字符串值的方法,并且它正确返回。但是当尝试检索java servlet中的值时会导致错误。
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//processRequest(request, response);
String val = request.getParameter("query");
PrintWriter out = response.getWriter();
getInfo gi = new getInfo();
request.getRequestDispatcher("header.jsp").include(request, response);
out.print("<div id=content>");
out.print(val);
try {
//gi.createIndex();
//List<String> str = gi.createIndexSearcher(val);
//out.print(str);
out.print(gi.queryOntology(val));
} catch (OWLOntologyCreationException ex) {
Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex);
}
out.print("</div>");
request.getRequestDispatcher("footer.jsp").include(request, response);
}
上面的代码在servlet中使用。我怎么解决这个问题?提前谢谢
这是我得到的错误屏幕的屏幕截图。 http://tinypic.com/r/2cnxj87/8
答案 0 :(得分:0)
非常感谢你给予的帮助。为sparql-dl api添加必要的依赖项就行了。