Hi to all,
I'm developing a Segmenter for testing porpouse. At the end of our
pipeline, we want to serialize to disk the annotation created by each
annotators.
At the moment it doesn't work as I want :(
Let me explain the details.
To do that, each annotator "sign" the annotation it creates using a
feature called "annotatorId".
Now, in the segmeter, I'm able to extract, using constranints and
filtered iterator, the annotations created by each one:
//get le list of id:
AnnotationIndex annotationIndex =
jcas.getAnnotationIndex(Annotation.type);
FSIterator iterator = annotationIndex.iterator();
iterator.moveToFirst();
Annotation current;
Set<String> annotatorsIds = new TreeSet<String>();
while (iterator.hasNext()) {
current = (Annotation) iterator.next();
annotatorsIds.add(current.getAnnoId());
}
CAS cas = jcas.getCas();
Type type =
cas.getTypeSystem().getType(Annotation.class.getName());
FSIndex index = cas.getAnnotationIndex(type);
//get annnotaions for each annototar
for (String id : annotatorsIds) {
logger.info("------>getting annotation produced by ::"
+ id);
Annotation template = new Annotation(jcas);
template.setAnnoId(id);
ConstraintFactory cf = cas.getConstraintFactory();
FSStringConstraint stringConstraint =
cf.createStringConstraint();
stringConstraint.equals(id);
ArrayList path = new ArrayList();
path.add("annoId");
FSMatchConstraint cons = cf.embedConstraint(path,
stringConstraint);
FSIterator filteredIterator =
cas.createFilteredIterator(index.iterator(), cons);
filteredIterator.moveToFirst();
Now, to serialize it, I want to create a new cas and put in only this
annotation and then serialize it to xmi:
JCas newJCas = getEmptyJCas();
while (filteredIterator.isValid()) {
try {
FeatureStructure anno =
(FeatureStructure) filteredIterator.next();
FeatureStructure clone =
(FeatureStructure) anno.clone();
newJCas.setDocumentText(doc);
newJCas.addFsToIndexes(clone);
serialize(newJCas);
} catch (ResourceProcessException e) {
logger.error(e.getMessage(), e);
} finally {
newJCas.release();
}
}
where serialize(jcasnew) simply calls XMICasSerializer, after
calcutaing the right path for the file.
Well, it doesn't work:
org.apache.uima.cas.CASRuntimeException: Error - the Annotation "NX
sofa: _InitialView
[cut]
" is over view "_InitialView" and cannot be added to indexes
associated with the different view "_InitialView".
at org.apache.uima.cas.impl.CASImpl.addFsToIndexes(CASImpl.java:3781)
at org.apache.uima.jcas.impl.JCasImpl.addFsToIndexes(JCasImpl.java:1410)
at
it.celi.components.AnnotatorIdSegmenter.next(AnnotatorIdSegmenter.java:176)
at
org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.callAnalysisComponentNext(PrimitiveAnalysisEngine_impl.java:489)
at
org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl$AnalysisComponentCasIterator.next(PrimitiveAnalysisEngine_impl.java:594)
at
org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.process(AnalysisEngineImplBase.java:221)
at
org.apache.uima.collection.impl.cpm.engine.ProcessingUnit.processNext(ProcessingUnit.java:892)
at
org.apache.uima.collection.impl.cpm.engine.ProcessingUnit.run(ProcessingUnit.java:577)
I understand that the annotation is in charge of the original CAS, in
fact I want to clone it and put this new one in the new CAS/Jcas.
What I missed?
Thank in advance, regards,
R.
--
Roberto Franchini
http://www.celi.it
http://www.blogmeter.it
http://www.memesphere.it
Tel +39-011-6600814
jabber:[EMAIL PROTECTED] skype:ro.franchini