Extract the triples from the existed owl file

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

Extract the triples from the existed owl file

small_tadpole
Hi:
        First, I load the wine owl file:
                   path = './data/wine.owl'
                   onto = get_ontology(path).load()
                   all_triples = onto.get_triples(None, None, None)
                   print(list(all_triples))
        Then, I get the result as follows:
                   [('4S', '6', '19'), ('4S', 'D', '"An example OWL ontology"'), ('4T', '6', '19'), ('4S', '1H', '4T'), ('4S', '1a', '4U'), ...]
        But, what I want is like this:
                   [('wine', 'hasColor', 'red'), ...]
        Can you help me with getting the result as I want?
        Thank you very much!
Best Wishes!

Reply | Threaded
Open this post in threaded view
|

Re: Extract the triples from the existed owl file

Jiba
Administrator
Hello,

> Then, I get the result as follows:
> [('4S', '6', '19'), ('4S', 'D', '"An example OWL ontology"'), ('4T', '6', '19'), ('4S', '1H', '4T'), ('4S', '1a', '4U'), ...]

These are triples in an "abbreviated" format (used by Olwready to reduce the size of the quadstore).

You can use onto.unabbreviate("4S"), etc, to remove those abbreviations.

You may also use onto.graph.dump() to show the entire quadstore without abbreviation, or use onto.save() to save it in NTriples format.

Best regards,
Jean-Baptiste Lamy
MCF HDR, Laboratoire LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: Extract the triples from the existed owl file

small_tadpole
Hi Jean-Baptiste,

Thanks for the fast reply :)
        I have tried the onto.unabbreviate("4S") you told me, it worked indeed! The result as follows:
                       http://www.w3.org/2001/sw/WebOnt/guide-src/wine#
       And I use onto.save(filepath) got a file as follows:
<owl:Class rdf:about="#Wine">
  <rdfs:subClassOf rdf:resource="http://www.w3.org/2001/sw/WebOnt/guide-src/food#PotableLiquid"/>
  <rdfs:subClassOf>
    <owl:Restriction>
...
</owl:Class>

        Can I get the triples like ('wine', 'subClassOf' ,'PotableLiquid') directly?
        Thanks very much!
Reply | Threaded
Open this post in threaded view
|

Re: Extract the triples from the existed owl file

Jiba
Administrator
Hello,

You need to specify the format : onto.save(file, format = "ntriples")

Best regards,
Jean-Baptiste Lamy
MCF HDR, Laboratoire LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: Extract the triples from the existed owl file

Philipp
I'm using the latest version of owlready2. Unfortunately neither .unabbreviate(), not graph.dump(), nor saving as ntriples seem to work. I always get the abbreviated output.

Is there a wy to get the "unabbreviated" triples in owlready2?

Thanks a lot!

ps: Is there a way to access axioms (already discussed in http://owlready.8326.n8.nabble.com/Accessing-the-axioms-and-axiom-closure-of-an-ontology-td217.html) or is the only way still to access the triples and build axioms thereof?
Reply | Threaded
Open this post in threaded view
|

Re: Extract the triples from the existed owl file

Jiba
Administrator
Hello,

There is no "axiom" level in Owlready, there are only the RDF triple level in the quadstore, and the object level in Python (which sometimes corresponds to axioms, but not always).

Notice that older versions of Owlready use string as abbreviated IRI, while newer use integer (I thus guess you are using an old version).

To unabbreviate triples, you need to unabbreviate each component separately (unabbreviate accepts a single argument, not a triple).

Jiba