}
}
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
CAS cas = jcas.getCas();
if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) {
initializeScript(cas.getViewName());
} else {
resetEnvironments(cas);
}
boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem();
if (!initialized || reloadScript || typeSystemChanged) {
initializeTypes(script, cas);
initialized = true;
lastTypeSystem = cas.getTypeSystem();
}
InferenceCrowd crowd = initializeCrowd();
RutaStream stream = initializeStream(cas, crowd);
stream.setDynamicAnchoring(dynamicAnchoring);
stream.setGreedyRuleElement(greedyRuleElement);
stream.setGreedyRule(greedyRule);
try {
script.apply(stream, crowd);
} catch (Throwable e) {
throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION,
new Object[] {}, e);
}
crowd.finished(stream);
if (removeBasics) {
List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>();
Type basicType = cas.getTypeSystem().getType(BASIC_TYPE);
AnnotationIndex<AnnotationFS> basicIndex = cas.getAnnotationIndex(basicType);
for (AnnotationFS fs : basicIndex) {
toRemove.add(fs);
}
for (Type seedType : seedTypes) {
AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType);
for (AnnotationFS fs : seedIndex) {
toRemove.add(fs);
}
}
for (AnnotationFS annotationFS : toRemove) {
cas.removeFsFromIndexes(annotationFS);
}
}
}