JCas type ...Timex3... used in Java code, but was not declared in the XML type descriptor heideltime

188 views Asked by At

I configured heidelTime using gradle. I am getting values however cannot iterate over the string result.

result = heidelTime.process(sentence, new Date());
JCas cas = JCasFactory.createJCas();
FSIterator it = cas.getAnnotationIndex(Timex3.type).iterator(); // Here I am getting error

Error is due to JCasImpl.class->TOP_Type getType(int i)

if (this.casImpl.getTypeSystem().getType(typeName) == null) {
            // no - report error that JCAS type was not defined in XML
            // descriptor
            CASRuntimeException casEx = new CASRuntimeException(
                CASRuntimeException.JCAS_TYPE_NOT_IN_CAS, new String[] { typeName });
            throw casEx;
          }

I checked on github project and I see HeidelTime_TypeSystem.xml files there defining type System.

Gradle Configuration

compile group: 'com.github.heideltime', name: 'heideltime', version: '2.2.1'
compile group: 'org.apache.uima', name: 'uimaj-core', version: '2.3.1'

Stack Trace

org.apache.uima.cas.CASRuntimeException: JCas type de.unihd.dbs.uima.types.heideltime.Timex3" used in Java code,  but was not declared in the XML type descriptor.
            at org.apache.uima.jcas.impl.JCasImpl.getType(JCasImpl.java:412) ~[uimaj-core-2.3.1.jar:2.3.1]
            at org.apache.uima.jcas.impl.JCasImpl.getCasType(JCasImpl.java:436) ~[uimaj-core-2.3.1.jar:2.3.1]
            at org.apache.uima.jcas.impl.JCasImpl.getAnnotationIndex(JCasImpl.java:1531) ~[uimaj-core-2.3.1.jar:2.3.1]

Do I need to add any files manually to make it work?

types.txt file location

enter image description here

1

There are 1 answers

5
rec On BEST ANSWER

This happens when a JCas class for an UIMA type is being used without the CAS being configured for this type.

The call to

JCas cas = JCasFactory.createJCas();

scans the classpath for files called types.txt under META-INF/org.apache.uima.fit/ (so a folder called META-INF with a subfolder called org.apache.uima.fit which then contains the types.txt file) and loads all the UIMA type descriptors referenced inside them. An example types.txt file looks like this:

classpath*:org/apache/uima/fit/type/Token.xml

This tells uimaFIT to load the type descriptor file Token.xml located in the package org.apache.uima.fit.type (replace with your own package and file names).

Note that if you use Maven, these all these files and folders must usually be under src/main/resources (not under src/main/java). Depending on how you set up your Gradle, this might apply to you as well.

uimaFIT's type auto-detection is also described in more detail in the uimaFIT documentation.

So for your particular case: try putting desc/type/HeidelTime_TypeSystem.xml into src/main/resources/desc/type/HeidelTime_TypeSystem.xml and create the src/main/resources/META-INF/org.apache.uima.fit/types.txt file with the content classpath*:desc/type/HeidelTime_TypeSystem.xml.

Note: At the time of writing, I am the maintainer of Apache uimaFIT.