use of org.apache.uima.cas.Feature in project webanno by webanno.
the class ArcAdapter method delete.
public void delete(AnnotatorState aState, JCas aJCas, AnnotationFeature aFeature, int aBegin, int aEnd, String aDepCoveredText, String aGovCoveredText, Object aValue) {
Feature dependentFeature = getAnnotationType(aJCas.getCas()).getFeatureByBaseName(getTargetFeatureName());
Feature governorFeature = getAnnotationType(aJCas.getCas()).getFeatureByBaseName(getSourceFeatureName());
AnnotationFS dependentFs = null;
AnnotationFS governorFs = null;
Type type = CasUtil.getType(aJCas.getCas(), getAnnotationTypeName());
Type spanType = getType(aJCas.getCas(), getAttachTypeName());
Feature arcSpanFeature = spanType.getFeatureByBaseName(getAttachFeatureName());
for (AnnotationFS fs : CasUtil.selectCovered(aJCas.getCas(), type, aBegin, aEnd)) {
if (getAttachFeatureName() != null) {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature).getFeatureValue(arcSpanFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature).getFeatureValue(arcSpanFeature);
} else {
dependentFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
governorFs = (AnnotationFS) fs.getFeatureValue(governorFeature);
}
if (aDepCoveredText.equals(dependentFs.getCoveredText()) && aGovCoveredText.equals(governorFs.getCoveredText())) {
if (ObjectUtils.equals(getFeatureValue(aFeature, fs), aValue)) {
delete(aState, aJCas, new VID(getAddr(fs)));
}
}
}
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class SpanAdapter method createAnnotation.
/**
* A Helper method to add annotation to CAS
*/
private Integer createAnnotation(AnnotatorState aState, CAS aCas, int aBegin, int aEnd) throws AnnotationException {
// If stacking is not allowed and there already is an annotation, then return the address
// of the existing annotation.
Type type = CasUtil.getType(aCas, getAnnotationTypeName());
for (AnnotationFS fs : CasUtil.selectCovered(aCas, type, aBegin, aEnd)) {
if (fs.getBegin() == aBegin && fs.getEnd() == aEnd) {
if (!allowStacking) {
return getAddr(fs);
}
}
}
AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd);
// 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);
publishEvent(new SpanCreatedEvent(this, aState.getDocument(), aState.getUser().getUsername(), newAnnotation));
return getAddr(newAnnotation);
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class SpanAdapter method getAnnotation.
@Override
public List<String> getAnnotation(Sentence aSentence, AnnotationFeature aFeature) {
CAS cas = aSentence.getCAS();
Type type = getType(cas, 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;
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class SpanAdapter method delete.
@Override
public void delete(AnnotatorState aState, 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, aState.getDocument(), aState.getUser().getUsername(), fs));
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class SpanAdapter method getMultipleAnnotation.
public Map<Integer, String> getMultipleAnnotation(Sentence sentence, AnnotationFeature aFeature) throws CASException {
Map<Integer, String> multAnno = new HashMap<>();
Type type = getType(sentence.getCAS(), 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;
}
Aggregations