Parsing the restriction of a class for OR logic (owlready2.class_construct.Or)

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

Parsing the restriction of a class for OR logic (owlready2.class_construct.Or)

Mehmed
Dear JiBa and friends!

I am working currently on a project to support the design of robot construction and I use the ontology to get the robot construction rules as meta models. I read the class of a robot part, which has differnt restrictions like below.

Legged_Platform (a subclass of Robot_Platform of Robot_Subsystem class)
 * Equivalent_To:  
   * Robot_Platform
     * and (hasNumberOfLeg exactly 1 xsd:int[>= "1"^^xsd:int])
 * Subclass Of (Annonymous_Ancestor): (# The restrictions from Robot_Platfrom and Electrical_Device classes)
   * Robot_Platform
     * and ((hasNumberOfLeg exactly 1 xsd:int[> "0"^^xsd:int]) or (hasNumberOfWheel exactly 1 xsd:int[> "0"^^xsd:int]))
     * and (isSufficientForLocomotion some Locomotion_Capability)
     * and (hasRobotSubSystem min 1 Battery_Subsystem)
     * and (hasPayloadCapacity exactly 1 rdfs:Literal)
   * hasElectricalDeviceType some Electrical_Load

My task is to find all releated restrictions (Equivalent To and Subclass of (Anonymous Ancestors) of a class)  and parse each restriction to export it. I implemented the following code:

....
for o in (system_modelling.Robot_Subsystem.subclasses ()):
    for s in o.descendants(include_self = False): # Get the robot platfrom types
        print('\n>', s.name, '\n')
        for l in s.ancestors(include_constructs = True): # find the all relations with grand relatives and restrictions
            restrictionParser(l)
....
def restrictionParser(l):
    if (isinstance(l, owlready2.class_construct.Not) or
        isinstance(l, owlready2.class_construct.And) or
        isinstance(l, owlready2.class_construct.Or)):
             for p in l.is_a:
                print('call for', type(p), '\n',p)#, 'call parser for', p)
                if isinstance(p, owlready2.class_construct.Or):
                    print(p.is_a) # is_a returns  () for OR ???
                restrictionParser(p)
    elif (isinstance(l, owlready2.class_construct.Restriction)):
        print(type(l))
        print(l.property.name,
              l.value,
              owlready2.class_construct._restriction_type_2_label[l.type],
              l.property.range,
              l.cardinality,'\n')
    else: # ignore Thing Class Type members
        print('not parsed',type(l), l.name)
.....


The code takes the descendants of a class, which contain several axioms, that can be composed from other axioms as logic statement (AND,OR) and parse it. It works for "owlready2.class_construct.And" and "owlready2.class_construct.Restriction" well. But for "owlready2.class_construct.Or" it doesnt work.

Before I try to find another way, I would like to ask you:
-Similar to owlready2.class_construct.And, can owlready2.class_construct.Or get the results for  "is_a" as well?  In my case it is empty.

Thank you in advance!
Greetings and regards,
Mehmed
Reply | Threaded
Open this post in threaded view
|

Re: Parsing the restriction of a class for OR logic (owlready2.class_construct.Or)

Mehmed
I understood that for owlready2.class_construct.Or I need to use ".Classes" so that I get the return as  owlready2.util.CallbackList type

Thanks