I created a Jena Rule Reasoner as in the documentation
final String rules = "[rule1: (?a urn:eg:p ?b) (?b urn:eg:p ?c) -> (?a urn:eg:p ?c)]";
final Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
reasoner.setDerivationLogging(true);
final InfModel inf = ModelFactory.createInfModel(reasoner, rawData);
Everything works fine, and I can check the derivation of triples in the inferred model, but the triples which already exist in rawData
are not re-inferred by the reasoner, even if they could be, which means that there will be no record of the derivation of such triples. Is there a way to force the reasoner to re-infer and record derivations of triples that already exist in the raw data?
Unfortunately, I cannot think of a way to force Jena to construct the derivations for the information in the raw data. I can, however, think of a brute-force way to cause information to be derived that could be derived, thus, resulting in a derivation.
Consider the result of the following (JUnit) test passing:
In effect, if you remove a triple from the graph that was presently in the raw data, then, if that triple can be derived, it will remain in the graph. You can then get the derivation. You can safely perform this (costly) operation for all triples in a graph using the following loop:
For the example data above (assuming we remove the everything after the creation of
inf
and replace it with our loop), the output is as follows:Your data is now in a state where you can obtain derivations for all derivable things, and only the minimal amount of
rawData
remains that would allow you to conclude the entirety ofinf
.Note that the behavior of this operation may not be consistent or expected, especially in the presence of multiple derivation paths. Good luck.