Issue with onto_world.instances()

classic Classic list List threaded Threaded
5 messages Options
MK
Reply | Threaded
Open this post in threaded view
|

Issue with onto_world.instances()

MK
Hello,
I'm encountering some issues with the functions in Owlready (particularly the instances() function) not returning the expected results and I'm hoping that someone can assist. I'm not sure whether it has to do with the format of the files that I'm using, but I can't see any issue with them:

When I load the following RDF file into the variable instance_world and run: list(instance_world.instances()), I get the following error:<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

        <rdf:Description rdf:about="http://example.com/foo">
                <rdf:type rdf:resource="http://example.com/bar"/>
        </rdf:Description>

</rdf:RDF>
Error:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-9eba4679c0c4> in <module>
----> 1 list(instance_world.instances())

AttributeError: 'World' object has no attribute 'instances'

I thought it might be that Owlready doesn't work with strictly rdf, so I tried another version of the same file:
<?xml version="1.0"?>
<rdf:RDF xmlns="/"
     xml:base="/"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology/>


    <owl:Class rdf:about="http://ontology.eil.utoronto.ca/icity/ESRI-GFX/GFXRoadSegment"/>

    <owl:NamedIndividual rdf:about="http://example.com/foo">
        <rdf:type rdf:resource="http://example.com/bar"/>
    </owl:NamedIndividual>
</rdf:RDF>

And still when I run list(instance_world.instances()), I get the same error.

I know the triple is being processed somehow because if I define the world as an rdf graph using rdflib I'm able to query it with the expected results. Any insight into this?

Thanks!

Megan
Reply | Threaded
Open this post in threaded view
|

Re: Issue with onto_world.instances()

Jiba
Administrator
Hi,

.instances() is a method available on classes (to get the instances of the class). For getting instances in an ontology (or a world), you should use .individuals().

Jiba
MK
Reply | Threaded
Open this post in threaded view
|

Re: Issue with onto_world.instances()

MK
Sorry about that oversight on my part, but I am still encountering an issue between the two file formats, one version recognizes the individuals whereas the other does not (see below):

When I load the following RDF file into the variable instance_world:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

        <rdf:Description rdf:about="http://example.com/foo">
                <rdf:type rdf:resource="http://example.com/bar"/>
        </rdf:Description>

</rdf:RDF>
And run: list(instance_world.individuals())
The result is an empty list. Whereas if I load the data in the alternate format:
<?xml version="1.0"?>
<rdf:RDF xmlns="/"
     xml:base="/"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
    <owl:Ontology/>
   
   
    <owl:Class rdf:about="http://example.com/bar"/>
   
   
    <owl:NamedIndividual rdf:about="http://example.com/foo">
        <rdf:type rdf:resource="http://example.com/bar"/>
    </owl:NamedIndividual>
</rdf:RDF>


Then list(instance_world.individuals()) correctly returns
[example.com.foo]
Reply | Threaded
Open this post in threaded view
|

Re: Issue with onto_world.instances()

Jiba
Administrator
Hi,

The problem is that your first file is an RDF file, but does not contain an OWL ontology, nor it contain any OWL individuals (= NamedIndividual).

Owlready can load RDF file, but only those that contains OWL entities, not plain RDF entities.

Jiba
MK
Reply | Threaded
Open this post in threaded view
|

Re: Issue with onto_world.instances()

MK
Hi Jiba,
Thank you, I had suspected that might be the case, so that is helpful. I thought it might be useful to add that this issue came about because such statements were output via the ontop OBDA tool. This was initially confusing because I was able to load the files into Protege, but not with Owlready.
Thanks again,
Megan