You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Roberto Franchini <fr...@celi.it> on 2011/08/30 22:46:35 UTC

TOP default constructor trhows RE

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:ro.franchini@gmail.com skype:ro.franchini

Re: TOP default constructor trhows RE

Posted by Roberto Franchini <fr...@celi.it>.
On Tue, Aug 30, 2011 at 11:58 PM, Richard Eckart de Castilho
<ec...@tk.informatik.tu-darmstadt.de> wrote:
> 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?

Yes, that's right.

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


Well, we tend to use lambaj  not so much, due to poor performance.
Lambdaj uses a lot of reflection..
This code is used inside a test to prepare a fake jCas
The same things could be done usign google-collection:

		Iterable<Token> transform = transform(filter(select(jCas,
Token.class), new Predicate<Token>() {

			@Override
			public boolean apply(Token token) {
				return token.getNormalForm().startsWith("#");
			}
		}), new Function<Token, Token>() {

			@Override
			public Token apply(Token token) {
				token.setKind("HashTag");
				token.setNormalForm(stripStart(token.getNormalForm(), "#"));
				return token;
			}

		});

		for (Token token : transform) {
			// NOOP
		}

Note the last for: filter and trasform are lazy! You need to "consume"
the iterable to activate predicates and functions.
I want to try to write the same this using Scala.
Cheers
RF

PS: uimafit: well done guys!
-- 
Roberto Franchini
L'impossibile è inevitabile.
http://www.celi.it
http://www.blogmeter.it
Tel +39.011.562.71.15
jabber:ro.franchini@gmail.com skype:ro.franchini

Re: TOP default constructor trhows RE

Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
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:ro.franchini@gmail.com 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
eckartde@tk.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------