cas.removeFsFromIndexes(it.next());
cas.removeFsFromIndexes(annotation);
private void removePredictions(CAS aCas, Type aPredictionType) { for (AnnotationFS fs : CasUtil.select(aCas, aPredictionType)) { aCas.removeFsFromIndexes(fs); } }
public static void removeSourceDocumentInformation(CAS cas) { Type sdiType = cas.getTypeSystem() .getType("org.apache.uima.examples.SourceDocumentInformation"); if (sdiType != null) { AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex(sdiType); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (AnnotationFS annotationFS : annotationIndex) { toRemove.add(annotationFS); } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }
public static void removeSourceDocumentInformation(CAS cas) { Type sdiType = cas.getTypeSystem() .getType("org.apache.uima.examples.SourceDocumentInformation"); if (sdiType != null) { AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex(sdiType); List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>(); for (AnnotationFS annotationFS : annotationIndex) { toRemove.add(annotationFS); } for (AnnotationFS annotationFS : toRemove) { cas.removeFsFromIndexes(annotationFS); } } }
cas.removeFsFromIndexes(it.next());
private void removeAnnotations(CAS cas, Type t) { LinkedList<AnnotationFS> annoToRemove = Lists.newLinkedList(cas.getAnnotationIndex(t)); for (AnnotationFS anno : annoToRemove) { cas.removeFsFromIndexes(anno); } if (getLogger().isDebugEnabled()) { getLogger().debug(String.format( "%s annotations of type %s have been removed", annoToRemove.size(), t)); } } }
private void removePredictedAnnotations(CAS aCas) { Type type = CasUtil.getType(aCas, getPredictedType()); for (AnnotationFS annotationFS : CasUtil.select(aCas, type)) { aCas.removeFsFromIndexes(annotationFS); } }
private void removePredictedAnnotations(CAS aCas) { Type type = CasUtil.getType(aCas, getPredictedType()); for (AnnotationFS annotationFS : CasUtil.select(aCas, type)) { aCas.removeFsFromIndexes(annotationFS); } }
public Type seed(String text, CAS cas) { Type result = super.seed(text, cas); JCas jCas = null; try { jCas = cas.getJCas(); } catch (CASException e) { throw new RuntimeException(e); } // FIXME: lexer rules for html markup won't work. Therefore, those rules where removed in the // grammar and the functionality is included directly with regex if (text != null) { Matcher matcher = markupPattern.matcher(text); Collection<AnnotationFS> toRemove = new LinkedList<AnnotationFS>(); while (matcher.find()) { int begin = matcher.start(); int end = matcher.end(); MARKUP markup = new MARKUP(jCas, begin, end); markup.addToIndexes(); List<AnnotationFS> selectCovered = CasUtil.selectCovered(result, markup); toRemove.addAll(selectCovered); } for (AnnotationFS each : toRemove) { cas.removeFsFromIndexes(each); } } return result; } }
/** * {@inheritDoc} */ @Override public void process(CAS cas) throws AnalysisEngineProcessException { for (AnnotationFS anno : cas.getAnnotationIndex(annoType)) { String featValue = extractValue(anno); if (featValue == null) { return; } Matcher matcher = pattern.matcher(featValue); if (matcher.matches()) { String newFeatValue = matcher.replaceAll(replaceBy); if (!newFeatValue.equals(featValue)) { cas.removeFsFromIndexes(anno); setValue(anno, newFeatValue); cas.addFsToIndexes(anno); getLogger().info(String.format( "Replacement done for feature %s.%s: '%s' => '%s'", annoTypeName, featurePathString, featValue, newFeatValue)); } } } }
@Override public void process(CAS aCas) throws AnalysisEngineProcessException { Collection<FeatureStructure> toAdd = new ArrayList<FeatureStructure>(); Collection<FeatureStructure> toRemove = new ArrayList<FeatureStructure>(); Type type = aCas.getTypeSystem().getType(tokenType); for (AnnotationFS token : select(aCas, type)) { split(aCas, token, token.getCoveredText(), toAdd, toRemove); } for (FeatureStructure a : toAdd) { aCas.addFsToIndexes(a); } for (FeatureStructure a : toRemove) { aCas.removeFsFromIndexes(a); } }
@Override public void process(CAS aCas) throws AnalysisEngineProcessException { Collection<FeatureStructure> toAdd = new ArrayList<FeatureStructure>(); Collection<FeatureStructure> toRemove = new ArrayList<FeatureStructure>(); Type type = aCas.getTypeSystem().getType(tokenType); for (AnnotationFS token : select(aCas, type)) { split(aCas, token, token.getCoveredText(), toAdd, toRemove); } for (FeatureStructure a : toAdd) { aCas.addFsToIndexes(a); } for (FeatureStructure a : toRemove) { aCas.removeFsFromIndexes(a); } }
@Nullable @Override public String put(String key, String value) { FeatureStructure check = metadataCas.createFS(metadataType); check.setStringValue(keyFeature, key); FeatureStructure fs = metadataIndex.find(check); String existing = null; if (fs != null) { existing = fs.getStringValue(valueFeature); metadataCas.removeFsFromIndexes(fs); } else { fs = check; } fs.setStringValue(valueFeature, value); metadataCas.addFsToIndexes(fs); return existing; }
cas.removeFsFromIndexes(toSplit); toSplit.setEnd(anchor); TextMarkerBasic newTMB = new TextMarkerBasic(getJCas(), anchor, newEnd);
@Override public void execute(RuleMatch match, RuleElement element, TextMarkerStream stream, InferenceCrowd crowd) { List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(stream, null, element.getContainer()); for (AnnotationFS matchedAnnotation : matchedAnnotations) { if (matchedAnnotation == null) { return; } Type type = getStructureType().getType(element.getParent()); List<AnnotationFS> list = stream.getAnnotationsInWindow(matchedAnnotation, type); if (list.isEmpty()) { list = stream.getOverappingAnnotations(matchedAnnotation, type); } // // for (AnnotationFS each : list) { // fillFeatures((Annotation)each, features, matchedAnnotation, element, stream); // } if (!list.isEmpty()) { AnnotationFS annotationFS = list.get(0); stream.getCas().removeFsFromIndexes(annotationFS); fillFeatures((Annotation) annotationFS, features, matchedAnnotation, element, stream); stream.getCas().addFsToIndexes(annotationFS); } } }
public void removeAnnotation(AnnotationFS annotation, Type type) { if (type.getName().equals(CAS.TYPE_NAME_DOCUMENT_ANNOTATION)) { // do not remove DocumentAnnotation return; } Collection<RutaBasic> basicAnnotationsInWindow = getAllBasicsInWindow(annotation); for (RutaBasic basic : basicAnnotationsInWindow) { basic.removePartOf(type); } Type parent = type; RutaBasic beginAnchor = getBeginAnchor(annotation.getBegin()); RutaBasic endAnchor = getEndAnchor(annotation.getEnd()); if (beginAnchor != null) { beginAnchor.removeBegin(annotation, parent); } if (endAnchor != null) { endAnchor.removeEnd(annotation, parent); } if (!(annotation instanceof RutaBasic)) { cas.removeFsFromIndexes(annotation); } }
public void removeAnnotation(AnnotationFS annotation, Type type) { Collection<TextMarkerBasic> basicAnnotationsInWindow = getAllBasicsInWindow(annotation); for (TextMarkerBasic basic : basicAnnotationsInWindow) { basic.removePartOf(type); } Type parent = type; TextMarkerBasic beginAnchor = getBeginAnchor(annotation.getBegin()); TextMarkerBasic endAnchor = getEndAnchor(annotation.getEnd()); beginAnchor.removeBegin(annotation, parent); endAnchor.removeEnd(annotation, parent); if (!(annotation instanceof TextMarkerBasic)) { cas.removeFsFromIndexes(annotation); } }
@Override public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { RuleMatch match = context.getRuleMatch(); RuleElement element = context.getElement(); element.getParent(); String featureString = featureStringExpression.getStringValue(context, stream); List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOfElement(element); for (AnnotationFS annotationFS : matchedAnnotations) { Feature feature = annotationFS.getType().getFeatureByBaseName(featureString); if (feature != null) { stream.getCas().removeFsFromIndexes(annotationFS); stream.assignFeatureValue(annotationFS, feature, expr, context); stream.getCas().addFsToIndexes(annotationFS); } else { throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText)."); } } }
private void splitAnnotationOnComplete(Annotation annotation, Type typeToSplit, boolean addToBegin, boolean addToEnd, RuleMatch match, RutaStream stream) { List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(annotation, typeToSplit); if (annotationsInWindow == null || annotationsInWindow.isEmpty()) { return; } CAS cas = annotation.getCAS(); CasCopier cc = new CasCopier(cas, cas); cas.removeFsFromIndexes(annotation); int overallEnd = annotation.getEnd(); Annotation first = annotation; for (AnnotationFS each : annotationsInWindow) { int firstEnd = addToEnd ? each.getEnd() : each.getBegin(); first.setEnd(firstEnd); boolean valid = trimInvisible(first, stream); if (valid) { stream.addAnnotation(first, true, true, match); } Annotation second = (Annotation) cc.copyFs(first); int secondBegin = addToBegin ? each.getBegin() : each.getEnd(); second.setBegin(secondBegin); second.setEnd(overallEnd); valid = trimInvisible(second, stream); if (valid) { stream.addAnnotation(second, true, true, match); } first = second; } }