private String getFeatureValueCovering(CAS aCas, AnnotationFS aToken, Type aType, Feature aFeature) { List<AnnotationFS> annotations = CasUtil.selectCovered(aType, aToken); if (annotations.isEmpty()) { return PAD; } String value = annotations.get(0).getFeatureValueAsString(aFeature); return isNoneBlank(value) ? value : PAD; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
public static List<AnnotationFS> selectAt(CAS aJcas, final Type type, int aBegin, int aEnd) { List<AnnotationFS> covered = CasUtil.selectCovered(aJcas, type, aBegin, aEnd); // Remove all that do not have the exact same offset covered.removeIf(cur -> !(cur.getBegin() == aBegin && cur.getEnd() == aEnd)); return covered; }
private static void getAllAnnosOnPosition(Map<String, JCas> aJCases, Map<String, List<FeatureStructure>> aAnnosPerUser, Set<String> aUsers, AnnotationFS aMergeAnno) { for (String user : aUsers) { List<AnnotationFS> fssAtThisPosition = selectCovered(aJCases.get(user).getCas(), aMergeAnno.getType(), aMergeAnno.getBegin(), aMergeAnno.getEnd()); if (!aAnnosPerUser.containsKey(user)) { aAnnosPerUser.put(user, (List) fssAtThisPosition); } else { aAnnosPerUser.get(user).addAll(fssAtThisPosition); } } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { Collection<AnnotationFS> sequences = CasUtil.select(aJCas.getCas(), sequenceSpanType); for (AnnotationFS s : sequences) { int seqSize = CasUtil.selectCovered(aJCas.getCas(), instanceType, s).size(); if (seqSize > maximumLength) { maximumLength = seqSize; } } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { Collection<AnnotationFS> sequences = CasUtil.select(aJCas.getCas(), sequenceSpanType); for (AnnotationFS s : sequences) { int seqSize = CasUtil.selectCovered(aJCas.getCas(), instanceType, s).size(); if (seqSize > maximumLength) { maximumLength = seqSize; } } }
/** * Get an annotation using the begin/offsets and its type */ public static AnnotationFS selectSingleFsAt(JCas aJcas, Type aType, int aBegin, int aEnd) { for (AnnotationFS anFS : selectCovered(aJcas.getCas(), aType, aBegin, aEnd)) { if (anFS.getBegin() == aBegin && anFS.getEnd() == aEnd) { return anFS; } } return null; }
private static Stream<AnnotationFS> getMergeFS(AnnotationFS aOldFs, JCas aJCas) { return selectCovered(aJCas.getCas(), aOldFs.getType(), aOldFs.getBegin(), aOldFs.getEnd()) .stream().filter(fs -> isSameAnno(fs, aOldFs)); }
private static Stream<AnnotationFS> getMergeFS(AnnotationFS aOldFs, JCas aJCas) { return selectCovered(aJCas.getCas(), aOldFs.getType(), aOldFs.getBegin(), aOldFs.getEnd()) .stream().filter(fs -> isSameAnno(fs, aOldFs)); }
private static List<AnnotationFS> getRelAnnosOnPosition(AnnotationFS aFs, AnnotationFS aOriginFs, AnnotationFS aTargetFs, JCas aJcas) { Type type = aFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); return selectCovered(aJcas.getCas(), type, aFs.getBegin(), aFs.getEnd()).stream() .filter(fs -> fs.getFeatureValue(sourceFeat).equals(aOriginFs) && fs.getFeatureValue(targetFeat).equals(aTargetFs)) .collect(Collectors.toList()); }
private static List<AnnotationFS> getRelAnnosOnPosition(AnnotationFS aFs, AnnotationFS aOriginFs, AnnotationFS aTargetFs, JCas aJcas) { Type type = aFs.getType(); Feature sourceFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE); Feature targetFeat = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET); return selectCovered(aJcas.getCas(), type, aFs.getBegin(), aFs.getEnd()).stream() .filter(fs -> fs.getFeatureValue(sourceFeat).equals(aOriginFs) && fs.getFeatureValue(targetFeat).equals(aTargetFs)) .collect(Collectors.toList()); }
private static List<AnnotationFS> getAnnosOnPosition(AnnotationFS aFs, JCas aJcas) { return selectCovered(aJcas.getCas(), aFs.getType(), aFs.getBegin(), aFs.getEnd()); }
private static List<AnnotationFS> getAnnosOnPosition(AnnotationFS aFs, JCas aJcas) { return selectCovered(aJcas.getCas(), aFs.getType(), aFs.getBegin(), aFs.getEnd()); }
@Override public List<String> getAnnotation(JCas aJcas, AnnotationFeature aFeature, int begin, int end) { Type type = getType(aJcas.getCas(), getAnnotationTypeName()); List<String> annotations = new ArrayList<String>(); for (AnnotationFS fs : selectCovered(aJcas.getCas(), type, begin, end)) { Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName()); annotations.add(fs.getFeatureValueAsString(labelFeature)); } return annotations; }
@Override public void delete(JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, String aValue) { Type type = CasUtil.getType(aJCas.getCas(), getAnnotationTypeName()); Feature feature = type.getFeatureByBaseName(aFeature.getName()); for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) { if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) { if (fs.getFeatureValueAsString(feature).equals(aValue)) { delete(aJCas, ((FeatureStructureImpl) fs).getAddress()); } } } }
@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 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)); }