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!
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.
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
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With