Large discrepancies between owlready2 worlds and world as_rdflib_graph

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

Large discrepancies between owlready2 worlds and world as_rdflib_graph

Peter
Please can somebody explain the results of the code below, and how I can re-zero the world as_rdflib_graph when used in a loop


from owlready2 import *

files = [
    "https://raw.githubusercontent.com/CompGuideRepository/CompGuide-Editor/master/Cguide.owl",
    "http://individual.utoronto.ca/hesham/Ontology/IPDFull.owl",
    "https://raw.githubusercontent.com/ayesha-banu79/Owl-Ontology/master/Library%20Ontology.owl"
    ]

for i in files:
    new_world = owlready2.World()
    onto_nw = new_world.get_ontology(i).load()
    onto_dw = get_ontology(i).load()
    len_onto_nw = len(onto_nw.get_triples())
    len_onto_dw = len(onto_dw.get_triples())
    graph_nw = new_world.as_rdflib_graph()
    graph_dw = default_world.as_rdflib_graph()
    len_graph_nw = len(graph_nw)
    len_graph_dw = len(graph_dw)
    print(i)
    print(len_onto_dw, " : ", len_graph_dw, " : ",len_onto_nw, " : ", len_graph_nw)
    print("- - "*40)


https://raw.githubusercontent.com/CompGuideRepository/CompGuide-Editor/master/Cguide.owl
5075  :  5075  :  5075  :  5075
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
http://individual.utoronto.ca/hesham/Ontology/IPDFull.owl
1734  :  8456  :  1734  :  3381
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
https://raw.githubusercontent.com/ayesha-banu79/Owl-Ontology/master/Library%20Ontology.owl
406  :  8862  :  406  :  406
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Process finished with exit code 0
Reply | Threaded
Open this post in threaded view
|

Re: Large discrepancies between owlready2 worlds and world as_rdflib_graph

Jiba
Administrator
Hi,

The graph produced by default_world.as_rdflib_graph() corresponds to the entire default_world, thus having all ontologies.

To avoid that, you can use different worlds, destroy the undesired ontologies, or create a contextualized RDFLIB graph limited to a given ontology, as follows:

graph_dw2 = graph_dw.get_context(onto_dw)

However, notice that there is a bug in the current version of Owlready: ontologies created/loaded after the creation of the RDFLIB graph cannot be used in get_context().
I have just fixed this bug in the development version on Bitbucket.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Large discrepancies between owlready2 worlds and world as_rdflib_graph

Peter
I'm having problems getting this to work with my example.... if you have the time to flesh out your suggestion @Jiba I'd appreciate it.  I'm still getting errors
Reply | Threaded
Open this post in threaded view
|

Re: Large discrepancies between owlready2 worlds and world as_rdflib_graph

Jiba
Administrator
Hi,

graph_dw.get_context(onto_dw)  produces a graph restricted to the given ontology.

The code below is a simplified version of your code, using contextualized graph. As a consequence, the graph size is the same as the ontology size.

Jiba

----8<-----------------


for i in files:
    onto_dw = get_ontology(i).load()
    len_onto_dw = len(onto_dw.get_triples())
   
    graph_dw = default_world.as_rdflib_graph()
    graph_dw = graph_dw.get_context(onto_dw)

    len_graph_dw = len(graph_dw)
    print(i)
    print(len_onto_dw, " : ", len_graph_dw)

Reply | Threaded
Open this post in threaded view
|

Re: Large discrepancies between owlready2 worlds and world as_rdflib_graph

Peter
Thanks for adding that code.  I did similar but when using my list of ontologies - in the programme I added, this gives errors after the first ontology.  Do you know why this is please?
Reply | Threaded
Open this post in threaded view
|

Re: Large discrepancies between owlready2 worlds and world as_rdflib_graph

Jiba
Administrator
Sorry, without seeing your code, and the error message you get, it is very difficult to me to figure what happened wrong.

Jiba