You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by abhishek <ab...@sqlstar.com> on 2011/09/28 11:34:16 UTC
Java code to add Element to FSList
Hi,
I have created one Feature in Types. The feature rangeType is FSList and element Type is another Annotator class(ParagraphAnnotation which extends org.apache.uima.jcas.tcas.Annotation ).
Now, I am not able to find out a way to set the value of this feature.
Example:
List<MyClass>sample= new Arraylist<MyClass>();
MyClass c = new MyClass();
sample.add(c);
Is there a way to replicate similar situation mentioned above in UIMA FSList code.
Kindly help
Re: Java code to add Element to FSList
Posted by Marshall Schor <ms...@schor.com>.
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 and element Type is another Annotator class(ParagraphAnnotation which extends org.apache.uima.jcas.tcas.Annotation ).
>>
>> Now, I am not able to find out a way to set the value of this feature.
>>
>> Example:
>>
>> List<MyClass>sample= new Arraylist<MyClass>();
>> MyClass c = new MyClass();
>> sample.add(c);
>>
>>
>>
>> Is there a way to replicate similar situation mentioned above in UIMA FSList code.
>>
>>
>> Kindly help
Re: Java code to add Element to FSList
Posted by Richard Eckart de Castilho <ec...@tk.informatik.tu-darmstadt.de>.
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 and element Type is another Annotator class(ParagraphAnnotation which extends org.apache.uima.jcas.tcas.Annotation ).
>
> Now, I am not able to find out a way to set the value of this feature.
>
> Example:
>
> List<MyClass>sample= new Arraylist<MyClass>();
> MyClass c = new MyClass();
> sample.add(c);
>
>
>
> Is there a way to replicate similar situation mentioned above in UIMA FSList code.
>
>
> Kindly help
--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab
FB 20 Computer Science Department
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckartde@tk.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------