Question

I have a jsp based web application, which uses tomcat as the j2ee server, please advise me with the necessary steps for implementing a semantic search?

I have added the code below.

  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;
}

The above code snippet shows the method returning a string value for the query executed and it is returned correctly.But when trying to retrieve the value inside the java servlet results in an error.

 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);

}

above code was used in the servlet. how can i resolve this? thanks in advance

this is a screenshot of the error screen i get. http://tinypic.com/r/2cnxj87/8

Was it helpful?

Solution

Thank you so much for the help given. adding the necessary dependencies for sparql-dl api did the trick.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top