On Tue, Aug 30, 2011 at 11:58 PM, Richard Eckart de Castilho
<[email protected]> 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:[email protected] skype:ro.franchini

Reply via email to