I am trying to add a Jena rule submitted as string to the below method. However the rule is not being added as I can verify no new change on the ontology written to E://1_1_1 Could someone help me how to do this. Other questions on SO that may be related are 26292160, 349652; both of which are similar to my case.
public String ValidateAndConfigureRule(String string) {
try{
GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(string));
Model oModel = m.getOntology();
reasoner.setDerivationLogging(true);
reasoner.setOWLTranslation(true);
reasoner.setTraceOn(true);
reasoner.setTransitiveClosureCaching(true);
InfModel inf = ModelFactory.createInfModel(reasoner, oModel);
inf.write(new FileWriter("E://1_1_1"));
Model baseModel = ModelFactory.createDefaultModel();
baseModel.add(inf);
final OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF, baseModel);
ValidityReport validity = model.validate();
}
}
The rule itself is in the format
[ r1: (?x :objProp1 :ind_x) -> (?x :objProp2 :ind_y) ]
where objProp
's are object properties and ind_x
, ind_y
are individuals along with the necessary prefix for ":" in the rule string.