Harold-Solbrig / funowl

Pythonic representation of OWL through the OWL functional syntax
Creative Commons Zero v1.0 Universal
50 stars 5 forks source link

SubObjectPropertyOf axioms are somewhat complex #19

Open cmungall opened 3 years ago

cmungall commented 3 years ago

Parsing this:

SubObjectPropertyOf(:activity :influencer)

yields this axiom object:

SubObjectPropertyOf(subObjectPropertyExpression=SubObjectPropertyExpression(v=ObjectPropertyExpression(v=ObjectProperty(v=':activity'))), superObjectPropertyExpression=ObjectPropertyExpression(v=ObjectProperty(v=':influencer')), annotations=[])

This is kinda awkward to work with. All I want to do is reconstruct a basic property hierarchy, as shown here:

image

(this is prov)

My code is already quite complex:

if isinstance(a, SubObjectPropertyOf):
                print(f'SUB: {a}')
                if isinstance(a.subObjectPropertyExpression, ObjectProperty):
                    child = self.iri_to_name(a.subObjectPropertyExpression)
                    if isinstance(a.superObjectPropertyExpression, ObjectProperty):
                        parent = self.iri_to_name(a.superObjectPropertyExpression)
                        print(f'{child} < {parent}')
                        slot_isamap[child].add(parent)
                    else:
                        logging.error(f"cannot handle anon parent properties for {a}")
                else:
                    print(f"cannot handle anon child properties for {a}")

but this doesn't work as it seems I have to check various levels of .v objects?

cmungall commented 3 years ago

I figured out how to do it:

if isinstance(a, SubObjectPropertyOf):
                sub = a.subObjectPropertyExpression.v
                if isinstance(sub, ObjectPropertyExpression) and isinstance(sub.v, ObjectProperty):
                    child = self.iri_to_name(sub.v)
                    sup = a.superObjectPropertyExpression.v
                    if isinstance(sup, ObjectPropertyExpression) and isinstance(sup.v, ObjectProperty):
                        parent = self.iri_to_name(sup.v)
                        print(f'{child} < {parent}')
                        slot_isamap[child].add(parent)
                    else:
                        logging.error(f"cannot handle anon parent properties for {a}")
                else:
                    print(f"cannot handle anon child properties for {a}")

but this seems a little complex

hsolbrig commented 2 years ago

Lets use this as one of the first tests for issue #42