How can I access specific constraints such as someValuesFrom?

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

How can I access specific constraints such as someValuesFrom?

Rickshow
Good everyone, I am having problems accessing the restrictions, I will show an example of owl text with restrictions:

    <owl:Class rdf:about="https://------/ontology/example/example/RotationMode">
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="https://Example/Example/servesToRotate"/>
                <owl:someValuesFrom rdf:resource="https://Example/Example/Wheel"/>
            </owl:Restriction>





The thing is that at the moment I can access the onProperty with the is_a class using '.Restriction' but I need to access 'someValuesFrom' and any other that I need. How can I do it? The use of hasattr(example, 'someValuesFrom') doesn't work either.


Thanks for your help!
Reply | Threaded
Open this post in threaded view
|

Re: How can I access specific constraints such as someValuesFrom?

Jiba
Administrator
Hello,

When you have a restriction, you can use the following properties on it:

type : SOME, ONLY, VALUE, MIN, MAX, EXACTLY
property : the onProperty
value : the range of the restriction (i.e. the entity referenced by someValuesFrom / allValuesFrom)
cardinality : the number (for MIN / MAX / EXACTLY only)

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How can I access specific constraints such as someValuesFrom?

Rickshow
I read your answer and have been trying to understand it, could you give me an example of accessing an AllValuesFrom constraint?

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: How can I access specific constraints such as someValuesFrom?

Jiba
Administrator
Here is an example:


from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")

with onto:
  class C(Thing): pass
  class prop(Thing >> Thing): pass
  class D(C):
    is_a = [prop.only(C)]

for i in D.is_a:
  if isinstance(i, Restriction):
    if i.type == ONLY:
      print("AllValuesFrom restriction on property", i.property, "and class", i.value)


=>
AllValuesFrom restriction on property onto.prop and class onto.C