You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Martynas Jusevičius <ma...@graphity.org> on 2015/09/03 12:46:15 UTC

Materializing custom rules on OntModel

Hey list,

I was implementing a OO-like inheritance for annotation properties
when I realized I can probably express it as custom Jena rules. I want
to push the properties down the subclass chains and preferably
materialize them. Currently my code looks like this:

        String rules = "[inheritance: (?class ?p ?o), (?p rdf:type
owl:AnnotationProperty), (?subClass rdfs:subClassOf ?class),
noValue(?subClass ?p) -> (?subClass ?p ?o) ]";
        Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
        reasoner.setDerivationLogging(true);
        reasoner.setParameter(ReasonerVocabulary.PROPtraceOn, Boolean.TRUE);
        OntModel ontModel =
OntDocumentManager.getInstance().getOntology(ontologyURI,
OntModelSpec.OWL_MEM);
        reasoner.bindSchema(ontModel);
        ontModel.prepare();

This does not seem to work however - subclasses without annotations do
not seem to inherit them from superclasses. Could the rule be wrong?
Should I be constructing the OntModel with a custom OntModelSpec
instead of bindSchema()? Or could it be smth else altogether?

Thanks.

Martynas

Re: Materializing custom rules on OntModel

Posted by Martynas Jusevičius <ma...@graphity.org>.
Thanks, that worked.

On Thu, Sep 3, 2015 at 2:23 PM, Dave Reynolds <da...@gmail.com> wrote:
> On 03/09/15 11:46, Martynas Jusevičius wrote:
>>
>> Hey list,
>>
>> I was implementing a OO-like inheritance for annotation properties
>> when I realized I can probably express it as custom Jena rules. I want
>> to push the properties down the subclass chains and preferably
>> materialize them. Currently my code looks like this:
>>
>>          String rules = "[inheritance: (?class ?p ?o), (?p rdf:type
>> owl:AnnotationProperty), (?subClass rdfs:subClassOf ?class),
>> noValue(?subClass ?p) -> (?subClass ?p ?o) ]";
>>          Reasoner reasoner = new
>> GenericRuleReasoner(Rule.parseRules(rules));
>>          reasoner.setDerivationLogging(true);
>>          reasoner.setParameter(ReasonerVocabulary.PROPtraceOn,
>> Boolean.TRUE);
>>          OntModel ontModel =
>> OntDocumentManager.getInstance().getOntology(ontologyURI,
>> OntModelSpec.OWL_MEM);
>>          reasoner.bindSchema(ontModel);
>>          ontModel.prepare();
>>
>> This does not seem to work however - subclasses without annotations do
>> not seem to inherit them from superclasses. Could the rule be wrong?
>> Should I be constructing the OntModel with a custom OntModelSpec
>> instead of bindSchema()?
>
>
> The latter. The bindSchema call isn't side-effecting, what it does is return
> a new reasoner that now "knows" about the ontology data. It changes neither
> the original reasoner nor the model you feed in.
>
> You want something more like:
>
>     OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
>     spec.setReasoner(reasoner);
>     OntModel ontModel = ModelFactory.createOntologyModel(spec, ...);
>
> Dave

Re: Materializing custom rules on OntModel

Posted by Dave Reynolds <da...@gmail.com>.
On 03/09/15 11:46, Martynas Jusevičius wrote:
> Hey list,
>
> I was implementing a OO-like inheritance for annotation properties
> when I realized I can probably express it as custom Jena rules. I want
> to push the properties down the subclass chains and preferably
> materialize them. Currently my code looks like this:
>
>          String rules = "[inheritance: (?class ?p ?o), (?p rdf:type
> owl:AnnotationProperty), (?subClass rdfs:subClassOf ?class),
> noValue(?subClass ?p) -> (?subClass ?p ?o) ]";
>          Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
>          reasoner.setDerivationLogging(true);
>          reasoner.setParameter(ReasonerVocabulary.PROPtraceOn, Boolean.TRUE);
>          OntModel ontModel =
> OntDocumentManager.getInstance().getOntology(ontologyURI,
> OntModelSpec.OWL_MEM);
>          reasoner.bindSchema(ontModel);
>          ontModel.prepare();
>
> This does not seem to work however - subclasses without annotations do
> not seem to inherit them from superclasses. Could the rule be wrong?
> Should I be constructing the OntModel with a custom OntModelSpec
> instead of bindSchema()?

The latter. The bindSchema call isn't side-effecting, what it does is 
return a new reasoner that now "knows" about the ontology data. It 
changes neither the original reasoner nor the model you feed in.

You want something more like:

     OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
     spec.setReasoner(reasoner);
     OntModel ontModel = ModelFactory.createOntologyModel(spec, ...);

Dave