Return-Path: X-Original-To: apmail-uima-user-archive@www.apache.org Delivered-To: apmail-uima-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7AFD8C287 for ; Fri, 8 Jun 2012 07:44:02 +0000 (UTC) Received: (qmail 72017 invoked by uid 500); 8 Jun 2012 07:44:02 -0000 Delivered-To: apmail-uima-user-archive@uima.apache.org Received: (qmail 71871 invoked by uid 500); 8 Jun 2012 07:44:02 -0000 Mailing-List: contact user-help@uima.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@uima.apache.org Delivered-To: mailing list user@uima.apache.org Received: (qmail 71848 invoked by uid 99); 8 Jun 2012 07:44:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 07:44:01 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=FSL_RCVD_USER,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [130.83.156.225] (HELO lnx500.hrz.tu-darmstadt.de) (130.83.156.225) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Jun 2012 07:43:53 +0000 Received: from mx.ukp.informatik.tu-darmstadt.de (fansworth.ukp.informatik.tu-darmstadt.de [130.83.167.132]) by lnx500.hrz.tu-darmstadt.de (8.14.4/8.14.4/HRZ/PMX) with ESMTP id q587hN0D022133 for ; Fri, 8 Jun 2012 09:43:23 +0200 (envelope-from eckart@ukp.informatik.tu-darmstadt.de) Received: from amy.ukp.informatik.tu-darmstadt.de ([169.254.1.38]) by fansworth.ukp.informatik.tu-darmstadt.de ([169.254.2.172]) with mapi id 14.02.0298.004; Fri, 8 Jun 2012 09:43:22 +0200 From: Richard Eckart de Castilho To: "" Subject: Re: Calling an annotator from another annotator Thread-Topic: Calling an annotator from another annotator Thread-Index: Ac1FQ+Kd9TEGkoP8TIqqTVe0UEgbLf//63UA Date: Fri, 8 Jun 2012 07:43:22 +0000 Message-ID: References: In-Reply-To: Accept-Language: de-DE, en-US Content-Language: de-DE X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [130.83.167.135] Content-Type: text/plain; charset="iso-8859-1" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-PMX-TU: seen v1.2 by 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.6.8.73620 X-PMX-RELAY: outgoing Am 08.06.2012 um 08:56 schrieb : > Hi, >=20 > I like to call an annotator from another annotator as it uses annotatatio= ns for which annotators already exist. Calling is not a problem, but settin= g the parameter is. Can this be done at all? How? Using uimaFIT the paramet= er values are injected using the AnalysisEngineFactory.createPrimitive(). D= oing so the parameters are set in the UIMA context of the outer annotator. = The inner annotator has its own UIMA context, does it? How can the outer an= notator's context be accessed while creating the inner annotator? At first = I thought that this could be done the same way as Philip Ogren has done wit= h XWriterFileNamer and XWriter. You just set the parameters for your XWrite= rFileNamer implmentation in the XWriter context. But this seems to be a lit= tle different as I don't instantiate a CasAnnototar_ImplBase object but cre= ate an annotator description which is than use to instantiate an AnalysisEn= gine object by AnalysisEngineFactory in uimaFit or UIMAFramework in UIMA it= self. Do you have any suggestions? Or is it just me, not getting to underst= and the UIMA way again? If I understand you correctly, you want to create an OuterAE to which you p= ass parameters. The OuterAE should use some of these parameters itself and = forward the rest to an InnerAE that it creates. To accomplish that, you wou= ld like the InnerAE to access the same UIMAContext object as the OuterAE. I think it's not possible or wise to have two AEs access the same UIMAConte= xt object. But it is possible to forward parameters - NOT recommened for va= rious reasons (read on). I tried to hack something together here that shoul= d work (untested): public static class OuterAnnotator extends CasAnnotator_ImplBase { @Override public void initialize(UimaContext context) throws ResourceInitialization= Exception { super.initialize(context); =09 // Copy all parameters into an array which can be passed as the variadic= parameter list // to createPrimitiveDesription List parameters =3D new ArrayList(); for (String name : context.getConfigParameterNames()) { parameters.add(name); parameters.add(context.getConfigParameterValue(name)); } =09 // Create a new AE which has access to all the parameters set on the out= er AE AnalysisEngineDescription aed =3D createPrimitiveDescription(InnerAnnota= tor.class,=20 parameters.toArray(new Object[parameters.size()])); } =09 @Override public void process(CAS aCAS) throws AnalysisEngineProcessException { //... } } I would like to point out though, that you are going to run into problems w= ith this approach, because in general there is no way to properly separate = parameters that go to the inner and to the outer AE. Well, you could introd= uce a prefix and only parameters having that prefix are passed to the inner= AE, but what if your InnerAE has another InnerInnerAE...?=20 The ConceptMapperAnnotator in the UIMA sandbox accepts the path of an Analy= sisEngineDescriptor for a tokenizer as a parameter and then instantiates th= is, but it doesn't set any additional parameters. So when one sets up the p= ipeline, one can create a AnalysisEngineDescription for the tokenizer, seri= alize it as XML to a temporary file using the toXml() method and then pass = that file to the ConceptMapperAnnotator. In that way, the ConceptMapperAnno= tator does not have to know anything about how to pass on parameters to the= tokenizer and avoids any potential parameter name clashes. At the moment, uimaFIT doesn't have explicit support for injecting Analysis= EngineDescriptors directly as parameters. One could imagine something like = this: createPrimitiveDescriptor(OuterAE.class, OuterAE.PARAM_NAME, "outer", OuterAE.PARAM_INNER_AE, createPrimitiveDescriptor(InnerAE.class,=20 PARAM_NAME, "inner"); We do something like that already for external resources. I think it would = make sense to add it for analysis engines as well. In that example above, y= ou can also see the that there could easily be a parameter name clash between = the parameters of the inner and outer AE. Philip liked to work around that = by prepending the full class name to each parameter name, but that approach= fails if OuterAE and InnerAE are actually two components of the same class= with different configurations, e.g. some generic filtering AE. As long as uimaFIT doesn't support engine injection, I'd suggest you work w= ith a temporary descriptor file that you generate with uimaFIT and pass to = your OuterAE.=20 - use AnalysisEngineFactory.createPrimitiveDescription(...) to create the d= escriptor for your inner AE - call AnalysisEngineDescription.resolveImports(UIMAFramework.newDefaultRes= ourceManager()) once on the descriptor to resolve it - persist the generated descriptor to a temporary file using AnalysisEngine= Description.toXML() - pass the path to that file as InnerAEDescriptorPath to OuterAE File.createTempFile() and File.deleteOnExit() are very helpful here. -- Richard --=20 -------------------------------------------------------------------=20 Richard Eckart de Castilho Technical Lead Ubiquitous Knowledge Processing Lab (UKP-TUD)=20 FB 20 Computer Science Department =20 Technische Universit=E4t Darmstadt=20 Hochschulstr. 10, D-64289 Darmstadt, Germany=20 phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117 eckart@ukp.informatik.tu-darmstadt.de=20 www.ukp.tu-darmstadt.de=20 Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de -------------------------------------------------------------------=20