You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Christoph Buescher <ch...@gmx.de> on 2009/01/29 15:13:16 UTC

Is it possible to get AnalysisComponent linked to an AnalysisEngine?

Hi,

I'm having a small problem in testing an UIMA annotator. My annotator XYZ 
extends JCasAnnotator_ImplBase which I understands, implements part of the 
AnalysisComponent interface.
I usually create my test annotator from an AnalysisEngintDesrition like this:

AnalysisEngine testAnnotator = produceAnalysisEngine(some 
AnalysisEngineDescription);

This is fine as long as I want to call methods like process() or initialize() 
from the AnalysisEngine interface.
Now my annotator XYZ has some additional public methods to get internal state 
information like XYZ.getFoo() which I want to call, which cant be done via the 
AnalysisEngine interface. I also can't cast the AnalysisEngine to my annotator 
XYZ because this extends AnalysisComponent and both don't seem to be directly 
connected in the class hirarchy.

So here's my question: somehow UIMA needs to internally know the connection 
between my AnalysisEngine instance and my custom implementation class XYZ to be 
able to route method calls (like process()) to it. Can I somehow get the 
"AnalysisComponent" instance underlying an AnalysisEngine to be able to cast to 
my annotators class? Otherwise I can't test any additional public methods I 
added to my annotator. Any hints appreciated.

Christoph Büscher




Re: Is it possible to get AnalysisComponent linked to an AnalysisEngine?

Posted by Thilo Goetz <tw...@gmx.de>.
Christoph Buescher wrote:
> Hi,
> 
> I'm having a small problem in testing an UIMA annotator. My annotator
> XYZ extends JCasAnnotator_ImplBase which I understands, implements part
> of the AnalysisComponent interface.
> I usually create my test annotator from an AnalysisEngintDesrition like
> this:
> 
> AnalysisEngine testAnnotator = produceAnalysisEngine(some
> AnalysisEngineDescription);
> 
> This is fine as long as I want to call methods like process() or
> initialize() from the AnalysisEngine interface.
> Now my annotator XYZ has some additional public methods to get internal
> state information like XYZ.getFoo() which I want to call, which cant be
> done via the AnalysisEngine interface. I also can't cast the
> AnalysisEngine to my annotator XYZ because this extends
> AnalysisComponent and both don't seem to be directly connected in the
> class hirarchy.
> 
> So here's my question: somehow UIMA needs to internally know the
> connection between my AnalysisEngine instance and my custom
> implementation class XYZ to be able to route method calls (like
> process()) to it. Can I somehow get the "AnalysisComponent" instance
> underlying an AnalysisEngine to be able to cast to my annotators class?
> Otherwise I can't test any additional public methods I added to my
> annotator. Any hints appreciated.
> 
> Christoph Büscher

Hi Christoph,

the short answer is "no".  UIMA does not allow you to access
the components it's running.  They could be running anywhere,
anyhow.

As a workaround, for testing only, you can add a static
accessor to your annotator, like this:

public class AccessibleAnnotator extends JCasAnnotator_ImplBase {

  private static AccessibleAnnotator instance = null;

  public static AccessibleAnnotator getInstance() {
    return instance;
  }

  public AccessibleAnnotator() {
    super();
    AccessibleAnnotator.instance = this;
  }

  @Override
  public void process(JCas cas) throws AnalysisEngineProcessException {
    // Implement...

  }

}

I do not recommend this, however.  Why do you need to test
public methods on your annotator that you can't later use
anyway?

HTH,
Thilo