Discussion:
Implementation of Rules
javed khan
2016-12-03 16:05:08 UTC
Permalink
My question is what are the possible ways to implement the Jena rules?
Is it necessary that we should always execute the SPARQL query to implement
the rules? If not, what are the alternatives?

What if we just write rules in our Java code and do nothing other than:

Reasoner myreasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infmodel = ModelFactory.createInfModel(myreasoner, model);

Thank you
Dave Reynolds
2016-12-03 17:06:03 UTC
Permalink
Post by javed khan
My question is what are the possible ways to implement the Jena rules?
Is it necessary that we should always execute the SPARQL query to implement
the rules? If not, what are the alternatives?
Reasoner myreasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infmodel = ModelFactory.createInfModel(myreasoner, model);
Sorry, don't follow the question.

Jena rules are the syntax for the built in Jena generic rules engine
which can be run as you show above.

You don't "implement the rules" by executing sparql queries you just run
the rules engine. You could compute the same results through using a
sequence of SPARQL queries and updates or through java code but that's
not the same thing as implementing the rules unless you have some sort
of jena-rules to "sequence of sparql updates" converter.

If you are talking about getting results out after running the rules
then your choices are SPARQL or the RDF API.

Dave
javed khan
2016-12-03 17:29:16 UTC
Permalink
Thank you Dave, I have a class "Expert", which have sub classes Researcher
and Teacher.
I have Jena rule like: If an Expert ResearchPapers more than 10, assign the
individual to Researcher sub class otherwise to Teacher subclass.
After writing the appropriate Jena rule, apart from SPARQL query

Select * Where{ ?ind rdf:type ont:Researcher . ?ind rdf:type ont:Teacher}

What is the alternate way to parse/execute the rule and the result
transfers to our infmodel. ?
Post by Dave Reynolds
Post by javed khan
My question is what are the possible ways to implement the Jena rules?
Is it necessary that we should always execute the SPARQL query to implement
the rules? If not, what are the alternatives?
Reasoner myreasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infmodel = ModelFactory.createInfModel(myreasoner, model);
Sorry, don't follow the question.
Jena rules are the syntax for the built in Jena generic rules engine which
can be run as you show above.
You don't "implement the rules" by executing sparql queries you just run
the rules engine. You could compute the same results through using a
sequence of SPARQL queries and updates or through java code but that's not
the same thing as implementing the rules unless you have some sort of
jena-rules to "sequence of sparql updates" converter.
If you are talking about getting results out after running the rules then
your choices are SPARQL or the RDF API.
Dave
Dave Reynolds
2016-12-03 18:24:29 UTC
Permalink
Post by javed khan
Thank you Dave, I have a class "Expert", which have sub classes Researcher
and Teacher.
I have Jena rule like: If an Expert ResearchPapers more than 10, assign the
individual to Researcher sub class otherwise to Teacher subclass.
After writing the appropriate Jena rule, apart from SPARQL query
Select * Where{ ?ind rdf:type ont:Researcher . ?ind rdf:type ont:Teacher}
What is the alternate way to parse/execute the rule and the result
transfers to our infmodel. ?
Sorry, still don't quite understand what you are asking.

There is no alternative way to "parse/execute" the rule other that to
pass it to a GenericRuleReasoner instance and create an InfModel. At
least no alternative built into Jena.

To then list all individuals that your rule has classified as a
Researcher then running a SPARQL query as you are is perfectly fine.

If you want to do that with the RDF API then it would be something like:

OntClass researcherClass = infModel.getResource(namespace +
"Researcher");
ResIterator i = infModel.listResourcesWithProperty(RDF.type,
researcherClass);
while (i.hasNext()){
Resource instance = i.next();
...
}

Dave
Post by javed khan
Post by Dave Reynolds
Post by javed khan
My question is what are the possible ways to implement the Jena rules?
Is it necessary that we should always execute the SPARQL query to implement
the rules? If not, what are the alternatives?
Reasoner myreasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infmodel = ModelFactory.createInfModel(myreasoner, model);
Sorry, don't follow the question.
Jena rules are the syntax for the built in Jena generic rules engine which
can be run as you show above.
You don't "implement the rules" by executing sparql queries you just run
the rules engine. You could compute the same results through using a
sequence of SPARQL queries and updates or through java code but that's not
the same thing as implementing the rules unless you have some sort of
jena-rules to "sequence of sparql updates" converter.
If you are talking about getting results out after running the rules then
your choices are SPARQL or the RDF API.
Dave
javed khan
2016-12-03 22:21:45 UTC
Permalink
Thanks Dave again, yes I was asking something like that. You answered what
I want.

Cheers
Post by Dave Reynolds
Post by javed khan
Thank you Dave, I have a class "Expert", which have sub classes Researcher
and Teacher.
I have Jena rule like: If an Expert ResearchPapers more than 10, assign the
individual to Researcher sub class otherwise to Teacher subclass.
After writing the appropriate Jena rule, apart from SPARQL query
Select * Where{ ?ind rdf:type ont:Researcher . ?ind rdf:type ont:Teacher}
What is the alternate way to parse/execute the rule and the result
transfers to our infmodel. ?
Sorry, still don't quite understand what you are asking.
There is no alternative way to "parse/execute" the rule other that to pass
it to a GenericRuleReasoner instance and create an InfModel. At least no
alternative built into Jena.
To then list all individuals that your rule has classified as a Researcher
then running a SPARQL query as you are is perfectly fine.
OntClass researcherClass = infModel.getResource(namespace +
"Researcher");
ResIterator i = infModel.listResourcesWithProperty(RDF.type,
researcherClass);
while (i.hasNext()){
Resource instance = i.next();
...
}
Dave
Post by javed khan
Post by javed khan
My question is what are the possible ways to implement the Jena rules?
Post by javed khan
Is it necessary that we should always execute the SPARQL query to implement
the rules? If not, what are the alternatives?
Reasoner myreasoner = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel infmodel = ModelFactory.createInfModel(myreasoner, model);
Sorry, don't follow the question.
Jena rules are the syntax for the built in Jena generic rules engine which
can be run as you show above.
You don't "implement the rules" by executing sparql queries you just run
the rules engine. You could compute the same results through using a
sequence of SPARQL queries and updates or through java code but that's not
the same thing as implementing the rules unless you have some sort of
jena-rules to "sequence of sparql updates" converter.
If you are talking about getting results out after running the rules then
your choices are SPARQL or the RDF API.
Dave
Continue reading on narkive:
Loading...