You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Simon Gray <si...@hum.ku.dk> on 2021/08/20 13:01:33 UTC

Inference rule selection for dummies?

Hi everyone,

I'm on Jena 3.14 experimenting with the built-in OntologySpecs.

My main requirement is inferring reverse relations (when applicable). Only the OWL reasoners do this, but they also infer so many more triples which balloons the size of the InfModel so much that it is impossible for me to infer every single triple within the memory constraints of my laptop. I have 16GB available, with 12GB set aside for the JVM heap, but every attempt at copying all inferred triples to a TDB2 model eventually fails with an OutOfMemoryError. The dataset is a modest-sized WordNet.

I wonder if it's possible for me to create an OntologySpec with a Reasoner that is a bit more basic, possibly only inferring reverse relation triples. Looking into this, it seems like one needs knowledge of the Logic DSL used to define the various built-in reasoners...? Or at least I never found an easy way to create a Reasoner that just does this.

Maybe it's possible to use one of the built-in OWL reasoners and simply disable some functionality? I'm not sure how, though. The only way I've found looking at the source code and the documentation seems to be editing a .rules file which contains the aforementioned logic DSL.

Kind regards
Simon



Re: Inference rule selection for dummies?

Posted by Dave Reynolds <da...@gmail.com>.
Hi Simon,

> So now I’ve instantiated a GenericRuleReasoner and mutated it in a similar fashion. There is one bit I’m unsure about which is the implementation of the bind method that I had copied from the OWLMicroReasoner:
> 
> 
> @Override
> public InfGraph bind(Graph data) throws ReasonerException {
>      InfGraph graph = super.bind(data);
>      ((FBRuleInfGraph)graph).setDatatypeRangeValidation(true);
>      return graph;
> }
> 
> This method seems to mutate the graph before returning. I wonder if it is necessary for me to even retain this functionality... and how would I go about doing that using a GenericRuleReasoner?

This is a feature/hack to (as the name suggests) do some validation of 
OWL data type ranges in a way that can't be conveniently done in the 
rules. Given your goals of just supporting inverse reasoning you can 
safely ignore this.

Dave

Re: Inference rule selection for dummies?

Posted by Simon Gray <si...@hum.ku.dk>.
Thanks a lot for these great answers. They really help to clear up some confusion.

I actually ended up successfully extending GenericRuleReasoner before your could reply (basically just copy-pasting the code from OWLMicroReasoner), but I would definitely prefer not to.

So now I’ve instantiated a GenericRuleReasoner and mutated it in a similar fashion. There is one bit I’m unsure about which is the implementation of the bind method that I had copied from the OWLMicroReasoner:


@Override
public InfGraph bind(Graph data) throws ReasonerException {
    InfGraph graph = super.bind(data);
    ((FBRuleInfGraph)graph).setDatatypeRangeValidation(true);
    return graph;
}

This method seems to mutate the graph before returning. I wonder if it is necessary for me to even retain this functionality... and how would I go about doing that using a GenericRuleReasoner?

I guess I should mutate the Graph in advance? But which graph?

Den 23. aug. 2021 kl. 21.58 skrev Dave Reynolds <da...@gmail.com>>:

[You don't often get email from dave.e.reynolds@gmail.com<ma...@gmail.com>. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.]

On 23/08/2021 08:16, Simon Gray wrote:
Thanks Dave, that is great to know!

Rght now I’m using one of the built-in OntModelSpec instances, calling `setBaseModelMaker` and `setImportModelMaker` on it with an instance created by `ModelFactory.createMemModelMaker` as the argument. It is my understanding that I will then also have to extend (or implement) both a Reasoner, e.g. org.apache.jena.reasoner.rulesys.OWLMicroReasoner, as well as a ReasonerFactory, e.g. OWLMicroReasonerFactory to make fresh OntModelSpec instance.

You shouldn't need to extend or implement a Reasoner.

I think you can simply create a reasoner instance - instantiate a
GenericRuleReasoner with the rules you want - and can then use
setReasoner on your copy of the OntModelSpec to install it for use.

Note that a reasoner can be reused multiple times - it's the
InfModel/InfGraph which holds all the reasoner state for a given
underlying base Model/Graph. The reasoner is just a reusable engine.

If you find that inelegant then you could indeed install a
ReasonerFactory (either the GenericRuleReasonerFactory passing in a
configuration model or create your own instance of a ReasonerFactory)
but I don't think that's necessary and certainly don't need to create a
new Reasoner class.

Dave



I wonder if this is the way to go?

Den 20. aug. 2021 kl. 17.24 skrev Dave Reynolds <da...@gmail.com>>:

[You don't often get email from dave.e.reynolds@gmail.com<ma...@gmail.com>. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.]

To create a reason with just a few rules of your choice then use the
GenericRuleReasoner. See
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjena.apache.org%2Fdocumentation%2Finference%2Findex.html%23rules&amp;data=04%7C01%7Csimongray%40hum.ku.dk%7C867301e2dd094d69f20e08d966707069%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C637653455372344657%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=HTHxCJC8RD8kngOCjsOcm4BYWb1OjRm6rpZ1SWuc0m8%3D&amp;reserved=0

You can write your own rules or pick and choose from those in the source
code you've found.

To only compute the inverse relationships, and do so on demand, you
probably just need:

[inverseOf2: (?P owl:inverseOf ?Q) -> table(?P), table(?Q),
[inverseOf2b: (?X ?P ?Y) <- (?Y ?Q ?X)] ]

That is a "hyrid" rule (mix of forward and backward) see the docs, but
that's the default for GenericRuleReasoner anyway.

Dave

On 20/08/2021 14:01, Simon Gray wrote:
Hi everyone,

I'm on Jena 3.14 experimenting with the built-in OntologySpecs.

My main requirement is inferring reverse relations (when applicable). Only the OWL reasoners do this, but they also infer so many more triples which balloons the size of the InfModel so much that it is impossible for me to infer every single triple within the memory constraints of my laptop. I have 16GB available, with 12GB set aside for the JVM heap, but every attempt at copying all inferred triples to a TDB2 model eventually fails with an OutOfMemoryError. The dataset is a modest-sized WordNet.

I wonder if it's possible for me to create an OntologySpec with a Reasoner that is a bit more basic, possibly only inferring reverse relation triples. Looking into this, it seems like one needs knowledge of the Logic DSL used to define the various built-in reasoners...? Or at least I never found an easy way to create a Reasoner that just does this.

Maybe it's possible to use one of the built-in OWL reasoners and simply disable some functionality? I'm not sure how, though. The only way I've found looking at the source code and the documentation seems to be editing a .rules file which contains the aforementioned logic DSL.

Kind regards
Simon





Re: Inference rule selection for dummies?

Posted by Dave Reynolds <da...@gmail.com>.
On 23/08/2021 08:16, Simon Gray wrote:
> Thanks Dave, that is great to know!
> 
> Rght now I’m using one of the built-in OntModelSpec instances, calling `setBaseModelMaker` and `setImportModelMaker` on it with an instance created by `ModelFactory.createMemModelMaker` as the argument. It is my understanding that I will then also have to extend (or implement) both a Reasoner, e.g. org.apache.jena.reasoner.rulesys.OWLMicroReasoner, as well as a ReasonerFactory, e.g. OWLMicroReasonerFactory to make fresh OntModelSpec instance.

You shouldn't need to extend or implement a Reasoner.

I think you can simply create a reasoner instance - instantiate a 
GenericRuleReasoner with the rules you want - and can then use 
setReasoner on your copy of the OntModelSpec to install it for use.

Note that a reasoner can be reused multiple times - it's the 
InfModel/InfGraph which holds all the reasoner state for a given 
underlying base Model/Graph. The reasoner is just a reusable engine.

If you find that inelegant then you could indeed install a 
ReasonerFactory (either the GenericRuleReasonerFactory passing in a 
configuration model or create your own instance of a ReasonerFactory) 
but I don't think that's necessary and certainly don't need to create a 
new Reasoner class.

Dave


> 
> I wonder if this is the way to go?
> 
>> Den 20. aug. 2021 kl. 17.24 skrev Dave Reynolds <da...@gmail.com>:
>>
>> [You don't often get email from dave.e.reynolds@gmail.com. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.]
>>
>> To create a reason with just a few rules of your choice then use the
>> GenericRuleReasoner. See
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjena.apache.org%2Fdocumentation%2Finference%2Findex.html%23rules&amp;data=04%7C01%7Csimongray%40hum.ku.dk%7C969da2c5af654732493b08d963eea058%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C637650698810113318%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=9vGnLU75Hl1sq%2FKe6vmBLthD9TKEoLBYvGIT%2F469P6w%3D&amp;reserved=0
>>
>> You can write your own rules or pick and choose from those in the source
>> code you've found.
>>
>> To only compute the inverse relationships, and do so on demand, you
>> probably just need:
>>
>> [inverseOf2: (?P owl:inverseOf ?Q) -> table(?P), table(?Q),
>> [inverseOf2b: (?X ?P ?Y) <- (?Y ?Q ?X)] ]
>>
>> That is a "hyrid" rule (mix of forward and backward) see the docs, but
>> that's the default for GenericRuleReasoner anyway.
>>
>> Dave
>>
>> On 20/08/2021 14:01, Simon Gray wrote:
>>> Hi everyone,
>>>
>>> I'm on Jena 3.14 experimenting with the built-in OntologySpecs.
>>>
>>> My main requirement is inferring reverse relations (when applicable). Only the OWL reasoners do this, but they also infer so many more triples which balloons the size of the InfModel so much that it is impossible for me to infer every single triple within the memory constraints of my laptop. I have 16GB available, with 12GB set aside for the JVM heap, but every attempt at copying all inferred triples to a TDB2 model eventually fails with an OutOfMemoryError. The dataset is a modest-sized WordNet.
>>>
>>> I wonder if it's possible for me to create an OntologySpec with a Reasoner that is a bit more basic, possibly only inferring reverse relation triples. Looking into this, it seems like one needs knowledge of the Logic DSL used to define the various built-in reasoners...? Or at least I never found an easy way to create a Reasoner that just does this.
>>>
>>> Maybe it's possible to use one of the built-in OWL reasoners and simply disable some functionality? I'm not sure how, though. The only way I've found looking at the source code and the documentation seems to be editing a .rules file which contains the aforementioned logic DSL.
>>>
>>> Kind regards
>>> Simon
>>>
>>>
> 

Re: Inference rule selection for dummies?

Posted by Simon Gray <si...@hum.ku.dk>.
Thanks Dave, that is great to know!

Rght now I’m using one of the built-in OntModelSpec instances, calling `setBaseModelMaker` and `setImportModelMaker` on it with an instance created by `ModelFactory.createMemModelMaker` as the argument. It is my understanding that I will then also have to extend (or implement) both a Reasoner, e.g. org.apache.jena.reasoner.rulesys.OWLMicroReasoner, as well as a ReasonerFactory, e.g. OWLMicroReasonerFactory to make fresh OntModelSpec instance.

I wonder if this is the way to go?

> Den 20. aug. 2021 kl. 17.24 skrev Dave Reynolds <da...@gmail.com>:
> 
> [You don't often get email from dave.e.reynolds@gmail.com. Learn why this is important at http://aka.ms/LearnAboutSenderIdentification.]
> 
> To create a reason with just a few rules of your choice then use the
> GenericRuleReasoner. See
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fjena.apache.org%2Fdocumentation%2Finference%2Findex.html%23rules&amp;data=04%7C01%7Csimongray%40hum.ku.dk%7C969da2c5af654732493b08d963eea058%7Ca3927f91cda14696af898c9f1ceffa91%7C0%7C0%7C637650698810113318%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=9vGnLU75Hl1sq%2FKe6vmBLthD9TKEoLBYvGIT%2F469P6w%3D&amp;reserved=0
> 
> You can write your own rules or pick and choose from those in the source
> code you've found.
> 
> To only compute the inverse relationships, and do so on demand, you
> probably just need:
> 
> [inverseOf2: (?P owl:inverseOf ?Q) -> table(?P), table(?Q),
> [inverseOf2b: (?X ?P ?Y) <- (?Y ?Q ?X)] ]
> 
> That is a "hyrid" rule (mix of forward and backward) see the docs, but
> that's the default for GenericRuleReasoner anyway.
> 
> Dave
> 
> On 20/08/2021 14:01, Simon Gray wrote:
>> Hi everyone,
>> 
>> I'm on Jena 3.14 experimenting with the built-in OntologySpecs.
>> 
>> My main requirement is inferring reverse relations (when applicable). Only the OWL reasoners do this, but they also infer so many more triples which balloons the size of the InfModel so much that it is impossible for me to infer every single triple within the memory constraints of my laptop. I have 16GB available, with 12GB set aside for the JVM heap, but every attempt at copying all inferred triples to a TDB2 model eventually fails with an OutOfMemoryError. The dataset is a modest-sized WordNet.
>> 
>> I wonder if it's possible for me to create an OntologySpec with a Reasoner that is a bit more basic, possibly only inferring reverse relation triples. Looking into this, it seems like one needs knowledge of the Logic DSL used to define the various built-in reasoners...? Or at least I never found an easy way to create a Reasoner that just does this.
>> 
>> Maybe it's possible to use one of the built-in OWL reasoners and simply disable some functionality? I'm not sure how, though. The only way I've found looking at the source code and the documentation seems to be editing a .rules file which contains the aforementioned logic DSL.
>> 
>> Kind regards
>> Simon
>> 
>> 


Re: Inference rule selection for dummies?

Posted by Dave Reynolds <da...@gmail.com>.
To create a reason with just a few rules of your choice then use the 
GenericRuleReasoner. See 
https://jena.apache.org/documentation/inference/index.html#rules

You can write your own rules or pick and choose from those in the source 
code you've found.

To only compute the inverse relationships, and do so on demand, you 
probably just need:

[inverseOf2: (?P owl:inverseOf ?Q) -> table(?P), table(?Q), 
[inverseOf2b: (?X ?P ?Y) <- (?Y ?Q ?X)] ]

That is a "hyrid" rule (mix of forward and backward) see the docs, but 
that's the default for GenericRuleReasoner anyway.

Dave

On 20/08/2021 14:01, Simon Gray wrote:
> Hi everyone,
> 
> I'm on Jena 3.14 experimenting with the built-in OntologySpecs.
> 
> My main requirement is inferring reverse relations (when applicable). Only the OWL reasoners do this, but they also infer so many more triples which balloons the size of the InfModel so much that it is impossible for me to infer every single triple within the memory constraints of my laptop. I have 16GB available, with 12GB set aside for the JVM heap, but every attempt at copying all inferred triples to a TDB2 model eventually fails with an OutOfMemoryError. The dataset is a modest-sized WordNet.
> 
> I wonder if it's possible for me to create an OntologySpec with a Reasoner that is a bit more basic, possibly only inferring reverse relation triples. Looking into this, it seems like one needs knowledge of the Logic DSL used to define the various built-in reasoners...? Or at least I never found an easy way to create a Reasoner that just does this.
> 
> Maybe it's possible to use one of the built-in OWL reasoners and simply disable some functionality? I'm not sure how, though. The only way I've found looking at the source code and the documentation seems to be editing a .rules file which contains the aforementioned logic DSL.
> 
> Kind regards
> Simon
> 
>