Re: Loading OWL imports from local
Posted by
Peter on
URL: http://owlready.306.s1.nabble.com/Loading-OWL-imports-from-local-tp1606p1609.html
An ontology in owlready has an attribute ".imported_ontologies" which is a list, so you can append to it, as documented in
https://pythonhosted.org/Owlready2/onto.html#importing-other-ontologiese.g. onto.imported_ontologies.append(pizzaOnto)
a full code example for importing from a local file is something like this:
from owlready2 import *
default_world.set_backend(filename = "./importTest.file.sqlite3")
pizzaOwl = "file://C:/Users/Pedro/Documents/vocabs/owl/pizza.owl"
pizzaOnto = get_ontology(pizzaOwl).load()
onto = get_ontology("
http://myOntology.org/example/one/")
# Annotation Properties
with onto:
class myPrefLabel(AnnotationProperty):
label = "my preferred label"
class myAltLabel(AnnotationProperty):
label = "my alternative label"
onto.imported_ontologies.append(pizzaOnto)
#-----------------------
default_world.save()
onto.save(file = r".\2020-01-08_owlready2_example.rdf", format = "rdfxml")
onto.save(file = r".\2020-01-08_owlready2_example.n3", format = "ntriples")
graph = default_world.as_rdflib_graph()
Query = '''prefix owl:<
http://www.w3.org/2002/07/owl#>
SELECT distinct ?ap WHERE {
?ap a owl:AnnotationProperty .
} limit 20'''
results = graph.query(Query)
for i in results:
print(i)