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 Büscher <ch...@neofonie.de> on 2008/02/15 15:31:16 UTC

How to "push" documents into CPE/CollectionReader?

Hi,

so far I've always used UIMA CPEs to read whole collections of documents from 
e.g. a source directory. In a new application it will be necessary to run a CPE 
on new documents beeing passed to it by another application (outside UIMA). It 
would be nice to be able to simply hand single documents over to a collection 
reader and then simply to "run/wake up" the CPE to process the document.

My idea was to put the incoming documents into a waiting queue, register this at 
a custom collection reader and then let the hasNext/getNext-Method simply to ask 
the queue if there is work to do. But when "hasNext()" in the collection reader 
returns "false", the CPE stops execution.

Is it possible to put a reader or the whole CPE into a "waiting" mode, or is the 
only solution to always restart the whole CPE once new documents have arrived to 
be processed? Has anybody dealt with a similar situation so far and has any 
"best practices" to share? How do you handle them ?

Thanks,

-- 
--------------------------------
Christoph Büscher

RE: How to "push" documents into CPE/CollectionReader?

Posted by Te...@thomson.com.
Our current tactic for PDF and Word is to use third party software to
convert it to xml first. The long term desire would be to encapsulate
that behavior into a reader. We could then call the "pdf" reader and
then the "xml" reader, in sequence. 

Terry Heinze



-----Original Message-----
From: Thilo Goetz [mailto:twgoetz@gmx.de] 
Sent: Friday, February 15, 2008 10:23 AM
To: uima-user@incubator.apache.org
Subject: Re: How to "push" documents into CPE/CollectionReader?

Terry.Heinze@thomson.com wrote:
> We've been using UIMA within a web service that processes one document
at a time. The single document is sent as a SOAP attachment. Metadata
configuring our UIMA components is included within the SOAP message. The
service module (which can also be executed as a standalone application)
gets a CAS from the pool, loads the document into the CAS, sequentially
calls the requested UIMA components, pulls the resulting document(s)
from the CAS and returns them to the service caller.
> 
> Rather than using a CPE, we wrote our own processing manager. We use a
xml configuration file, similar in format to the cpe descriptor. The
configuration file lists, in order, the readers, analysis engines, and
consumers that need to be instantiated. It also allows for overwriting
the respective descriptors. For example, any parameters and resource
file names can be changed via the configuration file. The processing
manager reads in the descriptors, modifies the contents (if requested),
saves the modified descriptors as an array of InputStreams. The
processing manager then creates the UIMA components and configures the
CAS pool.   
> 
> At this point we are not utilizing any of the sofa and type
input/output information to validate the order of execution -  this
processing manager controller is used for well-defined applications.  
> 
> The processing manager uses the metadata to control which reader(s)
and consumer(s) to execute. The web service will accept documents in
multiple formats (xml, html, text). The getNext() on the relevant reader
pulls the document from the CAS and parses it (the metadata may also
include xpath or similar instructions on how to find the plain text
portions), placing the result into the CAS. After the analysis engines
complete the annotating, one or more consumers are executed in order to
build the requested output (annotated original, annotated extract,
annotations only, xmi, etc.).  
> 
> Terry Heinze
> Thomson Corporation R&D

That sounds pretty powerful.  I know there are other people out there
who have/are working on systems that allow for dynamic configuration of
processing chains.  If more people find this useful, maybe it should be
in UIMA out of the box?

Question: are you considering to support binary formats such as PDF via,
e.g., Apache Tika?

--Thilo

Re: How to "push" documents into CPE/CollectionReader?

Posted by Thilo Goetz <tw...@gmx.de>.
Terry.Heinze@thomson.com wrote:
> We've been using UIMA within a web service that processes one document at a time. The single document is sent as a SOAP attachment. Metadata configuring our UIMA components is included within the SOAP message. The service module (which can also be executed as a standalone application) gets a CAS from the pool, loads the document into the CAS, sequentially calls the requested UIMA components, pulls the resulting document(s) from the CAS and returns them to the service caller.
> 
> Rather than using a CPE, we wrote our own processing manager. We use a xml configuration file, similar in format to the cpe descriptor. The configuration file lists, in order, the readers, analysis engines, and consumers that need to be instantiated. It also allows for overwriting the respective descriptors. For example, any parameters and resource file names can be changed via the configuration file. The processing manager reads in the descriptors, modifies the contents (if requested), saves the modified descriptors as an array of InputStreams. The processing manager then creates the UIMA components and configures the CAS pool.   
> 
> At this point we are not utilizing any of the sofa and type input/output information to validate the order of execution -  this processing manager controller is used for well-defined applications.  
> 
> The processing manager uses the metadata to control which reader(s) and consumer(s) to execute. The web service will accept documents in multiple formats (xml, html, text). The getNext() on the relevant reader pulls the document from the CAS and parses it (the metadata may also include xpath or similar instructions on how to find the plain text portions), placing the result into the CAS. After the analysis engines complete the annotating, one or more consumers are executed in order to build the requested output (annotated original, annotated extract, annotations only, xmi, etc.).  
> 
> Terry Heinze
> Thomson Corporation R&D

That sounds pretty powerful.  I know there are other people out there
who have/are working on systems that allow for dynamic configuration
of processing chains.  If more people find this useful, maybe it should
be in UIMA out of the box?

Question: are you considering to support binary formats such as PDF via,
e.g., Apache Tika?

--Thilo

RE: How to "push" documents into CPE/CollectionReader?

Posted by Te...@thomson.com.
We've been using UIMA within a web service that processes one document at a time. The single document is sent as a SOAP attachment. Metadata configuring our UIMA components is included within the SOAP message. The service module (which can also be executed as a standalone application) gets a CAS from the pool, loads the document into the CAS, sequentially calls the requested UIMA components, pulls the resulting document(s) from the CAS and returns them to the service caller.

Rather than using a CPE, we wrote our own processing manager. We use a xml configuration file, similar in format to the cpe descriptor. The configuration file lists, in order, the readers, analysis engines, and consumers that need to be instantiated. It also allows for overwriting the respective descriptors. For example, any parameters and resource file names can be changed via the configuration file. The processing manager reads in the descriptors, modifies the contents (if requested), saves the modified descriptors as an array of InputStreams. The processing manager then creates the UIMA components and configures the CAS pool.   

At this point we are not utilizing any of the sofa and type input/output information to validate the order of execution -  this processing manager controller is used for well-defined applications.  

The processing manager uses the metadata to control which reader(s) and consumer(s) to execute. The web service will accept documents in multiple formats (xml, html, text). The getNext() on the relevant reader pulls the document from the CAS and parses it (the metadata may also include xpath or similar instructions on how to find the plain text portions), placing the result into the CAS. After the analysis engines complete the annotating, one or more consumers are executed in order to build the requested output (annotated original, annotated extract, annotations only, xmi, etc.).  

Terry Heinze
Thomson Corporation R&D

-----Original Message-----
From: Christoph Büscher [mailto:christoph.buescher@neofonie.de] 
Sent: Friday, February 15, 2008 8:31 AM
To: uima-user@incubator.apache.org
Subject: How to "push" documents into CPE/CollectionReader?

Hi,

so far I've always used UIMA CPEs to read whole collections of documents from e.g. a source directory. In a new application it will be necessary to run a CPE on new documents beeing passed to it by another application (outside UIMA). It would be nice to be able to simply hand single documents over to a collection reader and then simply to "run/wake up" the CPE to process the document.

My idea was to put the incoming documents into a waiting queue, register this at a custom collection reader and then let the hasNext/getNext-Method simply to ask the queue if there is work to do. But when "hasNext()" in the collection reader returns "false", the CPE stops execution.

Is it possible to put a reader or the whole CPE into a "waiting" mode, or is the only solution to always restart the whole CPE once new documents have arrived to be processed? Has anybody dealt with a similar situation so far and has any "best practices" to share? How do you handle them ?

Thanks,

--
--------------------------------
Christoph Büscher

Re: How to "push" documents into CPE/CollectionReader?

Posted by Thilo Goetz <tw...@gmx.de>.
Roberto Franchini wrote:
> On Fri, Feb 15, 2008 at 4:01 PM, Thilo Goetz <tw...@gmx.de> wrote:
>> Not sure this is going to help, but here goes.  I find
>>  this kind of situation quite common.  So I don't use a
>>  CPE, but just run an aggregate under my own control.
>>
>>  Create a UIMA app with something like this:
> [cut]
> 
> I do this  inside a servlet. So the aggreagate could be called as a
> REST WS or by a web page with a simple form.
> Roberto
> 
> 

Roberto, have you seen the SimpleServer project in
the sandbox?  It's still under development, but you
may find it useful.  If you get a chance to try it
out, let me know what you think.

http://incubator.apache.org/uima/sandbox.html#simple-server

--Thilo


Re: How to "push" documents into CPE/CollectionReader?

Posted by Roberto Franchini <ro...@gmail.com>.
On Fri, Feb 15, 2008 at 4:01 PM, Thilo Goetz <tw...@gmx.de> wrote:
> Not sure this is going to help, but here goes.  I find
>  this kind of situation quite common.  So I don't use a
>  CPE, but just run an aggregate under my own control.
>
>  Create a UIMA app with something like this:
[cut]

I do this  inside a servlet. So the aggreagate could be called as a
REST WS or by a web page with a simple form.
Roberto


-- 
Roberto Franchini
CELI s.r.l. (http://www.celi.it) - C.so Moncalieri 21 - 10131 Torino - ITALY
Tel +39-011-6600814 - Fax +39-011-6600687
jabber:ro.franchini@gmail.com skype:ro.franchini

Re: How to "push" documents into CPE/CollectionReader?

Posted by Eddie Epstein <ea...@gmail.com>.
>
> However, I think this way I will not be able to benefit from some of the
> frameworks features like exception handling, multithreading etc..., but
> for the
> time being I think I can live without that,
>
> Christoph
>
>
Another approach will shortly be available with the uima-as extension. The
entire CPE can be implemented with all the exception handling of the CPM and
with much more flexible and extensive scalability. With uima-as, the top
level CPE is a standard UIMA aggregate, which may or may not include a CAS
multiplier component acting like a collection reader.

CPE without CM: Create an application that pushes documents (CASes) into the
aggregate using the uima-as client API, which supports both synchronous and
asynchronous interfaces. With the asynchronous interface a simple parameter
determines how many outstanding requests are allowed at the same time,
preventing overload of the aggregate's input queue. After processing the CAS
will be returned to the application, with whatever content is left in them.
This design is good if the overhead of serializing the CAS from the
application to the aggregate is much less than the work done in the
aggregate.

CPE with CM: To minimize framework overhead, the application could send a
CAS to the aggregate containing a pointer to a set of documents. The CM
component would act as a collection reader, creating the CASes with the
individual documents to be processed. Only the original CAS will be returned
to the application, which at this point could have customized status on the
results of processing.

In both cases scale up could be at the aggregate level, with multiple
instances of the aggregate processing client requests, as well as at the
delegate level, with any delegate being replicated in the same process as
the aggregate or itself scaled out across machines.

Eddie

Re: How to "push" documents into CPE/CollectionReader?

Posted by Thilo Goetz <tw...@gmx.de>.
Christoph Büscher wrote:
> Thanks Thilo,
> 
> this sound like a good thing to try. I thought that I need to start a 
> whole CPE because maybe the framework is needed to set up the initial 
> CAS that is passed on the the readers "getNext()" method, but it seems I 
> can use the AEs as "standalone" modules.

You definitely can.  You can even create more than one instance and run
them in separate threads.

> However, I think this way I will not be able to benefit from some of the 
> frameworks features like exception handling, multithreading etc..., but 
> for the time being I think I can live without that,
> 
> Christoph

If you like to use the CPE's multi-threading etc. capabilities,
you may wish to try Florian's idea.  We have done similar things
in the past, so something like that is possible.

--Thilo

Re: How to "push" documents into CPE/CollectionReader?

Posted by Christoph Büscher <ch...@neofonie.de>.
Thanks Thilo,

this sound like a good thing to try. I thought that I need to start a whole CPE 
because maybe the framework is needed to set up the initial CAS that is passed 
on the the readers "getNext()" method, but it seems I can use the AEs as 
"standalone" modules.
However, I think this way I will not be able to benefit from some of the 
frameworks features like exception handling, multithreading etc..., but for the 
time being I think I can live without that,

Christoph

Thilo Goetz schrieb:
> Not sure this is going to help, but here goes.  I find
> this kind of situation quite common.  So I don't use a
> CPE, but just run an aggregate under my own control.
> 
> Create a UIMA app with something like this:
> 
> public class UimaApp {
> 
>   public static void main(String[] args) {
>     try {
>       // Get Resource Specifier from XML file
>       XMLInputSource in = new XMLInputSource(args[0]);
>       ResourceSpecifier specifier = 
> UIMAFramework.getXMLParser().parseResourceSpecifier(in);
>       // Instantiate analysis engine
>       AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
>       // Create CAS
>       CAS cas = ae.newCAS();
> 
>       // Now process documents (in a loop, hooked up to a queue or 
> whatever is convenient...)
> 
>       // Reset CAS before processing
>       cas.reset();
>       // Set document text and do other initialization
>       cas.setDocumentText("Document text goes here");
>       // Run ae on CAS
>       ae.process(cas);
>       // If necessary, get results out of CAS...
>       System.out.println("Number of annotations: " + 
> cas.getAnnotationIndex().size());
> 
>     } catch (Exception e) {
>       e.printStackTrace();
>     }
>   }
> 
> }
> 
> So if the only thing you need the CPE for is the collection
> reader, this is an alternative for you.
> 
> --Thilo
> 


Re: How to "push" documents into CPE/CollectionReader?

Posted by Thilo Goetz <tw...@gmx.de>.
Not sure this is going to help, but here goes.  I find
this kind of situation quite common.  So I don't use a
CPE, but just run an aggregate under my own control.

Create a UIMA app with something like this:

public class UimaApp {

   public static void main(String[] args) {
     try {
       // Get Resource Specifier from XML file
       XMLInputSource in = new XMLInputSource(args[0]);
       ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
       // Instantiate analysis engine
       AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
       // Create CAS
       CAS cas = ae.newCAS();

       // Now process documents (in a loop, hooked up to a queue or whatever is convenient...)

       // Reset CAS before processing
       cas.reset();
       // Set document text and do other initialization
       cas.setDocumentText("Document text goes here");
       // Run ae on CAS
       ae.process(cas);
       // If necessary, get results out of CAS...
       System.out.println("Number of annotations: " + cas.getAnnotationIndex().size());

     } catch (Exception e) {
       e.printStackTrace();
     }
   }

}

So if the only thing you need the CPE for is the collection
reader, this is an alternative for you.

--Thilo

Christoph Büscher wrote:
> Hi,
> 
> so far I've always used UIMA CPEs to read whole collections of documents 
> from e.g. a source directory. In a new application it will be necessary 
> to run a CPE on new documents beeing passed to it by another application 
> (outside UIMA). It would be nice to be able to simply hand single 
> documents over to a collection reader and then simply to "run/wake up" 
> the CPE to process the document.
> 
> My idea was to put the incoming documents into a waiting queue, register 
> this at a custom collection reader and then let the 
> hasNext/getNext-Method simply to ask the queue if there is work to do. 
> But when "hasNext()" in the collection reader returns "false", the CPE 
> stops execution.
> 
> Is it possible to put a reader or the whole CPE into a "waiting" mode, 
> or is the only solution to always restart the whole CPE once new 
> documents have arrived to be processed? Has anybody dealt with a similar 
> situation so far and has any "best practices" to share? How do you 
> handle them ?
> 
> Thanks,
> 


Re: How to "push" documents into CPE/CollectionReader?

Posted by Thilo Goetz <tw...@gmx.de>.
Florian Laws wrote:
> Christoph Büscher schrieb:
>> Hi,
>>
>> so far I've always used UIMA CPEs to read whole collections of 
>> documents from e.g. a source directory. In a new application it will 
>> be necessary to run a CPE on new documents beeing passed to it by 
>> another application (outside UIMA). It would be nice to be able to 
>> simply hand single documents over to a collection reader and then 
>> simply to "run/wake up" the CPE to process the document.
>>
>> My idea was to put the incoming documents into a waiting queue, 
>> register this at a custom collection reader and then let the 
>> hasNext/getNext-Method simply to ask the queue if there is work to do. 
>> But when "hasNext()" in the collection reader returns "false", the CPE 
>> stops execution.
> 
> What about the naive solution:
> Wait in the hasNext() method until a new document is available.
> 
> Regards,
> 
> Florian

I think that's possible.  You may need to be
careful how to configure the CPE so you don't get
time outs?  Not sure.

--Thilo


Re: How to "push" documents into CPE/CollectionReader?

Posted by Florian Laws <fl...@ims.uni-stuttgart.de>.
Christoph Büscher schrieb:
> Hi,
>
> so far I've always used UIMA CPEs to read whole collections of 
> documents from e.g. a source directory. In a new application it will 
> be necessary to run a CPE on new documents beeing passed to it by 
> another application (outside UIMA). It would be nice to be able to 
> simply hand single documents over to a collection reader and then 
> simply to "run/wake up" the CPE to process the document.
>
> My idea was to put the incoming documents into a waiting queue, 
> register this at a custom collection reader and then let the 
> hasNext/getNext-Method simply to ask the queue if there is work to do. 
> But when "hasNext()" in the collection reader returns "false", the CPE 
> stops execution.

What about the naive solution:
Wait in the hasNext() method until a new document is available.

Regards,

Florian