You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Adam Lally <al...@alum.rpi.edu> on 2007/09/21 18:51:39 UTC

Re: Using and iterating with FSList FSArray

Hi Thomas,

For some reason, the email address that you send from doesn't seem to
be subscribed to the list?  I have to manually allow them through.

On 9/21/07, Thomas Francart <th...@mondeca.com> wrote:
>
>
>  Hi again UIMA gurus
>
>  Working with FSList and FSArray in UIMA type systems looks like a lot of
> fun... :
>
>  1. I just can't figure out a way to iterate over a FSList, or
> NonEmptyFSList... how can I iterate over a feature that is defined as an
> FSList ? I can't find anything describing this in the documentation
> anywhere.
>

Basically FSList is like a classic linked list implementation (or LISP
cons cell if you prefer) where each nonterminal node (NonEmptyFSList)
has a pointer to data (the "head') and a pointer to the rest of the
list (the "tail").  For the very last node, the tail points to an
instance of EmptyFSList.

So to iterate you do something like this:
FSList list = ... //get list from somewhere
while (list instanceof NonEmptyFSList) {
  FeatureStructure head = ((NonEmptyFSList)list).getHead();
  //do something with this element
  list = ((NonEmptyFSList)list).getTail();
}

Recently there was a question raised about why we need the distinction
between NonEmptyFSList and EmptyFSList.  Instead we could just have a
single FSList class with head and tail features, and have the tail of
the last node just doesn't point to null.  That would eliminate the
need for the typecasts in the loop above.  You'll have to ask Thilo
why that is the way it is since it was his idea. ;)

>  2. Similarly, I can iterate over a FSArray, but it looks tedious to add
> elements into it (what should I do when the array exceeds it size ?) any
> example of how to do that ?
>

This is a traditional fixed-size array, just like for example a Java
array.  If you want to increase the size you have to allocate a new
array.

-Adam