简体   繁体   English

创建自定义Apache UIMA CAS XML描述符时出现“CASRuntimeException”异常

[英]Exception “CASRuntimeException” while creating custom Apache UIMA CAS XML descriptor

I am trying add additional feature "version" for storing "uima.cas.Long" type value in the UIMA CAS. 我正在尝试添加附加功能“版本”,用于在UIMA CAS中存储“uima.cas.Long”类型值。

I have successfully created the XML descriptor which looks like as follows: 我已经成功创建了XML描述符,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<typeSystemDescription xmlns="http://uima.apache.org/resourceSpecifier">
    <types>
    <typeDescription>
            <name>CASVersion</name>
            <description/>
            <supertypeName>uima.cas.TOP</supertypeName>
            <features>
                <featureDescription>
                    <name>Version</name>
                    <description/>
                    <rangeTypeName>uima.cas.Long</rangeTypeName>
                </featureDescription>
            </features>
        </typeDescription>
    </types>
</typeSystemDescription>

And I generated the corresponding code using "UIMA JCasGen”. 我使用“UIMA JCasGen”生成了相应的代码。

Following classes were generated: 生成以下类:

CASVersion_Type.java
CASVersion.java

Now, I wanted to add a version to the JCas for that I wrote following code in my java class: 现在,我想在JCas中添加一个版本,因为我在java类中编写了以下代码:

    14: public void testAnnotation()    {
    15: JCas document = CasCreationUtils.createCas((TypeSystemDescription) null, null, null).getJCas();
    16: CASVersion version = new CASVersion(document);
    17: version.setVersion(1);

I am getting "CASRuntimeException" on running this code as mentioned below: 我正在运行此代码时收到“CASRuntimeException”,如下所述:

null
org.apache.uima.cas.CASRuntimeException: JCas type "com.example.test.CASVersion" used in Java code,  but was not declared in the XML type descriptor.
    at org.apache.uima.jcas.impl.JCasImpl.getTypeInit(JCasImpl.java:456)
    at org.apache.uima.jcas.impl.JCasImpl.getType(JCasImpl.java:425)
    at org.apache.uima.jcas.cas.TOP.<init>(TOP.java:96)
    at com.example.test.CASVersion.<init>(CASVersion.java:51)
    at com.example.test.Custom.testAnnotation(Custom.java:15)

Code in CASVersion.java at line 51 is as follows: CASVersion.java第51行的代码如下:

50:  public CASVersion(JCas jcas) {
51: super(jcas);
52: readObject();   
53:  } 

Since I am doing this for the first time I am not able to figure out how merge my custome xml descriptor to the existing XML type descriptor. 由于我是第一次这样做,我无法弄清楚如何将我的自定义xml描述符合并到现有的XML类型描述符。

Would be great if anyone can guide me in this. 如果有人能指导我这将是伟大的。

Thanks in Advance. 提前致谢。

This message 这条信息

JCas type "com.example.test.CASVersion" used in Java code,  
but was not declared in the XML type descriptor.

means that the JCas class for your custom type is present, but UIMA is unaware of the XML descriptor describing the custom type. 表示存在自定义类型的JCas类,但UIMA不知道描述自定义类型的XML描述符。 Assuming that you are using uimaFIT, make sure that you have set up the type system detection by creating a types.txt file pointing to your custom type's XML descriptor. 假设您正在使用uimaFIT,请确保通过创建指向自定义类型的XML描述符的types.txt文件来设置类型系统检测。 For the dirty details, please refer to the uimaFIT documentation . 有关脏的详细信息,请参阅uimaFIT文档

Disclosure: I am working on uimaFIT 披露:我正在研究uimaFIT

The new type was not idetified in JCas when I initialized JCas as follows: 当我按照以下方式初始化JCas时,JCas中没有确定新类型:

    JCas document = CasCreationUtils.createCas((TypeSystemDescription) null, null, null).getJCas();

This was fixed by replacing it by any one of the following : 通过以下任何一项替换它来解决此问题:

    //1st way
    JCas document = JCasFactory.createJCas();

    //2nd way
    TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription();
    JCas document = CasCreationUtils.createCas(tsd, null, null).getJCas();

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

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