You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Maciek Niemczyk <m....@me.com> on 2014/07/16 21:18:54 UTC
Fwd: Problems with Reasoning - even the simple explamples from Docu
does not work!
> Betreff: Problems with Reasoning - even the simple explamples from Docu does not work!
>
> Hi
>
> i have a serious problem to get any reasoner up and running.
> Also the examples from the documentation: https://jena.apache.org/documentation/inference/
> does not work here.
> I transferred the example into a unit test, so that the problem might be easier reproduced.
>
> Is reasoning limited to certain environment like a spatial JDK or so on, or am i getting something wrong?
>
> Thanks
>
> Here the (your example) code (as java unit test):
>
> import static org.junit.Assert.assertNotNull;
>
> import java.io.PrintWriter;
> import java.util.Iterator;
>
> import org.junit.Before;
> import org.junit.Test;
>
> import com.hp.hpl.jena.rdf.model.InfModel;
> import com.hp.hpl.jena.rdf.model.Model;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.rdf.model.Property;
> import com.hp.hpl.jena.rdf.model.Resource;
> import com.hp.hpl.jena.rdf.model.Statement;
> import com.hp.hpl.jena.rdf.model.StmtIterator;
> import com.hp.hpl.jena.reasoner.Derivation;
> import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
> import com.hp.hpl.jena.reasoner.rulesys.Rule;
> import com.hp.hpl.jena.vocabulary.RDFS;
>
> public class ReasonerTest {
>
> String NS = "urn:x-hp-jena:eg/";
>
> // Build a trivial example data set
> Model model = ModelFactory.createDefaultModel();
> InfModel inf;
>
> Resource A = model.createResource(NS + "A");
> Resource B = model.createResource(NS + "B");
> Resource C = model.createResource(NS + "C");
> Resource D = model.createResource(NS + "D");
>
> Property p = model.createProperty(NS, "p");
> Property q = model.createProperty(NS, "q");
>
>
> @Before
> public void init() {
>
> // Some small examples (subProperty)
> model.add(p, RDFS.subPropertyOf, q);
> model.createResource(NS + "A").addProperty(p, "foo");
>
> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]";
> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
> reasoner.setDerivationLogging(true);
> inf = ModelFactory.createInfModel(reasoner, model);
>
> // Derivations
> A.addProperty(p, B);
> B.addProperty(p, C);
> C.addProperty(p, D);
> }
>
>
> @Test
> public void subProperty() {
> Statement statement = A.getProperty(q);
> System.out.println("Statement: " + statement);
> assertNotNull(statement);
> }
>
>
> @Test
> public void derivations() {
> String trace = null;
> PrintWriter out = new PrintWriter(System.out);
> for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) {
> Statement s = i.nextStatement();
> System.out.println("Statement is " + s);
> for (Iterator id = inf.getDerivation(s); id.hasNext(); ) {
> Derivation deriv = (Derivation) id.next();
> deriv.printTrace(out, true);
> trace += deriv.toString();
> }
> }
> out.flush();
> assertNotNull(trace);
> }
>
> @Test
> public void listStatements() {
> StmtIterator stmtIterator = inf.listStatements();
> while(stmtIterator.hasNext()) {
> System.out.println(stmtIterator.nextStatement());
> }
> }
> }
>
>
Re: Problems with Reasoning - even the simple explamples from Docu
does not work!
Posted by Maciek Niemczyk <m....@me.com>.
You are awesome, as I already mentioned I the comments. It has been 4 years since working with Jena last time, and I wondered if something changed in that time, but I got my trust back and that's all thanks to you!
Have a nice evening!
Best regards
Maciek
Send from mobile - pleace excause typosch
> Am 16.07.2014 um 23:09 schrieb Joshua TAYLOR <jo...@gmail.com>:
>
>> On Wed, Jul 16, 2014 at 4:32 PM, Maciek Niemczyk <m....@me.com> wrote:
>> Thanks for the Rsponse. This question ob stackoverfow was entered by me ;) The namespace part is created but the reasoning does still not work, even when using RDFSRuleReasoner with RDFS_Default vocabulary. So it's still kind of open.
>
> And answered by me. If it wasn't done yet, you shouldn't have marked
> it as accepted yet. :) That's kind of a signal that the answer worked
> for you. At any rate, the answer is updated to get a custom reasoner
> created that does your rule and the RDFS rules, fixes the subProperty
> test, and gets everything running.
>
> //JT
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Problems with Reasoning - even the simple explamples from Docu
does not work!
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Wed, Jul 16, 2014 at 4:32 PM, Maciek Niemczyk <m....@me.com> wrote:
> Thanks for the Rsponse. This question ob stackoverfow was entered by me ;) The namespace part is created but the reasoning does still not work, even when using RDFSRuleReasoner with RDFS_Default vocabulary. So it's still kind of open.
And answered by me. If it wasn't done yet, you shouldn't have marked
it as accepted yet. :) That's kind of a signal that the answer worked
for you. At any rate, the answer is updated to get a custom reasoner
created that does your rule and the RDFS rules, fixes the subProperty
test, and gets everything running.
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Problems with Reasoning - even the simple explamples from Docu
does not work!
Posted by Maciek Niemczyk <m....@me.com>.
Thanks for the Rsponse. This question ob stackoverfow was entered by me ;) The namespace part is created but the reasoning does still not work, even when using RDFSRuleReasoner with RDFS_Default vocabulary. So it's still kind of open.
Thx
Send from mobile - pleace excause typosch
> Am 16.07.2014 um 22:27 schrieb Joshua TAYLOR <jo...@gmail.com>:
>
> This was already asked and answered on Stack Overflow [1]. The problem was:
>
> 1. The eg: prefix stands for "urn:x-hp:eg/", not "urn:x-hp-jena:eg/".
> It is a bit confusing because the documentation never explicitly
> states what it will be, and the documentation does use the latter in
> some of the examples, too.
> 2. RDFS reasoning requires a reasoner that does RDFS reasoning. The
> subproperty inference won't be performed by the custom rules provided
> here.
>
> //JT
>
> [1] http://stackoverflow.com/q/24786035/1281433
>
>> On Wed, Jul 16, 2014 at 3:18 PM, Maciek Niemczyk <m....@me.com> wrote:
>>
>>> Betreff: Problems with Reasoning - even the simple explamples from Docu does not work!
>>>
>>> Hi
>>>
>>> i have a serious problem to get any reasoner up and running.
>>> Also the examples from the documentation: https://jena.apache.org/documentation/inference/
>>> does not work here.
>>> I transferred the example into a unit test, so that the problem might be easier reproduced.
>>>
>>> Is reasoning limited to certain environment like a spatial JDK or so on, or am i getting something wrong?
>>>
>>> Thanks
>>>
>>> Here the (your example) code (as java unit test):
>>>
>>> import static org.junit.Assert.assertNotNull;
>>>
>>> import java.io.PrintWriter;
>>> import java.util.Iterator;
>>>
>>> import org.junit.Before;
>>> import org.junit.Test;
>>>
>>> import com.hp.hpl.jena.rdf.model.InfModel;
>>> import com.hp.hpl.jena.rdf.model.Model;
>>> import com.hp.hpl.jena.rdf.model.ModelFactory;
>>> import com.hp.hpl.jena.rdf.model.Property;
>>> import com.hp.hpl.jena.rdf.model.Resource;
>>> import com.hp.hpl.jena.rdf.model.Statement;
>>> import com.hp.hpl.jena.rdf.model.StmtIterator;
>>> import com.hp.hpl.jena.reasoner.Derivation;
>>> import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
>>> import com.hp.hpl.jena.reasoner.rulesys.Rule;
>>> import com.hp.hpl.jena.vocabulary.RDFS;
>>>
>>> public class ReasonerTest {
>>>
>>> String NS = "urn:x-hp-jena:eg/";
>>>
>>> // Build a trivial example data set
>>> Model model = ModelFactory.createDefaultModel();
>>> InfModel inf;
>>>
>>> Resource A = model.createResource(NS + "A");
>>> Resource B = model.createResource(NS + "B");
>>> Resource C = model.createResource(NS + "C");
>>> Resource D = model.createResource(NS + "D");
>>>
>>> Property p = model.createProperty(NS, "p");
>>> Property q = model.createProperty(NS, "q");
>>>
>>>
>>> @Before
>>> public void init() {
>>>
>>> // Some small examples (subProperty)
>>> model.add(p, RDFS.subPropertyOf, q);
>>> model.createResource(NS + "A").addProperty(p, "foo");
>>>
>>> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]";
>>> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>>> reasoner.setDerivationLogging(true);
>>> inf = ModelFactory.createInfModel(reasoner, model);
>>>
>>> // Derivations
>>> A.addProperty(p, B);
>>> B.addProperty(p, C);
>>> C.addProperty(p, D);
>>> }
>>>
>>>
>>> @Test
>>> public void subProperty() {
>>> Statement statement = A.getProperty(q);
>>> System.out.println("Statement: " + statement);
>>> assertNotNull(statement);
>>> }
>>>
>>>
>>> @Test
>>> public void derivations() {
>>> String trace = null;
>>> PrintWriter out = new PrintWriter(System.out);
>>> for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) {
>>> Statement s = i.nextStatement();
>>> System.out.println("Statement is " + s);
>>> for (Iterator id = inf.getDerivation(s); id.hasNext(); ) {
>>> Derivation deriv = (Derivation) id.next();
>>> deriv.printTrace(out, true);
>>> trace += deriv.toString();
>>> }
>>> }
>>> out.flush();
>>> assertNotNull(trace);
>>> }
>>>
>>> @Test
>>> public void listStatements() {
>>> StmtIterator stmtIterator = inf.listStatements();
>>> while(stmtIterator.hasNext()) {
>>> System.out.println(stmtIterator.nextStatement());
>>> }
>>> }
>>> }
>>>
>>>
>
>
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Problems with Reasoning - even the simple explamples from Docu
does not work!
Posted by Joshua TAYLOR <jo...@gmail.com>.
This was already asked and answered on Stack Overflow [1]. The problem was:
1. The eg: prefix stands for "urn:x-hp:eg/", not "urn:x-hp-jena:eg/".
It is a bit confusing because the documentation never explicitly
states what it will be, and the documentation does use the latter in
some of the examples, too.
2. RDFS reasoning requires a reasoner that does RDFS reasoning. The
subproperty inference won't be performed by the custom rules provided
here.
//JT
[1] http://stackoverflow.com/q/24786035/1281433
On Wed, Jul 16, 2014 at 3:18 PM, Maciek Niemczyk <m....@me.com> wrote:
>
>> Betreff: Problems with Reasoning - even the simple explamples from Docu does not work!
>>
>> Hi
>>
>> i have a serious problem to get any reasoner up and running.
>> Also the examples from the documentation: https://jena.apache.org/documentation/inference/
>> does not work here.
>> I transferred the example into a unit test, so that the problem might be easier reproduced.
>>
>> Is reasoning limited to certain environment like a spatial JDK or so on, or am i getting something wrong?
>>
>> Thanks
>>
>> Here the (your example) code (as java unit test):
>>
>> import static org.junit.Assert.assertNotNull;
>>
>> import java.io.PrintWriter;
>> import java.util.Iterator;
>>
>> import org.junit.Before;
>> import org.junit.Test;
>>
>> import com.hp.hpl.jena.rdf.model.InfModel;
>> import com.hp.hpl.jena.rdf.model.Model;
>> import com.hp.hpl.jena.rdf.model.ModelFactory;
>> import com.hp.hpl.jena.rdf.model.Property;
>> import com.hp.hpl.jena.rdf.model.Resource;
>> import com.hp.hpl.jena.rdf.model.Statement;
>> import com.hp.hpl.jena.rdf.model.StmtIterator;
>> import com.hp.hpl.jena.reasoner.Derivation;
>> import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
>> import com.hp.hpl.jena.reasoner.rulesys.Rule;
>> import com.hp.hpl.jena.vocabulary.RDFS;
>>
>> public class ReasonerTest {
>>
>> String NS = "urn:x-hp-jena:eg/";
>>
>> // Build a trivial example data set
>> Model model = ModelFactory.createDefaultModel();
>> InfModel inf;
>>
>> Resource A = model.createResource(NS + "A");
>> Resource B = model.createResource(NS + "B");
>> Resource C = model.createResource(NS + "C");
>> Resource D = model.createResource(NS + "D");
>>
>> Property p = model.createProperty(NS, "p");
>> Property q = model.createProperty(NS, "q");
>>
>>
>> @Before
>> public void init() {
>>
>> // Some small examples (subProperty)
>> model.add(p, RDFS.subPropertyOf, q);
>> model.createResource(NS + "A").addProperty(p, "foo");
>>
>> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]";
>> GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>> reasoner.setDerivationLogging(true);
>> inf = ModelFactory.createInfModel(reasoner, model);
>>
>> // Derivations
>> A.addProperty(p, B);
>> B.addProperty(p, C);
>> C.addProperty(p, D);
>> }
>>
>>
>> @Test
>> public void subProperty() {
>> Statement statement = A.getProperty(q);
>> System.out.println("Statement: " + statement);
>> assertNotNull(statement);
>> }
>>
>>
>> @Test
>> public void derivations() {
>> String trace = null;
>> PrintWriter out = new PrintWriter(System.out);
>> for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) {
>> Statement s = i.nextStatement();
>> System.out.println("Statement is " + s);
>> for (Iterator id = inf.getDerivation(s); id.hasNext(); ) {
>> Derivation deriv = (Derivation) id.next();
>> deriv.printTrace(out, true);
>> trace += deriv.toString();
>> }
>> }
>> out.flush();
>> assertNotNull(trace);
>> }
>>
>> @Test
>> public void listStatements() {
>> StmtIterator stmtIterator = inf.listStatements();
>> while(stmtIterator.hasNext()) {
>> System.out.println(stmtIterator.nextStatement());
>> }
>> }
>> }
>>
>>
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/