public static Map<Integer, String> getMultipleAnnotation( AnnotationSchemaService aAnnotationService, Sentence sentence, AnnotationFeature aFeature) throws CASException { SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aFeature.getLayer()); Map<Integer, String> multAnno = new HashMap<>(); Type type = getType(sentence.getCAS(), adapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(type, sentence)) { boolean isBegin = true; Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); for (Token token : selectCovered(Token.class, fs)) { if (multAnno.get(getAddr(token)) == null) { if (isBegin) { multAnno.put(getAddr(token), "B-" + fs.getFeatureValueAsString(labelFeature)); isBegin = false; } else { multAnno.put(getAddr(token), "I-" + fs.getFeatureValueAsString(labelFeature)); } } } } return multAnno; }
public static Map<Integer, String> getMultipleAnnotation( AnnotationSchemaService aAnnotationService, Sentence sentence, AnnotationFeature aFeature) throws CASException { SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aFeature.getLayer()); Map<Integer, String> multAnno = new HashMap<>(); Type type = getType(sentence.getCAS(), adapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(type, sentence)) { boolean isBegin = true; Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); for (Token token : selectCovered(Token.class, fs)) { if (multAnno.get(getAddr(token)) == null) { if (isBegin) { multAnno.put(getAddr(token), "B-" + fs.getFeatureValueAsString(labelFeature)); isBegin = false; } else { multAnno.put(getAddr(token), "I-" + fs.getFeatureValueAsString(labelFeature)); } } } } return multAnno; }
selection.getEnd() }); Type type = CasUtil.getType(aJCas.getCas(), aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(aJCas.getCas(), type, adjustedRange[0], adjustedRange[1])) {
/** * 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 int upsertFeature(AnnotationSchemaService annotationService, SourceDocument aDocument, String aUsername, JCas aJCas, AnnotationLayer layer, AnnotationFeature aFeature, String aValue, int aBegin, int aEnd) throws AnnotationException { // The feature of the predicted label SpanAdapter adapter = (SpanAdapter) annotationService.getAdapter(layer); // Check if there is already an annotation of the target type at the given location Type type = CasUtil.getType(aJCas.getCas(), adapter.getAnnotationTypeName()); AnnotationFS annoFS = selectSingleFsAt(aJCas, type, aBegin, aEnd); int address; if (annoFS != null) { // ... if yes, then we update the feature on the existing annotation address = getAddr(annoFS); } else { // ... if not, then we create a new annotation - this also takes care of attaching to // an annotation if necessary address = getAddr(adapter.add(aDocument, aUsername, aJCas, aBegin, aEnd)); } // Update the feature value adapter.setFeatureValue(aDocument, aUsername, aJCas, address, aFeature, aValue); return address; }
Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName()); List<AnnotationFS> annotations = selectCovered(aJcas.getCas(), type, aWindowBegin, aWindowEnd);
Type type = getType(aJcas.getCas(), typeAdapter.getAnnotationTypeName()); List<AnnotationFS> annotations = selectCovered(aJcas.getCas(), type, aWindowBegin, aWindowEnd);