uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject Re: Java code to add Element to FSList
Date Wed, 28 Sep 2011 14:52:02 GMT
Suggestions welcome for a better / more convenient APIs for lists :-).

In general, the advice for lists in the CAS is to recognize that they're not
necessarily "efficient" compared to Arrays, unless, of course you are
dynamically inserting / removing things. 

And, as always, only put things into the CAS which you are wanting to share with
other components.  Within one component, you can use native data structures
(e.g., Java lists) as opposed to CAS data.

-Marshall

On 9/28/2011 6:34 AM, Richard Eckart de Castilho wrote:
> Hello,
>
> the UIMA lists are linked lists and - to my knowledge - offer no convenient API. As an
illustration of how to use them, consider the following method which takes a Collection of
strings and turns it into an UIMA StringList. This method is part of the uimaFIT FSCollectionFactory
class.
>
> http://code.google.com/p/uimafit/source/browse/trunk/uimaFIT/src/main/java/org/uimafit/util/FSCollectionFactory.java

>
> 	public static StringList createStringList(JCas aJCas, Collection<String> aCollection)
> 	{
> 		if (aCollection.size() == 0) {
> 			return new EmptyStringList(aJCas);
> 		}
>
> 		NonEmptyStringList head = new NonEmptyStringList(aJCas);
> 		NonEmptyStringList list = head;
> 		Iterator<String> i = aCollection.iterator();
> 		while (i.hasNext()) {
> 			head.setHead(i.next());
> 			if (i.hasNext()) {
> 				head.setTail(new NonEmptyStringList(aJCas));
> 				head = (NonEmptyStringList) head.getTail();
> 			}
> 			else {
> 				head.setTail(new EmptyStringList(aJCas));
> 			}
> 		}
>
> 		return list;
> 	}
>
> Cheers,
>
> -- Richard
>
> Am 28.09.2011 um 11:34 schrieb abhishek:
>
>> Hi,
>> I have created one Feature in Types. The feature rangeType is FSList&nbsp;and
&nbsp;element Type is another Annotator class(ParagraphAnnotation which extends org.apache.uima.jcas.tcas.Annotation&nbsp;).
>> &nbsp;
>> Now, I am not able to find out a way to set the value of this feature.
>> &nbsp;
>> Example:
>> &nbsp;
>> List&lt;MyClass&gt;sample= new Arraylist&lt;MyClass&gt;();
>> MyClass c = new MyClass();
>> sample.add(c);
>> &nbsp;
>> &nbsp;
>> &nbsp;
>> Is there a way to replicate similar situation mentioned above in UIMA FSList code.
>> &nbsp;
>> &nbsp;
>> Kindly help

Mime
View raw message