/** * Get the single instance of the specified type from the CAS at the given offsets. * * @param aCas * the CAS containing the annotations. * @param aType * the type of annotations to fetch. * @param aBegin * the begin offset. * @param aEnd * the end offset. * @return the single annotation at the specified offsets. */ public static AnnotationFS selectSingleAt(final CAS aCas, final Type aType, int aBegin, int aEnd) { List<AnnotationFS> list = selectAt(aCas, aType, aBegin, aEnd); if (list.isEmpty()) { throw new IllegalArgumentException("CAS does not contain any [" + aType.getName() + "] at [" + aBegin + "," + aEnd + "]"); } if (list.size() > 1) { throw new IllegalArgumentException("CAS contains more than one [" + aType.getName() + "] at [" + aBegin + "," + aEnd + "]"); } return list.get(0); }
/** * Get all annotations of the given type at the specified offsets. * * @param <T> * the type of annotations to fetch. * @param jCas * the CAS containing the annotations. * @param type * the type of annotations to fetch. * @param aBegin * the begin offset. * @param aEnd * the end offset. * @return the annotations at the specified offsets. */ public static <T extends Annotation> List<T> selectAt(final JCas jCas, final Class<T> type, int aBegin, int aEnd) { return cast(CasUtil.selectAt(jCas.getCas(), getType(jCas, type), aBegin, aEnd)); }
private Optional<AnnotationFS> getMatchingAnnotation(CAS aCas, LearningRecord aRecord) { Type type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName()); Feature feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName()); return selectAt(aCas, type, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()).stream() .filter(fs -> aRecord.getAnnotation().equals(fs.getFeatureValueAsString(feature))) .findFirst(); }
private Optional<AnnotationFS> getMatchingAnnotation(CAS aCas, LearningRecord aRecord) { Type type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName()); Feature feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName()); return selectAt(aCas, type, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()).stream() .filter(fs -> aRecord.getAnnotation().equals(fs.getFeatureValueAsString(feature))) .findFirst(); }
List<AnnotationFS> sourceCandidates = CasUtil.selectAt(arc.getCAS(), source.getType(), source.getBegin(), source.getEnd()); if (sourceCandidates.size() > 1) { List<AnnotationFS> targetCandidates = CasUtil.selectAt(arc.getCAS(), target.getType(), target.getBegin(), target.getEnd()); if (targetCandidates.size() > 1) {