On 18/09/16 16:41, javed khan wrote:
This code does not work.
You haven't shown us the data and haven't said in what way it doesn't work.
I want to save student marks/GPA in the file and
based on GPA assign students to GoodStudent or WorstStudents sub classes of
Student via Jena rules.
[snip]
String rule="[rule1:(?x http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.semanticweb.org#Student) " +
"( http://www.semanticweb.org#Student
http://www.semanticweb.org#GPA ?marks + )"
That *still" has the spurious + in from your last question.
Furthermore it is highly unlikely you mean the subject of that pattern
to be the Student class, it should be ?x.
A simplified version of your code, which doesn't require any input data is:
public void temp() throws Exception {
OntModel model = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM );
String ns = "http://www.semanticweb.org#";
OntClass Student = model.createClass(ns + "Student");
OntClass GoodStudent = model.createClass(ns + "GoodStudent");
Individual indiv = Student.createIndividual(ns + "s1");
Property prop = model.getProperty(ns, "GPA");
indiv.addLiteral(prop, 3);
String rule = "[rule1:(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.semanticweb.org#Student) "
+ "( ?x http://www.semanticweb.org#GPA ?marks )"
+ "greaterThan(?marks, 2) "
+ " -> (?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.semanticweb.org#GoodStudent )]";
Reasoner reasoner2 = new
GenericRuleReasoner(Rule.parseRules(rule));
InfModel inf = ModelFactory.createInfModel(reasoner2, model);
for (Iterator i = inf.listResourcesWithProperty(RDF.type,
GoodStudent); i.hasNext();) {
System.out.println("Good student: " + i.next());
}
}
Which produces the output:
Good student: http://www.semanticweb.org#s1
Dave