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!
-
possible duplicate of [How to create an ontology in python?](http://stackoverflow.com/questions/1762291/how-to-create-an-ontology-in-python) – Sven Marnach Feb 23 '11 at 15:57
-
Just noticed that this is not a duplicate -- Please ignore my close vote (can't revoke it). – Sven Marnach Feb 23 '11 at 16:00
-
don't worry I will wait for an answer ;) – Hossein Feb 23 '11 at 16:02
5 Answers
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

- 36,608
- 11
- 63
- 88

- 5,747
- 1
- 25
- 41
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:
- Import OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format.
- Export OWL 2.0 ontologies to NTriples or RDF/XML.
- Manipulates ontology classes, instances and properties transparently, as if they were normal Python objects.
- Add Python methods to ontology classes.
- Perform automatic classification of classes and instances, using the HermiT reasoner.
- Tested up to 100 millions of RDF triples (but can potentially support more).
- In addition, the quadstore is compatible with the RDFlib Pyton module, which can be used to perform SPARQL queries.

- 51
- 3
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.

- 60,957
- 96
- 316
- 522