I'm trying to query RDF (owl ontology) model using JSP form. I am getting following error - "HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/jena/riot/RDFDataMgr"
This is my code for JSP form-
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="disease-result.jsp" method="post">
<p align="center">
Select affected part:
<input type="radio" name="part" value="Boll" /> Boll
<input type="radio" name="part" value="Leaves" /> Leaves
<input type="radio" name="part" value="Stem" /> Stem
<input type="radio" name="part" value="Root" /> Root
<br/><br/>
Select symptom:
<select name="symptom">
<option>Brown_to_black_color_lesions</option>
<option>Spots_on_cotyledons_and_seedlings</option>
<option>Drooping_of_bolls</option>
<option>Water_soaked_spots</option>
<option>Small_and_round_spots_on_bolls</option>
</select>
<br/><br/>
<input type="submit" value="Submit" />
</p>
</form>
</body>
</html>
Following is the code for "disease-result.jsp"
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="com.doitgeek.MyProject.PredictDisease"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
PredictDisease pd = new PredictDisease();
String affectedPart = request.getParameter("part");
String symptom = request.getParameter("symptom");
%>
Affected Part = <%= affectedPart %>
<br/><br/>
Symptom = <%= symptom %>
<br/><br/>
Output = <%= pd.diseasePrediction(affectedPart, symptom) %>
</body>
</html>
Following is the actual java code for class "PredictDisease"-
package com.doitgeek.MyProject;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.QuerySolution;
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.riot.RDFDataMgr;
public class PredictDisease {
public String diseasePrediction(String ap, String s) {
Model model = RDFDataMgr.loadModel("CottonOntology.owl");
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 co: <http://www.semanticweb.org/sainath/ontologies/2016/11/CottonOntology#> "+
"select ?Diseases ?Prevention where{?Diseases co:isControlledBy ?Prevention. "+
"?Diseases co:affectsPart co:"+ap+". "+
"?Diseases co:hasSymptom co:"+s+".}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
QuerySolution soln = results.nextSolution();
RDFNode disease = soln.get("Diseases");
String d = disease.asNode().getLocalName();
String p = soln.get("Prevention").toString();
return d;
} finally {
qexec.close();
}
}
}