uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thilo Goetz <twgo...@gmx.de>
Subject Re: Unit testing CollectionReaders
Date Wed, 29 Oct 2008 09:45:28 GMT
And here's the relevant passage in the docs:
http://incubator.apache.org/uima/downloads/releaseDocs/2.2.2-incubating/docs/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.application.setting_configuration_parameters

--Thilo

Roberto Franchini wrote:
> On Wed, Oct 29, 2008 at 9:10 AM, Isabel Drost <isabel@apache.org> wrote:
>> Hello,
>>
>> I am about to do my first steps using UIMA. I started out with the tutorial
>> and am about to write my first CollectionReader (extending
>> CollectionReader_ImplBase). As the tutorial says, I implemented initialize()
>> to init the reader from its config parameters:
>>
>>> ...
>>> File webKbDir = new File((String) getConfigParameterValue(PARAM_INPUTDIR));
>>> ...
>> In order to test the class I created a unit test. I thought it might be a good
>> idea to set the parameters of the reader in the setUp method of my test like
>> this:
>>
>>> ...
>>> public void setUp() throws Exception {
>>>   this.reader = new WebKbReader();
>>>   URL path = this.getClass().getResource("dataset");
>>>   String pathString = path.getPath();
>>>   this.reader.setConfigParameterValue(WebKbReader.PARAM_INPUTDIR, path);
>>>   this.reader.initialize();
>>> }
>> ...
>>
>> Unfortunately this gives me a null pointer exception in the line setting the
>> config parameter that comes from inside UIMA:
>>
>>> java.lang.NullPointerException
>>>       at
>> org.apache.uima.resource.ConfigurableResource_ImplBase.getConfigParameterValue(ConfigurableResource_ImplBase.java:37)
>>>       at
>> org.apache.mahout.clustering.webkb.kmeans.WebKbReader.initialize(WebKbReader.java:58)
>>
>>
>> I had a look at the UIMA code, the line throwing the exception is the
>> following:
>>
>>> public void setConfigParameterValue(String aParamName, Object aValue) {
>>>  getUimaContextAdmin().getConfigurationManager().setConfigParameterValue(
>>>      getUimaContextAdmin().getQualifiedContextName() + aParamName, aValue);
>>> }
>> I guess I am just making some stupid beginners mistake - forgot to initialize
>> some internal UIMA object before calling my reader? Unfortunately I have no
>> clue what could have gone wrong. Any help would be appreciated.
>>
> 
> 
> If you search in the list archives you will find a thread on that subject.
> Here a snippet
> //rfcr is a reader
> CasManager casManager = rfcr.getCasManager();
> 
> 			casManager.addMetaData((ProcessingResourceMetaData) rfcr.getMetaData());
> 			casManager.defineCasPool("pool", 2, null);
> 			int fileCounter = 0;
> 			while (rfcr.hasNext()) {
> 
> 				CAS cas = casManager.getCas("pool");
> 
> 				rfcr.getNext(cas);
> 
> 				fileCounter++;
> 				Progress[] progress = rfcr.getProgress();
> 				assertEquals(fileCounter, progress[0].getCompleted());
> 				cas.release();
> 			}
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 			fail(e.getMessage());
> 		}
> 
> 
> To get rfcr (reader for  you) parse the descriptor programmatically:
> 			XMLInputSource xml = new XMLInputSource("/my/path/desc.xml");
> 			ResourceSpecifier aSpecifier =
> UIMAFramework.getXMLParser().parseCollectionReaderDescription(xml );
> 			reader =UIMAFramework.produceCollectionReader(aSpecifier );
> 
> I hope this help you.
> Roberto
> 
> 
> 

Mime
View raw message