Hi,
Here is a small example that shows how to use SWRL rule and then to query the results with Owlready and with SPARQL.
Jiba
from owlready2 import *
onto = get_ontology("
http://test.org/onto.owl")
with onto:
class Animal(Thing): pass
class Bird(Animal): pass
class Organ(Thing): pass
class Wing(Organ): pass
class has_organ(Animal >> Organ): pass
t = Animal("t")
t.has_organ.append(Wing())
imp = Imp()
imp.set_as_rule("Animal(?a), Wing(?o), has_organ(?a, ?o) -> Bird(?a)")
sync_reasoner_pellet()
print(list(Bird.instances()))
graph = default_world.as_rdflib_graph()
print(list(graph.query_owlready("""
SELECT ?b WHERE {
?b <
http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <
http://test.org/onto.owl#Bird> .
} """)))