You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Birte Glimm <bi...@uni-ulm.de> on 2012/10/18 09:47:27 UTC

RDFS inference missing

Hi,

I am trying to use ARQ (2.9.3) in combination with Jena (2.7.3) to
answer SPARQL queries with RDFS inferences. I'm missing, however, one
inference that is not derived by Jena. Below is a simple code snippet
that illustrates the problem. Given (ex:x rdf:type ex:c), Jena does
not derive (ex:c rdfs:subClassOf ex:c) although it derives (ex:c
rdf:type rdfs:Class), which should, via rule rdfs10, give (ex:c
rdfs:subClassOf ex:c). Any idea why that triple is not derived?

Cheers,

Birte

String NS = "http://example.org/";
Model model = ModelFactory.createDefaultModel();
Resource x = model.createResource(NS+"x");
Resource c = model.createResource(NS+"c");
model.add(x, RDF.type, c);
Reasoner reasoner=RDFSRuleReasonerFactory.theInstance().create(null);
reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel,
  ReasonerVocabulary.RDFS_FULL);
InfModel infModel=ModelFactory.createInfModel(reasoner, model);
infModel.prepare(); // just to be sure
System.out.println("Contains (ex:c rdfs:subClassOf ex:c) ? "
  +infModel.contains(c, RDFS.subClassOf, c));
// prints false
System.out.println("Contains (ex:c rdf:type rdfs:Class) ? "
  +infModel.contains(c, RDF.type, RDFS.Class));
// prints true

-- 
Jun. Prof. Dr. Birte Glimm            Tel.:    +49 731 50 24125
Inst. of Artificial Intelligence         Secr:  +49 731 50 24258
University of Ulm                         Fax:   +49 731 50 24188
D-89069 Ulm                               birte.glimm@uni-ulm.de
Germany

Re: RDFS inference missing

Posted by Birte Glimm <bi...@uni-ulm.de>.
Thanks Dave, that fix worked.

Birte

On 18 October 2012 10:21, Dave Reynolds <da...@gmail.com> wrote:
> On 18/10/12 08:47, Birte Glimm wrote:
>>
>> Hi,
>>
>> I am trying to use ARQ (2.9.3) in combination with Jena (2.7.3) to
>> answer SPARQL queries with RDFS inferences. I'm missing, however, one
>> inference that is not derived by Jena. Below is a simple code snippet
>> that illustrates the problem. Given (ex:x rdf:type ex:c), Jena does
>> not derive (ex:c rdfs:subClassOf ex:c) although it derives (ex:c
>> rdf:type rdfs:Class), which should, via rule rdfs10, give (ex:c
>> rdfs:subClassOf ex:c). Any idea why that triple is not derived?
>
>
> It's a layering bug. The RDFS rule set uses a mix of forward and backward
> inference to try to get marginally better scaling. What's happening is that
> the (ex:c rdf:type rdfs:Class) inference is only computed backwards and
> doesn't trigger the forward inference of the reflexive subClassOf.
>
> A work around would be to extend the rule set.
>
> Define your own rule set:
>
> [[
> @include <RDFS>.
>
> # Forward inference of rdfs:Class
> [rdfs-fix: (?i rdf:type ?c) -> (?c rdf:type rdfs:Class)]
>
> # Missing from default RDFS rules but necessary for FULL
> [rdf1and4: (?x ?p ?y) -> (?p rdf:type rdf:Property),
>            (?x rdf:type rdfs:Resource), (?y rdf:type rdfs:Resource)]
> ]]
>
> Then use that instead of the RDFS_FULL configuration:
>
>         List<Rule> rules = Rule.rulesFromURL("file:data/test.rules");
>         GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
>         reasoner.setTransitiveClosureCaching(true);
>
> Dave
>



-- 
Jun. Prof. Dr. Birte Glimm            Tel.:    +49 731 50 24125
Inst. of Artificial Intelligence         Secr:  +49 731 50 24258
University of Ulm                         Fax:   +49 731 50 24188
D-89069 Ulm                               birte.glimm@uni-ulm.de
Germany

Re: RDFS inference missing

Posted by Dave Reynolds <da...@gmail.com>.
On 18/10/12 08:47, Birte Glimm wrote:
> Hi,
>
> I am trying to use ARQ (2.9.3) in combination with Jena (2.7.3) to
> answer SPARQL queries with RDFS inferences. I'm missing, however, one
> inference that is not derived by Jena. Below is a simple code snippet
> that illustrates the problem. Given (ex:x rdf:type ex:c), Jena does
> not derive (ex:c rdfs:subClassOf ex:c) although it derives (ex:c
> rdf:type rdfs:Class), which should, via rule rdfs10, give (ex:c
> rdfs:subClassOf ex:c). Any idea why that triple is not derived?

It's a layering bug. The RDFS rule set uses a mix of forward and 
backward inference to try to get marginally better scaling. What's 
happening is that the (ex:c rdf:type rdfs:Class) inference is only 
computed backwards and doesn't trigger the forward inference of the 
reflexive subClassOf.

A work around would be to extend the rule set.

Define your own rule set:

[[
@include <RDFS>.

# Forward inference of rdfs:Class
[rdfs-fix: (?i rdf:type ?c) -> (?c rdf:type rdfs:Class)]

# Missing from default RDFS rules but necessary for FULL
[rdf1and4: (?x ?p ?y) -> (?p rdf:type rdf:Property),
            (?x rdf:type rdfs:Resource), (?y rdf:type rdfs:Resource)]
]]

Then use that instead of the RDFS_FULL configuration:

         List<Rule> rules = Rule.rulesFromURL("file:data/test.rules");
         GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
         reasoner.setTransitiveClosureCaching(true);

Dave