dkpro / dkpro-cassis

UIMA CAS processing library written in Python
https://pypi.org/project/dkpro-cassis/
Apache License 2.0
85 stars 22 forks source link

Resolve reference to sofa for nested FeatureStructure #133

Closed jcklie closed 4 years ago

jcklie commented 4 years ago

For the following typesystem and xml:

https://drive.google.com/drive/folders/1GqWanaAB9Duj8orYLTDtfNILv3OmZD24?usp=sharing

with open('typesystem.xml', 'rb') as f:
    typesystem = load_typesystem(f)

cas = load_cas_from_xmi(open('simple.xml', 'rb'), typesystem=typesystem)

cas.to_xmi( path="../output_dir/simple_out.xml" )  

I get the following error after loading to cas, and then creating an xmi representation:

...
xmi.py in _serialize_feature_structure(self, cas, root, fs)
    365                     child.text = e
    366             elif feature_name == "sofa":
--> 367                 elem.attrib[feature_name] = str(value.xmiID)
    368             elif ts.is_primitive(feature.rangeTypeName):
    369                 elem.attrib[feature_name] = str(value)

AttributeError: 'int' object has no attribute 'xmiID'

This is because references to the Sofa object for nested FeatureStructure is not done correct. ( in the example)

jcklie commented 4 years ago

In the XMI, it is strange that the html:TagAttribute has a sofa attribute but is not actually in the sofa members list. I would say it is even wrong.

reckart commented 4 years ago

@ArneDefauw how was the XMI file that you reference in #132 originally created?

ArneDefauw commented 4 years ago

The XMI file was created via custom java code (using UIMA SDK). Adding the 'nested' html:TagAttribute to the sofa members list indeed fixes the problem. It thus seems to be a misinterpretation from my side, thanks for the swift response!

reckart commented 4 years ago

If the a simple code example using the UIMA Java SDK without any hacks can produce an XMI file with an annotation that has a Sofa but where the annotation is not in the indexes, then IMHO cassis should be able to deal with that.

jcklie commented 4 years ago

@ArneDefauw It is fixed in master, thank you for reporting! I fixed it when loading XMI, not when adding an annotation as it should never happen when you add an annotation, only when loading XMI.

ArneDefauw commented 4 years ago

Thanks, now everything works fine!

jcklie commented 4 years ago

Solved with #134