use of org.apache.uima.cas.Feature in project lucene-solr by apache.
the class SampleEntityAnnotator method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
Feature entityFeature = type.getFeatureByBaseName(ENTITY_FEATURE);
Feature nameFeature = type.getFeatureByBaseName(NAME_FEATURE);
for (Annotation annotation : jcas.getAnnotationIndex(TokenAnnotation.type)) {
String tokenPOS = ((TokenAnnotation) annotation).getPosTag();
if (NP.equals(tokenPOS) || NPS.equals(tokenPOS)) {
AnnotationFS entityAnnotation = jcas.getCas().createAnnotation(type, annotation.getBegin(), annotation.getEnd());
entityAnnotation.setStringValue(entityFeature, annotation.getCoveredText());
// "OTHER" makes no sense. In practice, "PERSON", "COUNTRY", "E-MAIL", etc.
String name = "OTHER";
if (annotation.getCoveredText().equals("Apache"))
name = "ORGANIZATION";
entityAnnotation.setStringValue(nameFeature, name);
jcas.addFsToIndexes(entityAnnotation);
}
}
}
use of org.apache.uima.cas.Feature in project lucene-solr by apache.
the class SamplePoSTagger method process.
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Type type = jcas.getCas().getTypeSystem().getType(TYPE_NAME);
Feature posFeature = type.getFeatureByBaseName(FEATURE_NAME);
for (Annotation annotation : jcas.getAnnotationIndex(type)) {
String text = annotation.getCoveredText();
String pos = extractPoS(text);
annotation.setStringValue(posFeature, pos);
}
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class AnnotationDetailEditorPanel method getAttachedSpans.
private Set<AnnotationFS> getAttachedSpans(AnnotationFS aFs, AnnotationLayer aLayer) {
CAS cas = aFs.getCAS();
Set<AnnotationFS> attachedSpans = new HashSet<>();
TypeAdapter adapter = annotationService.getAdapter(aLayer);
if (adapter instanceof SpanAdapter && aLayer.getAttachType() != null) {
Type spanType = CasUtil.getType(cas, aLayer.getAttachType().getName());
Feature attachFeature = spanType.getFeatureByBaseName(aLayer.getAttachFeature().getName());
for (AnnotationFS attachedFs : selectAt(cas, spanType, aFs.getBegin(), aFs.getEnd())) {
if (isSame(attachedFs.getFeatureValue(attachFeature), aFs)) {
attachedSpans.add(attachedFs);
}
}
}
return attachedSpans;
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class AnnotationDetailEditorPanel method getAttachedRels.
public Set<AnnotationFS> getAttachedRels(AnnotationFS aFs, AnnotationLayer aLayer) {
CAS cas = aFs.getCAS();
Set<AnnotationFS> toBeDeleted = new HashSet<>();
for (AnnotationLayer relationLayer : annotationService.listAttachedRelationLayers(aLayer)) {
ArcAdapter relationAdapter = (ArcAdapter) annotationService.getAdapter(relationLayer);
Type relationType = CasUtil.getType(cas, relationLayer.getName());
Feature sourceFeature = relationType.getFeatureByBaseName(relationAdapter.getSourceFeatureName());
Feature targetFeature = relationType.getFeatureByBaseName(relationAdapter.getTargetFeatureName());
// This code is already prepared for the day that relations can go between
// different layers and may have different attach features for the source and
// target layers.
Feature relationSourceAttachFeature = null;
Feature relationTargetAttachFeature = null;
if (relationAdapter.getAttachFeatureName() != null) {
relationSourceAttachFeature = sourceFeature.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
relationTargetAttachFeature = targetFeature.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
}
for (AnnotationFS relationFS : CasUtil.select(cas, relationType)) {
// Here we get the annotations that the relation is pointing to in the UI
FeatureStructure sourceFS;
if (relationSourceAttachFeature != null) {
sourceFS = relationFS.getFeatureValue(sourceFeature).getFeatureValue(relationSourceAttachFeature);
} else {
sourceFS = relationFS.getFeatureValue(sourceFeature);
}
FeatureStructure targetFS;
if (relationTargetAttachFeature != null) {
targetFS = relationFS.getFeatureValue(targetFeature).getFeatureValue(relationTargetAttachFeature);
} else {
targetFS = relationFS.getFeatureValue(targetFeature);
}
if (isSame(sourceFS, aFs) || isSame(targetFS, aFs)) {
toBeDeleted.add(relationFS);
LOG.debug("Deleted relation [" + getAddr(relationFS) + "] from layer [" + relationLayer.getName() + "]");
}
}
}
return toBeDeleted;
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class WebannoTsv3Reader method addChainAnnotations.
/**
* The individual link annotations are stored in a {@link TreeMap} (chainAnnosPerTye) with chain
* number and link number references, sorted in an ascending order <br>
* Iterate over each chain number and link number references and construct the chain.
*/
private void addChainAnnotations(JCas aJCas) {
for (Type linkType : chainAnnosPerTyep.keySet()) {
for (int chainNo : chainAnnosPerTyep.get(linkType).keySet()) {
Type chainType = aJCas.getCas().getTypeSystem().getType(linkType.getName().substring(0, linkType.getName().length() - 4) + CHAIN);
Feature firstF = chainType.getFeatureByBaseName(FIRST);
Feature nextF = linkType.getFeatureByBaseName(NEXT);
FeatureStructure chain = aJCas.getCas().createFS(chainType);
aJCas.addFsToIndexes(chain);
AnnotationFS firstFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(1);
AnnotationFS linkFs = firstFs;
chain.setFeatureValue(firstF, firstFs);
for (int i = 2; i <= chainAnnosPerTyep.get(linkType).get(chainNo).size(); i++) {
linkFs.setFeatureValue(nextF, chainAnnosPerTyep.get(linkType).get(chainNo).get(i));
linkFs = chainAnnosPerTyep.get(linkType).get(chainNo).get(i);
}
}
}
}
Aggregations