/** * Get the CAS type of the this {@link TypeAdapter} * * @param cas * the CAS. * @return the type. */ default Type getAnnotationType(CAS cas) { return CasUtil.getType(cas, getAnnotationTypeName()); }
/** * Get the CAS type of the this {@link TypeAdapter} * * @param cas * the CAS. * @return the type. */ default Type getAnnotationType(CAS cas) { return CasUtil.getType(cas, getAnnotationTypeName()); }
public static String getUiTypeName(TypeAdapter aAdapter) { return aAdapter.getTypeId() + "_" + aAdapter.getAnnotationTypeName(); }
public static String getUiTypeName(TypeAdapter aAdapter) { return aAdapter.getTypeId() + "_" + aAdapter.getAnnotationTypeName(); }
private static List<String> getAnnotation(TypeAdapter aAdapter, Sentence aSentence, AnnotationFeature aFeature) { CAS cas = aSentence.getCAS(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); List<String> annotations = new ArrayList<>(); for (Token token : selectCovered(Token.class, aSentence)) { List<AnnotationFS> tokenLevelAnnotations = selectCovered(type, token); if (tokenLevelAnnotations.size() > 0) { AnnotationFS anno = tokenLevelAnnotations.get(0); Feature labelFeature = anno.getType().getFeatureByBaseName(aFeature.getName()); annotations.add(anno.getFeatureValueAsString(labelFeature)); } else { annotations.add(NILL); } } return annotations; } }
private static List<String> getAnnotation(TypeAdapter aAdapter, Sentence aSentence, AnnotationFeature aFeature) { CAS cas = aSentence.getCAS(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); List<String> annotations = new ArrayList<>(); for (Token token : selectCovered(Token.class, aSentence)) { List<AnnotationFS> tokenLevelAnnotations = selectCovered(type, token); if (tokenLevelAnnotations.size() > 0) { AnnotationFS anno = tokenLevelAnnotations.get(0); Feature labelFeature = anno.getType().getFeatureByBaseName(aFeature.getName()); annotations.add(anno.getFeatureValueAsString(labelFeature)); } else { annotations.add(NILL); } } return annotations; } }
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isCrossSentence()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); for (AnnotationFS fs : select(cas, type)) { if (!isBeginEndInSameSentence(aJCas, fs.getBegin(), fs.getEnd())) { messages.add(Pair.of( LogMessage.error(this, "Crossing sentence bounardies is not permitted."), fs)); } } return messages; } }
Type type = getType(cas, aAdapter.getAnnotationTypeName());
Type type = getType(cas, aAdapter.getAnnotationTypeName()); Feature targetFeature = type.getFeatureByBaseName(adapter.getTargetFeatureName()); Feature sourceFeature = type.getFeatureByBaseName(adapter.getSourceFeatureName());
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isAllowStacking()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); AnnotationFS prevFS = null; List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); // Since the annotations are sorted, we can easily find stacked annotation by scanning // through the entire list and checking if two adjacent annotations have the same offsets for (AnnotationFS fs : select(cas, type)) { if (prevFS != null && prevFS.getBegin() == fs.getBegin() && prevFS.getEnd() == fs.getEnd()) { messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)); } prevFS = fs; } return messages; } }
@Override public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, JCas aJCas) { if (aAdapter.getLayer().isAllowStacking()) { return emptyList(); } CAS cas = aJCas.getCas(); Type type = getType(cas, aAdapter.getAnnotationTypeName()); AnnotationFS prevFS = null; List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>(); // Since the annotations are sorted, we can easily find stacked annotation by scanning // through the entire list and checking if two adjacent annotations have the same offsets for (AnnotationFS fs : select(cas, type)) { if (prevFS != null && prevFS.getBegin() == fs.getBegin() && prevFS.getEnd() == fs.getEnd()) { messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)); } prevFS = fs; } return messages; } }
@Deprecated private static void deleteSpanAnnotation(TypeAdapter aAdapter, AnnotatorState aState, JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, Object aValue) { Type type = CasUtil.getType(aJCas.getCas(), aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { if (ObjectUtils.equals(aAdapter.getFeatureValue(aFeature, fs), aValue)) { aAdapter.delete(aState.getDocument(), aState.getUser().getUsername(), aJCas, new VID(getAddr(fs))); } } } }
@Deprecated private static void deleteSpanAnnotation(TypeAdapter aAdapter, AnnotatorState aState, JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, Object aValue) { Type type = CasUtil.getType(aJCas.getCas(), aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { if (ObjectUtils.equals(aAdapter.getFeatureValue(aFeature, fs), aValue)) { aAdapter.delete(aState.getDocument(), aState.getUser().getUsername(), aJCas, new VID(getAddr(fs))); } } } }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isAllowStacking()) { return aRequest; } final CAS aCas = aRequest.getJcas().getCas(); final int aBegin = aRequest.getBegin(); final int aEnd = aRequest.getEnd(); // If stacking is not allowed and there already is an annotation, then return the address // of the existing annotation. Type type = getType(aCas, aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(aCas, type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { throw new AnnotationException("Cannot create another annotation of layer [" + aAdapter.getLayer().getUiName() + "] at this location - stacking is not " + "enabled for this layer."); } } return aRequest; }
@Override public CreateSpanAnnotationRequest onCreate(TypeAdapter aAdapter, CreateSpanAnnotationRequest aRequest) throws AnnotationException { if (aAdapter.getLayer().isAllowStacking()) { return aRequest; } final CAS aCas = aRequest.getJcas().getCas(); final int aBegin = aRequest.getBegin(); final int aEnd = aRequest.getEnd(); // If stacking is not allowed and there already is an annotation, then return the address // of the existing annotation. Type type = getType(aCas, aAdapter.getAnnotationTypeName()); for (AnnotationFS fs : selectCovered(aCas, type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { throw new AnnotationException("Cannot create another annotation of layer [" + aAdapter.getLayer().getUiName() + "] at this location - stacking is not " + "enabled for this layer."); } } return aRequest; }