Benjamin Sznajder wrote:
> Hi Matthew
> 
> Thank you for your reply.
> Unfortunately, it does not iterate over the whole annotations.

It does iterate over all annotations, your code also
copies FSs that are not annotations.

> 
> I wrote this one and it seems to work
> 
>                   FSIndexRepository indexRep =
> aJCas.getFSIndexRepository();
>                   Iterator<String> labelIterators = indexRep.getLabels();
>                   while (labelIterators.hasNext()) {
>                         String label = labelIterators.next();
>                         FSIndex fsIndex = indexRep.getIndex(label);
>                         FSIterator fsiterator = fsIndex.iterator();
>                         while (fsiterator.hasNext()) {
>                               FeatureStructure fs = (FeatureStructure)
> fsiterator.next();
>       /// Copy the FeatureStructure using the CasCopier class.
> 
>                         }
>                   }

Your code is fine, but there is now a convenience method
for accessing all indexed FSs of a certain type.  So you
could simply do:

FSIterator fsIterator = jcas.getJFSIndexRepository().getAllIndexedFS(TOP.type);

Note that in your code, if you have more than one index for the
same type, you will copy some FSs more than once.  You can avoid
this by using the above convenience method.

Or even simpler:

CasCopier.copyCas(CAS aSrcCas, CAS aDestCas, boolean aCopySofa)

However, I assume you saw this and have good reasons for not
using it :-)

--Thilo

Reply via email to