@Override public String getText(Annotation annotation) { synchronized (annotation.getCAS()) { return annotation.getCoveredText().toLowerCase(); } }
/** * Trim the offsets of the given annotation to remove leading/trailing whitespace. * <p> * <b>Note:</b> use this method only if the document text of the CAS has already been set! * <p> * <b>Note:</b> best use this method before adding the annotation to the indexes. * * @param aAnnotation * the annotation to trim. Offsets are updated. */ public static void trim(Annotation aAnnotation) { trim(aAnnotation.getCAS().getDocumentText(), aAnnotation); }
/** * Trim the offsets of the given annotation to remove leading/trailing whitespace. * <p> * <b>Note:</b> use this method only if the document text of the CAS has already been set! * <p> * <b>Note:</b> best use this method before adding the annotation to the indexes. * * @param aAnnotation * the annotation to trim. Offsets are updated. */ public static void trim(Annotation aAnnotation) { trim(aAnnotation.getCAS().getDocumentText(), aAnnotation); }
public static Token getHeadTokenOfAnnotation(Annotation annotation) { try { return getHeadTokenInRange(annotation.getCAS().getJCas(), annotation.getBegin(), annotation.getEnd()); } catch (CASException e) { return null; } }
public void token(Annotation annotation, String tag, String lemma) { CAS cas = annotation.getCAS(); int begin = annotation.getBegin(); int end = annotation.getEnd(); String picked = null; if (lemma == null) { picked = annotation.getCoveredText(); // "unknown" } else { String lemmata[] = lemma.split("\\|"); if (lemmata.length == 0) { picked = lemma; } else { picked = lemmata[lemmata.length - 1]; } } if (picked.endsWith("?")) { picked = picked.substring(0, picked.length() - 1); } assert (picked != null); if (this.update) { this.update(cas, annotation, this.tagFeature, tag); this.update(cas, annotation, this.lemmaFeature, picked); } else { this.annotate(cas, this.tagFeature, begin, end, tag); this.annotate(cas, this.lemmaFeature, begin, end, picked); } }
private void addMergeToHistory(Annotation keep, Annotation removed) { if (keep instanceof Recordable && removed instanceof Base) { Recordable r = (Recordable) keep; Base b = (Base) removed; try { addToHistory( keep.getCAS().getJCas(), HistoryEvents.createMerged(r, referrer, b.getInternalId())); } catch (CASException e) { monitor.error("Unable to add merge to history", e); } } }
private void addMergeToHistory(Annotation keep, Annotation removed) { if (keep instanceof Recordable && removed instanceof Base) { Recordable r = (Recordable) keep; Base b = (Base) removed; try { addToHistory( keep.getCAS().getJCas(), HistoryEvents.createMerged(r, referrer, b.getInternalId())); } catch (CASException e) { monitor.error("Unable to add merge to history", e); } } }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
srcCAS = srcCAS == null ? curAnno.getCAS() : srcCAS;
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
throws CASException JCas aJCas = root.getCAS().getJCas();
aJCas = root.getCAS().getJCas();
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; } }
/** * Remove an annotation to the JCas index, notifying UimaMonitor of the fact we have done so. * * <p>Relations that refer to the given annotation will also be removed. * * @param annot Annotation(s) to remove */ public void remove(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { if (annot instanceof Recordable) { try { addToHistory( annot.getCAS().getJCas(), HistoryEvents.createAdded((Recordable) annot, referrer)); } catch (CASException e) { monitor.error("Unable to add to history on remove", e); } } if (annot instanceof Entity) { for (Relation r : getRelations((Entity) annot)) { monitor.entityRemoved(r.getType().getName()); r.removeFromIndexes(); } } monitor.entityRemoved(annot.getType().getName()); annot.removeFromIndexes(); } }
/** * Remove an annotation to the JCas index, notifying UimaMonitor of the fact we have done so. * * <p>Relations that refer to the given annotation will also be removed. * * @param annot Annotation(s) to remove */ public void remove(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { if (annot instanceof Recordable) { try { addToHistory( annot.getCAS().getJCas(), HistoryEvents.createAdded((Recordable) annot, referrer)); } catch (CASException e) { monitor.error("Unable to add to history on remove", e); } } if (annot instanceof Entity) { for (Relation r : getRelations((Entity) annot)) { monitor.entityRemoved(r.getType().getName()); r.removeFromIndexes(); } } monitor.entityRemoved(annot.getType().getName()); annot.removeFromIndexes(); } }
Collection<RutaBasic> basics = stream.getAllBasicsInWindow(annotation); CAS cas = annotation.getCAS(); CasCopier cc = new CasCopier(cas, cas);