You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Junsung <wn...@gmail.com> on 2015/09/15 09:53:33 UTC

Reusing inferred statements in InfModel to existing model in Jena

To whom it may concern,


I have a Jena Model filled with statements and use a GenericRuleReasoner with
custom rule strings as follow (Example directly taken from Jena tutorial
page <https://jena.apache.org/documentation/inference/index.html>)

String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p
?c)]";Reasoner reasoner = new
GenericRuleReasoner(Rule.parseRules(rules));
reasoner.setDerivationLogging(true);InfModel inf =
ModelFactory.createInfModel(reasoner, model);

>From my understanding of Jena reasoner, new inference model inf would
contain statements from model as well as newly inferred statements
generated by the rules. Are instances of statements in both inf and
model shared
or different? If different, wouldn't this waste memory too much?

An issue that I'm having is reusing inferred statements into the model.
Looping through infmodel to find newly inferred statements and adding them
to model seems to be a naive approach. Is there any other wiser method?

Lastly, I am wondering what would be the best approach to remove outdated
statement from model. What I mean by an outdated statement is probably best
explained by an example. Say there is a statement (Speaker hasSoundLevel
50) in the model. Later, when a new statement such as (Speaker
hasSoundLevel 80) is inserted, it should invalidate(i.e. delete) (Speaker
hasSoundLevel 50) from the model. Could this be achieved by using a rule?
What if a statement needs to be outdated after certain amount of time since
its insertion? Any suggestions on how to achieve this would be appreciated.

Thanks,


Junsung Lim

Re: Reusing inferred statements in InfModel to existing model in Jena

Posted by Martynas Jusevičius <ma...@graphity.org>.
Junsung,

is InfModel.getDeductionsModel() not what you're looking for?

https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/InfModel.html#getDeductionsModel--

On Tue, Sep 15, 2015 at 9:53 AM, Junsung <wn...@gmail.com> wrote:
> To whom it may concern,
>
>
> I have a Jena Model filled with statements and use a GenericRuleReasoner with
> custom rule strings as follow (Example directly taken from Jena tutorial
> page <https://jena.apache.org/documentation/inference/index.html>)
>
> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p
> ?c)]";Reasoner reasoner = new
> GenericRuleReasoner(Rule.parseRules(rules));
> reasoner.setDerivationLogging(true);InfModel inf =
> ModelFactory.createInfModel(reasoner, model);
>
> From my understanding of Jena reasoner, new inference model inf would
> contain statements from model as well as newly inferred statements
> generated by the rules. Are instances of statements in both inf and
> model shared
> or different? If different, wouldn't this waste memory too much?
>
> An issue that I'm having is reusing inferred statements into the model.
> Looping through infmodel to find newly inferred statements and adding them
> to model seems to be a naive approach. Is there any other wiser method?
>
> Lastly, I am wondering what would be the best approach to remove outdated
> statement from model. What I mean by an outdated statement is probably best
> explained by an example. Say there is a statement (Speaker hasSoundLevel
> 50) in the model. Later, when a new statement such as (Speaker
> hasSoundLevel 80) is inserted, it should invalidate(i.e. delete) (Speaker
> hasSoundLevel 50) from the model. Could this be achieved by using a rule?
> What if a statement needs to be outdated after certain amount of time since
> its insertion? Any suggestions on how to achieve this would be appreciated.
>
> Thanks,
>
>
> Junsung Lim

Re: Reusing inferred statements in InfModel to existing model in Jena

Posted by Dave Reynolds <da...@gmail.com>.
On 15/09/15 08:53, Junsung wrote:
> To whom it may concern,
>
>
> I have a Jena Model filled with statements and use a GenericRuleReasoner with
> custom rule strings as follow (Example directly taken from Jena tutorial
> page <https://jena.apache.org/documentation/inference/index.html>)
>
> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p
> ?c)]";Reasoner reasoner = new
> GenericRuleReasoner(Rule.parseRules(rules));
> reasoner.setDerivationLogging(true);InfModel inf =
> ModelFactory.createInfModel(reasoner, model);
>
>  From my understanding of Jena reasoner, new inference model inf would
> contain statements from model as well as newly inferred statements
> generated by the rules. Are instances of statements in both inf and
> model shared
> or different? If different, wouldn't this waste memory too much?

Deduced statements (at least from forward rules) go into an internal 
"deductions" model associated with the InfModel. Martynas has already 
shown you how to access that.

The InfModel provides a dynamic union over the base model and the 
deductions, there is no duplication.

> An issue that I'm having is reusing inferred statements into the model.
> Looping through infmodel to find newly inferred statements and adding them
> to model seems to be a naive approach. Is there any other wiser method?

Why do this at all?

If you want to create a materialized copy (a separate plain, 
non-inference model containing all the original plus all the deduced 
statements) that do that by:

    plainModel.add( infModel) ;

But I can't think why you might want to add the deduced statements back 
into the base model. It's possible:

    baseModel.add( infModel.getDeductionsModel() );

but seems pointless.

> Lastly, I am wondering what would be the best approach to remove outdated
> statement from model. What I mean by an outdated statement is probably best
> explained by an example. Say there is a statement (Speaker hasSoundLevel
> 50) in the model. Later, when a new statement such as (Speaker
> hasSoundLevel 80) is inserted, it should invalidate(i.e. delete) (Speaker
> hasSoundLevel 50) from the model. Could this be achieved by using a rule?
> What if a statement needs to be outdated after certain amount of time since
> its insertion? Any suggestions on how to achieve this would be appreciated.

There's no reliable way with Jena rules to work out what triples have 
been invalidated.

If you retract any base statements (whether or not you "replace" them by 
something similar) then you just have to start inference over again. If 
you just add statements then the additional deductions can be made 
incrementally.

In both cases just add (or if you must, remove) statements from the 
InfModel and let the reasoner do the work.

Dave