Working with owl files of directory

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

Working with owl files of directory

Hamico
Hi guys,
I wanted to ask you a question relating more python than owlready2. I want to know how to have in input files of different name .owl in a same directory (also current directory) so that you can read them and then write the same thing on them in group.

For example:

import os
file = os.listdir(‘.’)
onto = get_ontology(file).load()
with onto:
     class Car(Thing):
           pass
onto.save(file=file, format=“rdfxml”)

How is possible to do it?

Many thanks.
Best regards,
Hamico

Reply | Threaded
Open this post in threaded view
|

Re: Working with owl files of directory

Hamico
This post was updated on .
I have solved. I post my code. I hope it can be useful for other users.

from owlready2 import *
import os
for file in os.listdir(‘C://Users//hamico//Desktop//Ontology’):
       if file.endswith(“.owl”):
            onto = get_ontology(file).load()
            namespace = onto.get_namespace(“C:/Users/hamico/Desktop/Ontology/test.owl”)
            with namespace:
                  class Car(Thing):
                        pass
            onto.save(file=file, format=“rdfxml”)

Best regards,
Hamico