The rule for subClassOf
defined in, for example etc/owl-fb-mini.rules
creates (or allows query for) new triples in the underlying graph that now relate some individual to its ancestor classes (through subClassOf
) rather than its direct parent. These rules attempt to implement rdfs and owl inference.
So, for example, if your graph contained:
<urn:ex:instance> <rdf:type> <urn:ex:ClassA>
<urn:ex:ClassA> <rdfs:subClassOf> <urn:ex:ClassB>
Then, with basic class reasoning, the graph should behave as though it contained the following triples, instead:
<urn:ex:instance> <rdf:type> <urn:ex:ClassA>
<urn:ex:ClassA> <rdfs:subClassOf> <urn:ex:ClassB>
<urn:ex:instance> <rdf:type> <urn:ex:ClassB>
If you want to change the interpretation of OWL or RDFS axioms as expressed in RDF, that is, what triples you can access through the graph, then you would need to make your own versions of the rdfs and/or owl rules files. If you wish to do that, you will need to study the Reasoners and Rule Engines documentation as well as the existing rules files within jena-core
.
Implementing your example would be a matter of adding an additional rule to the existing RDFS or OWL rulesets:
[andPropertiesToo: (?child rdfs:subClassOf ?parent),
(?parent ?p ?o) ->
(?child ?p ?o)
]
You could, for example, retrieve the set of rules that is used for RDFS, and then add this new rule as well, then create a GenericRuleReasoner
whose List<Rule>
contained all of them:
final String customRule =
"[andPropertiesToo: (?child rdfs:subClassOf ?parent),\n"+
"(?parent ?p ?o) ->\n"+
"(?child ?p ?o)\n"+
"]";
final List<Rule> customRules = new ArrayList<Rule>(){{
this.addAll(RDFSRuleReasoner.loadRulesLevel(RDFSRuleReasoner.SIMPLE_RULES));
try( final BufferedReader src = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(customRule.getBytes()))) ) {
this.addAll(Rule.parseRules(Rule.rulesParserFromReader(src)));
}
}};
final RuleReasoner reasoner = (RuleReasoner)GenericRuleReasonerFactory.theInstance().create(null);
reasoner.setRules(customRules);
final InfModel model = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel());
model.prepare();