Hi Roberto,

when calling the no-args constructor of TOP, the instance is unusable. The JCas 
wrapper needs to know the CAS type and the CAS address to access the actual 
data it exposes via its getters and setters. Mind, that the JCas classes are no 
Java Beans - they are just convenience classes to access data hidden deep 
within the heaps of the low-level CAS.

I suppose in your scenario, you never actually intend to use that instance 
created via the no-args constructor. It's just a dummy instance internally used 
by lambdaj to intercept the method calls to the real Tokens (those from the 
"tokens" iterable). Is this correct?

What you're doing there with lambdaj looks fascinating! We wanted to implement 
an API in uimaFIT which supports a similar style, but it couldn't ever have 
been that nice.

Cheers,

-- Richard

Am 30.08.2011 um 22:46 schrieb Roberto Franchini:

> hello.
> I'm using uimafit and lamdaj to update annotations:
> 
>               Iterable<Token> tokens = JCasUtil.select(jCas, Token.class);
> 
>               forEach(select(tokens, having(on(Token.class).getNormalForm(),
> startsWith("#")))).setKind("HashTag");
> 
> 
> This code trhows a runtine excpetion, because TOP has this deafult 
> constructor:
> 
>       // This constructor is never called .
>       // Have to set "final" values to avoid compile errors
>       protected TOP() {
>               jcasType = null;
>               addr = 0;
>               throw new RuntimeException("Internal Error: TOP() constructor 
> should
> never be called.");
>       }
> 
> 
> Lambdaj creates a dinamic proxy via reflection, so it calls TOP()  to
> build the proxy for Token:
> 
> on(Token.class).
> 
> 
> I can do the same thing in different ways, using plain java for each
> or google collection/guava.
> But lambdaj is very cool :)
> 
> Is it possible to avoid to throw the runtime exception?
> Cheers,
> RF
> -- 
> Roberto Franchini
> L'impossibile è inevitabile.
> http://www.celi.it
> http://www.blogmeter.it
> Tel +39.011.562.71.15
> jabber:[email protected] skype:ro.franchini

Richard Eckart de Castilho

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab 
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
[email protected] 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
------------------------------------------------------------------- 




Reply via email to