0

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)

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 inf model 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,

wns349
  • 1,266
  • 1
  • 10
  • 20

2 Answers2

0

The Inferred model that is generated contains both statements from the original ontology and the inferred statements from the reasoner. As far as I am aware, these statements are not shared, however I do not believe it wastes a lot of memory. To find out more, you may want to drop an email to the people actually working on Jena through their mailing list.

As for removing outdated statements, you can't directly do so through rules. You can however create a custom builtin for Jena rules that would remove statements you feed it through your rule file, or use an API call on the OntModel by specifying some underlying logical conditions in your program.
Again as as far as I know, Jena does not natively maintain a timestamp for when a statement was added to the model so it is impossible to invalidate a statement after a certain amount of time, although you could add a listener and keep a log of changes and use the log time to figure out when to invalidate.

Kunal Khaladkar
  • 493
  • 3
  • 16
0

Are instances of statements in both inf and model shared or different?

They appear to be shared. For example, after you have created InfModel you can add a new triple directly using InfModel.add(s,p,o). Then you will find that triple has also been added to the original model. As far as inferred statements go, those appear to remain distinct, i.e. will not show up in model.

fprac
  • 53
  • 3