jena-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Reynolds <>
Subject Re: I think I've got some pretty basic confusion with reading into models
Date Thu, 09 Dec 2010 16:04:39 GMT
Hi Benson,

On Thu, 2010-12-09 at 09:11 -0500, Benson Margulies wrote: 
> Here's a little RDF snippet:
> <rdf:RDF
>     xmlns:rdf=""
>     xmlns:rex=""
>     xmlns:owl=""
>     xmlns:xsd=""
>     xmlns:rdfs="">
>   <rex:Location rdf:about="uri:c6c54ebb-a232-48cd-80fa-e4adf9cc5001#3">
>     <rex:hasOriginalText rdf:datatype=""
>     >Pakistan</rex:hasOriginalText>
>     <rex:hasNormalizedText
> rdf:datatype=""
>     >Pakistan</rex:hasNormalizedText>
>     <rex:hasEntityDetectionSource
> rdf:datatype=""
>     >gazetteer:../../../bt_root/rlp/rlp/dicts/en-all-gazetteer-LE.bin</rex:hasEntityDetectionSource>
>   </rex:Location>
> </rdf:RDF>
> The following rather trivial test fails. I'm sure I'm just befuddled,
> could some kind soul rescue me?
>         OntModel model = ModelFactory.createOntologyModel();
>, "", "RDF/XML-ABBREV");
>         ExtendedIterator<Individual> individuals = model.listIndividuals();
>         int individualCount = 0;
>         while (individuals.hasNext()) {
>             individualCount++;
>         }
>         assertTrue("Should have more than two individuals, but got " +
> individualCount, individualCount > 0);

Actually that's a tricky area :)

For OWL then we treat an individual as being anything of type

If you have an OWL-capable reasoner configured for the OntModel then the
code can just query for that directly. If you don't then it looks for
all resources whose declared type is itself an owl:Class (and not part
of the OWL/RDFS "furniture").

Since you don't have a declaration of rex:Location anywhere then nothing

Since your test comment suggest you are expecting at least 2 then I'm
guessing you mean to count rex:Location as well so you are probably just
after resources mentioned rather than Individuals in the OWL sense. In
that case try:

       OntModel model =
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);"file:data/temp2.rdf", "", "RDF/XML-ABBREV");
        ExtendedIterator<RDFNode> nodes =
model.listObjects().andThen( model.listSubjects() );
        int count = 0;
        while ( nodes.hasNext() ) {
            if ( count ++;

Note the explicit OntModelSpec to turn off the default RDFS reasoner
which would otherwise complicate things.

Actually checking this out revealed a possible bug in this area. RDFS
reasoning can infer that rex:Location is a rdfs:Class so if you set the
OntModel profile to RDFS then uri:c6c54ebb-a232-48cd-80fa-e4adf9cc5001#3
is treated as an individual. The trouble is that a lot of stuff in the
background RDFS knowledge are also treated as Individuals (28 of them
including things that are rdfs:Class/rdf:Property). While technically
correct (because in RDFS all resources are Individuals) I would have
expected the OntModel conventions to filter those out. Ian will log a
JIRA case the check this out (assuming he can get access to JIRA).


View raw message