Javed,

This *still* doesn't show your data, *still" isn't plain text so we can't check what code you actually have and *still* isn't a complete example.

As one last attempt to help you, here's a version of the sample code I showed before which includes your second rule, which is working just fine.

#### code

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");
        OntClass WorstStudent = model.createClass(ns + "WorstStudent");
        Property prop = model.getProperty(ns, "GPA");

        Individual indiv = Student.createIndividual(ns + "s1");
        indiv.addLiteral(prop, 3);

        Individual indiv2 = Student.createIndividual(ns + "s2");
        indiv2.addLiteral(prop, 1);

String rules = "[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 )]"

+ "[rule2:(?x http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.semanticweb.org#Student) "
                + "( ?x http://www.semanticweb.org#GPA  ?marks )"
                + "lessThan(?marks, 2) "
+ " -> (?x http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.semanticweb.org#WorstStudent )]";

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rules));
        InfModel inf = ModelFactory.createInfModel(reasoner2, model);

for (Iterator i = inf.listResourcesWithProperty(RDF.type, GoodStudent); i.hasNext();) {
            System.out.println("Good student: " + i.next());
        }
for (Iterator i = inf.listResourcesWithProperty(RDF.type, WorstStudent); i.hasNext();) {
            System.out.println("Worst student: " + i.next());
        }

#### Output

Good student: http://www.semanticweb.org#s1
Worst student: http://www.semanticweb.org#s2

Note that a student with a grade of exactly 2 will trigger neither rule, that may or may not be what you want.

Dave

On 24/09/16 19:55, javed khan wrote:
This is the code where the first rules works and the second does not.

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


 * String rule2 = "[rule2:(?y
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>*
*http://www.semanticweb.org#Student <http://www.semanticweb.org#Student> )
"*
*                 + "( ?y http://www.semanticweb.org#GPA
<http://www.semanticweb.org#GPA>*
*  ?marks )"*
*                 + "lessThan(?marks, 2) "*
*                 + " ->  (?y
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>*
* http://www.semanticweb.org#WorstStudent
<http://www.semanticweb.org#WorstStudent>*
* )]";*

   "SELECT  * " +
                " WHERE {  ?x rdf:type std:GoodStudent . ?y rdf:type
std:WorstStudent }";

            Reasoner reasoner2 = new
GenericRuleReasoner(Rule.parseRules(rule));
        InfModel inf = ModelFactory.createInfModel(reasoner2, model);
             Query query = QueryFactory.create(queryString);

     QueryExecution qe = QueryExecutionFactory.create(query, inf);
     ResultSet results = qe.execSelect();



     ResultSetFormatter.out(System.out, results, query);
     qe.close();


Reply via email to