althonos/pronto

Latest hp.owl fails due to SynonymTypeProperty w/o label with AttributeError: 'NoneType' object has no attribute 'text'

davmlaw opened this issue · 1 comments

If elem.find returns None it fails as the test is against the .text value not the return from find, ie:

/usr/local/lib/python3.8/dist-packages/pronto/parsers/rdfxml.py in parse_from(self, handle, threads)
    113                 self._extract_object_property(prop, curies)
    114             for prop in tree.iterfind(_NS["owl"]["AnnotationProperty"]):
--> 115                 self._extract_annotation_property(prop, curies)
    116             for class_ in tree.iterfind(_NS["owl"]["Class"]):
    117                 self._extract_term(class_, curies)

/usr/local/lib/python3.8/dist-packages/pronto/parsers/rdfxml.py in _extract_annotation_property(self, elem, curies)
    666             if resource == _NS["oboInOwl"].raw("SynonymTypeProperty"):
    667                 # extract ID and label of the synonymtypedef
--> 668                 label = elem.find(_NS["rdfs"]["label"]).text
    669                 if label is None:
    670                     label = ""

AttributeError: 'NoneType' object has no attribute 'text'

File from:

https://raw.githubusercontent.com/obophenotype/human-phenotype-ontology/master/hp.owl

I have been able to reproduce with a test file that contains:

    <owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/caloha-reqs-vetted#PLURAL">
        <rdfs:subPropertyOf rdf:resource="http://www.geneontology.org/formats/oboInOwl#SynonymTypeProperty"/>
    </owl:AnnotationProperty>

I fixed it locally by moving the test onto the element returned from find rather than element.text ie

                label_element = elem.find(_NS["rdfs"]["label"])
                if label_element:
                    label = label_element.text
                else:
                    label = ""
                    warnings.warn(
                        "`oboInOwl:SynonymTypeProperty` element has no label",
                        SyntaxWarning,
                        stacklevel=3,
                    )

Closed in #179 (thanks again).