On 5/10/07, Katherine Enderling <[EMAIL PROTECTED]> wrote:
In order to do unit testing on my Analysis Engines, I would like to create a
basic JCas object from scratch and set its document text. What is the
correct way to do this?
Thanks for your help!

I'm learning UIMA in a TDL way (Test Driven Learning :) ), and this is
a snippet of a test method:
...

                File file = getFile("it/celi/ae/emailAeDescriptor.xml"); //get a
file from classpath

                XMLInputSource in = new XMLInputSource(file);
                ResourceSpecifier specifier;
                specifier = 
UIMAFramework.getXMLParser().parseResourceSpecifier(in);
                AnalysisEngine analysisEngine =
UIMAFramework.produceAnalysisEngine(specifier);
                
                JCas aCas = analysisEngine.newJCas();
                
                String document= "This is a test document with, this is an 
email:
[EMAIL PROTECTED]";
                
                aCas.setDocumentText(document);
                analysisEngine.process(aCas);
                
                // get annotation iterator for this CAS (Email is my type
                FSIndex anIndex = aCas.getAnnotationIndex(Email.type);
                FSIterator anIter = anIndex.iterator();
                assertTrue(anIter.hasNext());
                int i = 0;
                while (anIter.isValid()) {
                        AnnotationFS annot = (AnnotationFS) anIter.get();
                        assertEquals("it.celi.type.Email", 
annot.getType().getName());
                        
                        assertEquals(mail[i], annot.getCoveredText());
                        
                        anIter.moveToNext();
                        i++;
                }
......
Take a look to the uima surces and test sources too to learn how to
test uima artifact in isolation.
I hope this could help,
Roberto


--
Roberto "FRANK" 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:[EMAIL PROTECTED] skype:ro.franchini

Reply via email to