You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by swirl <lr...@gmail.com> on 2014/02/06 07:10:33 UTC

Sharing the same ExternalResource instance between a CollectionReader and Annotators

I am creating a pipeline as follows:
a. CollectionReader
b. AnnotatorA
c. AnnotatorB

All the above (including the CollectionReader and the 2 annotators) have a 
dependency on an ExternalResource.

Here's a shortened code that I used:
// create the external resource desc 
ExternalResourceDescription myExternalResourceDesc = 
createExternalResourceDescription();

// create the CollectionReaderDescription, with the external resource desc
CollectionReaderDescription myCollectionReaderDesc = 
createDescription(myExternalResourceDesc);

// create the MyAnnotatorA desc, with the external resource desc 
AnalysisEngineDescription myAnnotatorADesc = 
createPrimitiveDescription(myExternalResourceDesc);


// create the MyAnnotatorB desc, with the external resource desc 
AnalysisEngineDescription myAnnotatorBDesc = 
createPrimitiveDescription(myExternalResourceDesc);

// run 
SimplePipeline.runPipeline(myCollectionReaderDesc, myAnnotatorADesc,				
myAnnotatorBDesc);


In the initialize(UimaContext context) method of collection reader and 
annotator, I print out the instance of the ExternalResource:
MyCollectionReader:com.example.MyExternalResource@26a7dd39
MyAnnotatorA:com.example.MyExternalResource@6ee1dac2
MyAnnotatorB:com.example.MyExternalResource@6ee1dac2


As you can see, MyAnnotatorA and MyAnnotatorB got the same instance of the 
ExternalResource, but MyCollectionReader got a different instance.

How can I ensure that the CollectionReader and the annotators got hold of 
the same instance of the ExternalResource?

Thanks.


Re: Sharing the same ExternalResource instance between a CollectionReader and Annotators

Posted by swirl <lr...@gmail.com>.
swirl <lr...@...> writes:

> 
> Richard Eckart de Castilho <rec <at> ...> writes:
> 
> > 
> > Thanks for the report. This hasn't been noticed so far.
> > 
> > I am afraid that SimplePipeline currently does not support sharing
> > a resource between the reader and the components.

> > Sounds like something that should be fixable for the next uimaFIT 
release. 
> Would you mind opening a bug for
> > that on the Apache Jira?
 

Raised a Jira bug: https://issues.apache.org/jira/browse/UIMA-3597





Re: Sharing the same ExternalResource instance between a CollectionReader and Annotators

Posted by swirl <lr...@gmail.com>.
Richard Eckart de Castilho <re...@...> writes:

> 
> Thanks for the report. This hasn't been noticed so far.
> 
> I am afraid that SimplePipeline currently does not support sharing
> a resource between the reader and the components.
> 
> Internally, SimplePipeline instantiates the reader and the components
> separately, thus they end up with different resource managers.
> Resources can only be shared by components that use the same resource
> manager.
> 
> As a workaround, you could try the following:
> 
> - Create the reader and component descriptions as usual with uimaFIT.
> - Use UIMAFramework.newDefaultResourceManager() to create a resource 
manager.
> - Use UIMAFramework.produceCollectionReader() and 
UIMAFramework.produceAnalysisEngine()
> to create CollectionReader and AnalysisEngine instances from the 
descriptors and with your resource manager.
> - Pass the CollectionReader and AnalysisEngine instances as parameters to 
SimplePipeline.
> - Mind that you'll have to call the "collectionProcessComplete" and 
"destroy" methods manually on the
> instances after SimplePipeline is complete - if you need these events.
> 
> I think that should work, but I currently have no time to try it out.
> 
> Sounds like something that should be fixable for the next uimaFIT release. 
Would you mind opening a bug for
> that on the Apache Jira?
> 
> Cheers,
> 


Indeed, I followed your steps and now they are all using the same instance:
MyCollectionReader:com.example.MyExternalResource@32dcb03b
MyAnnotatorA:com.example.MyExternalResource@32dcb03b
MyAnnotatorB:com.example.MyExternalResource@32dcb03b



Re: Sharing the same ExternalResource instance between a CollectionReader and Annotators

Posted by Richard Eckart de Castilho <re...@apache.org>.
Thanks for the report. This hasn't been noticed so far.

I am afraid that SimplePipeline currently does not support sharing
a resource between the reader and the components.

Internally, SimplePipeline instantiates the reader and the components
separately, thus they end up with different resource managers.
Resources can only be shared by components that use the same resource
manager.

As a workaround, you could try the following:

- Create the reader and component descriptions as usual with uimaFIT.
- Use UIMAFramework.newDefaultResourceManager() to create a resource manager.
- Use UIMAFramework.produceCollectionReader() and UIMAFramework.produceAnalysisEngine()
to create CollectionReader and AnalysisEngine instances from the descriptors and with your resource manager.
- Pass the CollectionReader and AnalysisEngine instances as parameters to SimplePipeline.
- Mind that you'll have to call the "collectionProcessComplete" and "destroy" methods manually on the instances after SimplePipeline is complete - if you need these events.

I think that should work, but I currently have no time to try it out.

Sounds like something that should be fixable for the next uimaFIT release. Would you mind opening a bug for that on the Apache Jira?

Cheers,

-- Richard

On 06.02.2014, at 07:10, swirl <lr...@gmail.com> wrote:

> I am creating a pipeline as follows:
> a. CollectionReader
> b. AnnotatorA
> c. AnnotatorB
> 
> All the above (including the CollectionReader and the 2 annotators) have a 
> dependency on an ExternalResource.
> 
> Here's a shortened code that I used:
> // create the external resource desc 
> ExternalResourceDescription myExternalResourceDesc = 
> createExternalResourceDescription();
> 
> // create the CollectionReaderDescription, with the external resource desc
> CollectionReaderDescription myCollectionReaderDesc = 
> createDescription(myExternalResourceDesc);
> 
> // create the MyAnnotatorA desc, with the external resource desc 
> AnalysisEngineDescription myAnnotatorADesc = 
> createPrimitiveDescription(myExternalResourceDesc);
> 
> 
> // create the MyAnnotatorB desc, with the external resource desc 
> AnalysisEngineDescription myAnnotatorBDesc = 
> createPrimitiveDescription(myExternalResourceDesc);
> 
> // run 
> SimplePipeline.runPipeline(myCollectionReaderDesc, myAnnotatorADesc,				
> myAnnotatorBDesc);
> 
> 
> In the initialize(UimaContext context) method of collection reader and 
> annotator, I print out the instance of the ExternalResource:
> MyCollectionReader:com.example.MyExternalResource@26a7dd39
> MyAnnotatorA:com.example.MyExternalResource@6ee1dac2
> MyAnnotatorB:com.example.MyExternalResource@6ee1dac2
> 
> 
> As you can see, MyAnnotatorA and MyAnnotatorB got the same instance of the 
> ExternalResource, but MyCollectionReader got a different instance.
> 
> How can I ensure that the CollectionReader and the annotators got hold of 
> the same instance of the ExternalResource?
> 
> Thanks.
>