简体   繁体   English

UIMA注释功能是否有通用类型?

[英]Is there a generic type for UIMA annotation features?

Is there a generic type, similar to Object in Java, that would allow values of different types to be set to it? 是否存在类似于Java中的Object的泛型类型,可以将不同类型的值设置为它?

<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> : 我尝试将以下内容放入<rangeTypeName>

  • java.lang.Object and Object This doesn't work and I get the following message when trying to generate the code using JCasGen: java.lang.ObjectObject这不起作用,尝试使用JCasGen生成代码时收到以下消息:

    JCasGen Warning: ** Resource Initialization Error occurred while instantiating the CAS type system. JCasGen警告: **实例化CAS类型系统时发生资源初始​​化错误。 Continuing, but may generate incorrectly. 继续,但是可能生成不正确。 Caused by 'Undefined type "Object", referenced in feature "exampleFeature" declared on type "com.example.Annotation". 由“未定义类型”对象”引起,在类型“ com.example.Annotation”上声明的功能“ exampleFeature”中引用。

  • 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. uima.cas.TOP这会生成代码,但是当我尝试通过将intString传递给setExampleField()方法来调用它时会给出错误,因为它无法将它们转换为TOP类型。

The uima.cas.TOP is the Object -equivalent type of UIMA. uima.cas.TOP是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!). UIMA有两个概念:1) FeatureStructure ,2) 基本类型 (int,boolean等和String!)。 If you set the range of a feature to TOP, it can accept any kind of feature structure (ie anything that inherits from TOP), but not any of the primitive types - no auto-boxing here. 如果将要素的范围设置为TOP,则它可以接受任何种类的要素结构(即,任何继承自TOP的要素),但不接受任何原始类型-此处不进行自动装箱。 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 , eg FSInt, FSString, FSBoolean which inherit from TOP and which would have a "value" feature of the respective type (int, String, boolean). 解决方法是定义自定义类型,例如FSInt,FSString,FSBoolean,它们继承自TOP并且具有相应类型(int,String,boolean)的“值”功能。 You could then set the value in that FS and assign it to a feature with range TOP. 然后,您可以在该FS中设置值,并将其分配给具有TOP范围的功能。

Note: I am currently a committer on the Apache UIMA project. 注意:我目前是Apache UIMA项目的提交者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM