uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Eckart de Castilho <eck...@ukp.informatik.tu-darmstadt.de>
Subject Re: generics and type safety in UIMA AEs
Date Mon, 06 Aug 2012 10:59:12 GMT
Hello Florian,

with vanilla UIMA, there is no other way than casting. You might want to take a look at uimaFIT

> FSIterator<Annotation> annIt = jcas.getAnnotationIndex(myType).iterator();

List<Token> tokens = JCasUtil.select(jcas, Token.class)

> 2. The second type safety issue I have is with external resources. Lets assume I've got
an interface defining a StringMapResource<T>, i.e., much like in the UIMA tutorials,
essentially a Map<String, T> using String keys and some generic values. Usually, in
the initialize(UimaContext ctx) method, I'd write:
> StringMapResource<MyType> smr = (StringMapResource<MyType>)  ctx.getResourceObject(myResourceKey);

This is really a bit difficult to do statically type safe, but uimaFIT allows you to at least
avoid the compiler warnings. You'd just set up a class variable of the type you want and annotate
it with @ExternalResource:

private StringMapResource<MyType> smr;

Mind that for this annotation (or the similarliy useful @ConfigurationParameter annotation)
to work either your component must inherit from one of the uimaFIT base classes (e.g. org.uimafit.component.JCasAnnotator_ImplBase)
or you have to call ConfigurationParameterInitializer and ExternalResourceInitializer manually
in initialize().


-- Richard
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab (UKP-TUD) 
FB 20 Computer Science Department      
Technische Universit├Ąt Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de

View raw message