0

I have built an application that uses Jena API and lets you create an ontology for Products and have different type of products like sports, electronics products etc. Now what I have to do is to change certain rules. Like one rule is subClassOf which give you specific class and its Parent class. Making a change so that it would be a subClassOf would give me any Property of that class or beside giving me the parent class it would return me the child of that class. Basic Aim is to play with axioms of jena API.

Thanks

Nikhil Gupta
  • 1,708
  • 1
  • 23
  • 38

1 Answers1

0

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();
Rob Hall
  • 2,693
  • 16
  • 22