Posted by
Jiba on
URL: http://owlready.306.s1.nabble.com/How-to-access-owl-Axiom-tp3406p3409.html
Hi,
If you want to search for all such axioms, the best option is to use a SPARQL query. Here is an example:
onto = get_ontology("
http://example.org/onto.owl")
with onto:
class C(Thing): pass
class p (C >> int): pass
class p2(C >> int): pass
c1 = C()
c1.p = [1]
comment[c1, p, 1] = "comment"
a = AnnotatedRelation(c1, p, 1)
a.comment = ["a comment on the relation"]
a.label = ["relation label"]
l = default_world.sparql("""
SELECT ?source ?target {
?x owl:annotatedSource ?source .
?x owl:annotatedProperty onto:p .
?x owl:annotatedTarget ?target .
}
""")
for source, target in l:
a = AnnotatedRelation(source, p, target)
print(a, a.get_properties())
You can either use AnnotatedRelation to modify the axiom, or using more complex SPARQL queries to perform the modification, e.g.:
with onto:
default_world.sparql("""
INSERT {
?x owl:annotatedProperty onto:p2 .
} WHERE {
?x owl:annotatedSource ?source .
?x owl:annotatedProperty onto:p .
?x owl:annotatedTarget ?target .
}
""")
default_world.sparql("""
DELETE {
?x owl:annotatedProperty onto:p .
} WHERE {
?x owl:annotatedSource ?source .
?x owl:annotatedProperty onto:p .
?x owl:annotatedTarget ?target .
}
""")
Best regards,
Jiba