uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Eckart de Castilho <eck...@ukp.informatik.tu-darmstadt.de>
Subject Re: Dependency injection support in UIMA
Date Tue, 20 Nov 2012 15:07:03 GMT
Hello Florin,

first of all, UIMA does not support injections of pre-existing instances. You are not supposed
to access any object instances that are not created within the context of UIMA. If you can
live with the consequences of doing this (i.e. no UIMA supported scale-out), you can have
a look at the following possibilities that I have implemented as proof-of-concept in uimaFIT:

== SimpleNamedResourceManager ==

The uimaFIT SimpleNamedResourceManager takes a key-value map of names and instances. When
you create your analysis instance with this resource manager, you can fetch the instances
via the UIMA external resource mechanism. Example:

 // Create a custom resource manager that allows to inject any Java object as an external
 // dependency
 final Map<String, Object> externalContext = new HashMap<String, Object>();
 externalContext.put("pojoName2", new AtomicInteger(5));

 // Create resource manager
 SimpleNamedResourceManager resMgr = new SimpleNamedResourceManager();

 // Instantiate component
 AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);

More test code is here:


== SpringContextResourceManager ==

The uimaFIT SpringContextResourceManager makes all Spring beans from a given Spring application
context available via the UIMA external resource mechanism. Example:

 // Acquire application context
 ApplicationContext ctx = getApplicationContext();

 // Create resource manager
 SpringContextResourceManager resMgr = new SpringContextResourceManager();

 // Instantiate component
 AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc, resMgr, null);

See also: 


== UIMA Factory Patching ==

This is an invasive mechanism that patches the UIMA framework at runtime so that every UIMA
component that is created is post-processed by a Spring application context. This means, UIMA
components can directly use any annotations supported by Spring (e.g. @PersistenceContext,
…). Only one application context is supported per JVM because the UIMA framework is (unfortunately)
internally statically configured. This should work, but I didn't really test it yet beyond
the proof-of-concept unit test.

Example code: 



-- Richard

Am 20.11.2012 um 14:22 schrieb Spico Florin <spicoflorin@gmail.com>:

> Hello!
>   I have a connection to data source (triplestore) that is used by
> multiple annotators. With the current implementation of UIMA I have to
> provide this connection in for all these annotators descriptors, making the
> deployment very tedious when switching from one environment to another (for
> example test env to production env).
> I have read the  posts from
> http://comments.gmane.org/gmane.comp.apache.uima.general/3340 but still is
> not clear for me how to handle the DI. Basically I would like to inject
> this connection to all of annotators that need it from a single
> configuration file, thus eliminating the mentioned inconvenience.
>  Can you please provide what is the best approach for handling this kind
> of problems?
> I look forward for your answers.
> Regards,
>  Florin
> P.S. I was thinking to use Spring and ApplicationContext and its
> configuration file. Is this a suitable solution?

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

View raw message