You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Isabel Drost <is...@apache.org> on 2008/10/29 09:10:07 UTC

Unit testing CollectionReaders

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.

Thanks,
Isabel

-- 
A woman should have compassion.		-- Kirk, "Catspaw", stardate 3018.2
  |\      _,,,---,,_       Web:   <http://www.isabel-drost.de>
  /,`.-'`'    -.  ;-;;,_
 |,4-  ) )-,_..;\ (  `'-'
'---''(_/--'  `-'\_) (fL)  IM:  <xm...@spaceboyz.net>

Re: Unit testing CollectionReaders

Posted by Isabel Drost <is...@apache.org>.
On Wednesday 29 October 2008, Thilo Goetz wrote:
> And here's the relevant passage in the docs:
> http://incubator.apache.org/uima/downloads/releaseDocs/2.2.2-incubating/doc
>s/html/tutorials_and_users_guides/tutorials_and_users_guides.html#ugr.tug.ap
>plication.setting_configuration_parameters

Thanks a lot for the link. Now the test works just fine :) Seems like I was a 
little too impatient to start coding in UIMA and missed the information one 
chapter further down than I had read already :(

Isabel


-- 
I think...  I think it's in my basement... Let me go upstairs and check.		-- 
Escher
  |\      _,,,---,,_       Web:   <http://www.isabel-drost.de>
  /,`.-'`'    -.  ;-;;,_
 |,4-  ) )-,_..;\ (  `'-'
'---''(_/--'  `-'\_) (fL)  IM:  <xm...@spaceboyz.net>

Re: Unit testing CollectionReaders

Posted by Thilo Goetz <tw...@gmx.de>.
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 <is...@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
> 
> 
> 

Re: Unit testing CollectionReaders

Posted by Roberto Franchini <ro...@gmail.com>.
On Wed, Oct 29, 2008 at 9:10 AM, Isabel Drost <is...@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



-- 
Roberto Franchini
http://www.celi.it
http://www.blogmeter.it
http://www.memesphere.it
Tel +39-011-6600814
jabber:ro.franchini@gmail.com skype:ro.franchini