Benjamin:

I'm doing something similar I think, and my method for copying annotations generically is shown below. The UIMA gurus out there can feel free to correct it, as I put it together as best I can from wandering around the javadocs. The key is the copyFs() method, which deep copies the annotation and doesn't require any sort of TypeSystem knowledge to use. I'm using the CasCopier to move annotations between two Sofa views here, but the same could be done to move from one Cas to another I think. In that case I would remove the stuff about updating the 'sofa' feature.

JCas originalContent = aJCAS.getView("originalContent");
JCas mergedContent = aJCAS.createView("mergedContent");

CasCopier copier = new CasCopier(originalContent .getCas(), mergedContent.getCas());

//First, get all of the annotations in the originalContent so
//we can propagate them to the mergedContent view.
FSIterator iter = originalContent .getAnnotationIndex().iterator();
while (iter.hasNext()) {
  Annotation currAnnot = (Annotation)iter.next();

  //make a copy of the annotation
  Annotation newAnnot = (Annotation)copier.copyFs(currAnnot);
  Feature sofaFeature = newAnnot.getType().getFeatureByBaseName("sofa");
  newAnnot.setFeatureValue(sofaFeature, mergedContent.getSofa());
  mergedContent.addFsToIndexes(newAnnot);
}

As I said, it's a bit hacked together, but I think it's working fine for me.


-Matt

Benjamin Sznajder wrote:
Hi,

I would like to write a CASMerger that knows to iterate over the
annotations in the CAS and to copy them to the "mergedCAS".

My question is : is there a way to iterate over these annotations if I do
not know the typeSystem and the annotators this CAS passed through? I would
like to write an as most generic as possible CASMerger class.

Many thanks
Benjamin


Reply via email to