Hi,
Sorry for my rookie question: my classes have <owl:Axiom> sections. A typical ex: <owl:Axiom> <owl:annotatedSource rdf:resource="http://xxxxxxx/ID1"/> <owl:annotatedProperty rdf:resource="http://XXXXXXX/core#CONCEPT_hasMapping"/> <owl:annotatedTarget rdf:resource="http://id.nlm.nih.gov/mesh/D016584"/> <dcterm:source>IDMESH</dcterm:source> <rdfs:label>Panic Disorder</rdfs:label> </owl:Axiom> I haven't found how to access and modify their content. Many thanks in advance and kind regards, fsutter |
Administrator
|
Hi,
These axioms, used for annotating relations, can be accessed in Owlready as follows : * Old notations (still supported) : annotation[source, property, target] where annotation is the annotation property (e.g. label in your example), and source, property and target are the annotatedSource, annotatedProperty and annotatedTarget. * New notation : AnnotatedRelation(source, property, target) object, and then use .annotation to access the various annotation (e.g. .label). Access is both read and write. Here is an example: onto = get_ontology("http://example.org/onto.owl") with onto: class C(Thing): pass class p(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"] Best regards, Jiba |
Hi,
thanks for the reply. Maybe I should better explain what I want to achieve: In the file I've currently a lot of block like that: <owl:Axiom> <owl:annotatedSource rdf:resource="http://xxxxxxx/ID1"/> <owl:annotatedProperty rdf:resource="http://XXXXXXX/core#CONCEPT_hasMapping"/> <owl:annotatedTarget rdf:resource="http://id.nlm.nih.gov/mesh/D016584"/> <dcterm:source>IDMESH</dcterm:source> <rdfs:label>Panic Disorder</rdfs:label> </owl:Axiom> And want to replace <owl:annotatedProperty rdf:resource="http://XXXXXXX/core#CONCEPT_hasMapping"/> depending of the value of dcterm:source So I need two things: * have a way to find all AnnotatedRelation with annotatedProperty == http://XXXXXXX/core#CONCEPT_hasMapping * replace http://XXXXXXX/core#CONCEPT_hasMapping I can access a specif disease with this code: disease_ontology = get_ontology("class.owl").load() disease = disease_ontology["ID1"] But after I don't know how to continue. Once again, sorry fo my stupid questions. Thanks a lot |
Administrator
|
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 |
Free forum by Nabble | Edit this page |