/** * A Helper method to add annotation to CAS */ private AnnotationFS createSpanAnnotation(CAS aCas, int aBegin, int aEnd) throws AnnotationException { Type type = CasUtil.getType(aCas, getAnnotationTypeName()); AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd); // If if the layer attaches to a feature, then set the attach-feature to the newly // created annotation. if (getAttachFeatureName() != null) { Type theType = CasUtil.getType(aCas, getAttachTypeName()); Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName()); if (CasUtil.selectCovered(aCas, theType, aBegin, aEnd).isEmpty()) { throw new AnnotationException("No annotation of type [" + getAttachTypeName() + "] to attach to at location [" + aBegin + "-" + aEnd + "]."); } CasUtil.selectCovered(aCas, theType, aBegin, aEnd).get(0) .setFeatureValue(attachFeature, newAnnotation); } aCas.addFsToIndexes(newAnnotation); return newAnnotation; }
/** * A Helper method to add annotation to CAS */ private AnnotationFS createSpanAnnotation(CAS aCas, int aBegin, int aEnd) throws AnnotationException { Type type = CasUtil.getType(aCas, getAnnotationTypeName()); AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd); // If if the layer attaches to a feature, then set the attach-feature to the newly // created annotation. if (getAttachFeatureName() != null) { Type theType = CasUtil.getType(aCas, getAttachTypeName()); Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName()); if (CasUtil.selectCovered(aCas, theType, aBegin, aEnd).isEmpty()) { throw new AnnotationException("No annotation of type [" + getAttachTypeName() + "] to attach to at location [" + aBegin + "-" + aEnd + "]."); } CasUtil.selectCovered(aCas, theType, aBegin, aEnd).get(0) .setFeatureValue(attachFeature, newAnnotation); } aCas.addFsToIndexes(newAnnotation); return newAnnotation; }
@Override public void delete(SourceDocument aDocument, String aUsername, JCas aJCas, VID aVid) { AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId()); aJCas.removeFsFromIndexes(fs); // delete associated attachFeature if (getAttachTypeName() != null) { Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName()); Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName()); if (attachFeature != null) { CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0) .setFeatureValue(attachFeature, null); } } publishEvent(new SpanDeletedEvent(this, aDocument, aUsername, getLayer(), fs)); }
@Override public void delete(SourceDocument aDocument, String aUsername, JCas aJCas, VID aVid) { AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId()); aJCas.removeFsFromIndexes(fs); // delete associated attachFeature if (getAttachTypeName() != null) { Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName()); Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName()); if (attachFeature != null) { CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0) .setFeatureValue(attachFeature, null); } } publishEvent(new SpanDeletedEvent(this, aDocument, aUsername, getLayer(), fs)); }