简体   繁体   中英

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.

I have successfully created the XML descriptor which looks like as follows:

<?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”.

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:

    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:

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:

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.

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. 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. For the dirty details, please refer to the uimaFIT documentation .

Disclosure: I am working on uimaFIT

The new type was not idetified in JCas when I initialized JCas as follows:

    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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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