Question

Is there a generic type, similar to Object in Java, that would allow values of different types to be set to it?

<typeDescription>
    <name>com.example.Annotation</name>
    <description></description>
    <supertypeName>uima.tcas.Annotation</supertypeName>
    <features>
        <featureDescription>
            <name>exampleFeature</name>
            <description>An example feature</description>
            <rangeTypeName>uima.cas.Generic</rangeTypeName>
        </featureDescription>
    </features>
</typeDescription>

I have tried putting the following in <rangeTypeName>:

  • java.lang.Object and Object This doesn't work and I get the following message when trying to generate the code using JCasGen:

    JCasGen Warning: ** Resource Initialization Error occurred while instantiating the CAS type system. Continuing, but may generate incorrectly. Caused by 'Undefined type "Object", referenced in feature "exampleFeature" declared on type "com.example.Annotation".

  • uima.cas.TOP This generates the code but then gives an error when I try to call the setExampleField() method by passing it an int or String as it cannot convert them to the TOP type.

Was it helpful?

Solution

The uima.cas.TOP is the Object-equivalent type of UIMA. But it is slightly different from what you would expect. UIMA operates with two concepts: 1) FeatureStructure, 2) primitive types (int, boolean, etc. and String!). If you set the range of a feature to TOP, it can accept any kind of feature structure (i.e. anything that inherits from TOP), but not any of the primitive types - no auto-boxing here. If you set the range to a primitive type, then it will only accept that type.

A work-around could be to define custom types , e.g. FSInt, FSString, FSBoolean which inherit from TOP and which would have a "value" feature of the respective type (int, String, boolean). You could then set the value in that FS and assign it to a feature with range TOP.

Note: I am currently a committer on the Apache UIMA project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top