9

I have an Ontology written in OWL. Does anyone know I can load it into python? any packages or even manually? rdflib which is mentioned in other questions is not suitable for me because it mainly concerns with RDF and "Seth" which is a very nice library doesn't work, because it requires "Pellet" library for which the website seems to be down and it(seth) also only works with JVM 1.4!

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Hossein
  • 40,161
  • 57
  • 141
  • 175

5 Answers5

2

Within rdfAlchemy in the commands.py file there is commands section that was started for just this purpose. Haven't used it in a while but it is the beginings of exactly what you asked about i.e. creating the python skel from an ontology.

In fact, it uses paster "commands". If you go to the rdfalchemy subdir and type:

paster rdfSubject -h

you should see:

Usage: /home/phil/venv/some_path/bin/paster rdfSubject [options] 
paster rdfalchemy.commands
Create an rdfSubject subclass with descriptors from an RDF Schema

    will set the rdf_type
    Descriptors will be created
    
      1.  rdfs:domain and rdfs:range are respected
      2.  rdfSingle is used for properties that are
            * owl:InverseFunctionalProperty
            * owl:FunctionalProperty   
      3.  rdfList or rdfContainer is used if the proper range is set
      4.  rdfMultiple is used for all others
      
    The resulting .py file is ment to be a skeleton for the developers confvience.  
    Do not expect to be able to use the raw results.
    
Create an rdfSubject subclass with descriptors from an RDF Schema

Options:
  -h, --help            show this help message and exit
  -v, --verbose         
  -n, --simulate        
  -s SCHEMA, --schema=SCHEMA
                        file name or url of rdfSchema for this class
  -o FOUT, --fout=FOUT  output file name default: stdout (e.g.
                        ../MyRdfModel.py)
  -l, --list            list valid instances of `owl:Class` in the schema file
Lutz Prechelt
  • 36,608
  • 11
  • 63
  • 88
Phil Cooper
  • 5,747
  • 1
  • 25
  • 41
2

In case anyone stumbles across this question again, this package is now available for interacting with OWL ontologies in Python: https://pypi.org/project/Owlready2/

From the project description, it has these capabilities:

  1. Import OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format.
  2. Export OWL 2.0 ontologies to NTriples or RDF/XML.
  3. Manipulates ontology classes, instances and properties transparently, as if they were normal Python objects.
  4. Add Python methods to ontology classes.
  5. Perform automatic classification of classes and instances, using the HermiT reasoner.
  6. Tested up to 100 millions of RDF triples (but can potentially support more).
  7. In addition, the quadstore is compatible with the RDFlib Pyton module, which can be used to perform SPARQL queries.
rosemcc
  • 51
  • 3
2

I've not fully tried this, but you could look at loading your ontology into a Sesame database and then query it using a Python wrapper. I've played with RDFAlchemy and pySesame a little, but I still don't have a feel for how good they are. RDF/OWL databases feel very immature to me in general, so expect to encounter some significant technical hurtles.

Cerin
  • 60,957
  • 96
  • 316
  • 522
1

Right, RDFLib works at the RDF semantics, so you'd need a toolkit for managing OWL semantics.

What I usually do it to first use another tool to get all the triples (OWLAPI or OWLRL, for instance) and then load it in RDFLib.

wikier
  • 2,517
  • 2
  • 26
  • 39
0

I could also find this ordf but it seems that they have just written some text for themsleves it is not clear at all how to use it, it's a pity!

Hossein
  • 40,161
  • 57
  • 141
  • 175