use of org.apache.uima.cas.Feature in project webanno by webanno.
the class MergeCas method getAllFeatures.
public static Feature[] getAllFeatures(FeatureStructure aFS) {
Feature[] cachedSortedFeatures = new Feature[aFS.getType().getNumberOfFeatures()];
int i = 0;
for (Feature f : aFS.getType().getFeatures()) {
cachedSortedFeatures[i] = f;
i++;
}
return cachedSortedFeatures;
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class MergeCas method copySpanAnnotation.
/**
* Copy this same annotation from the user annotation to the mergeview
*/
private static void copySpanAnnotation(AnnotatorState aState, AnnotationSchemaService aAnnotationService, AnnotationLayer aAnnotationLayer, AnnotationFS aOldFs, JCas aJCas) throws AnnotationException {
SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aAnnotationLayer);
// Create the annotation - this also takes care of attaching to an annotation if necessary
int id = adapter.add(aState, aJCas, aOldFs.getBegin(), aOldFs.getEnd());
List<AnnotationFeature> features = aAnnotationService.listAnnotationFeature(adapter.getLayer());
// Copy the features
for (AnnotationFeature feature : features) {
Type oldType = adapter.getAnnotationType(aOldFs.getCAS());
Feature oldFeature = oldType.getFeatureByBaseName(feature.getName());
if (isLinkOrBasicFeatures(aOldFs, oldFeature)) {
continue;
}
Object value = adapter.getFeatureValue(feature, aOldFs);
adapter.setFeatureValue(aState, aJCas, id, feature, value);
}
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class CopyAnnotationTest method simpleCopyRelationToEmptyAnnoTest.
@Test
public void simpleCopyRelationToEmptyAnnoTest() throws Exception {
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());
Type posType = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);
AnnotationFS originClicked = createPOSAnno(jcas, posType, "NN", 0, 0);
AnnotationFS targetClicked = createPOSAnno(jcas, posType, "NN", 1, 1);
jcas.addFsToIndexes(originClicked);
jcas.addFsToIndexes(targetClicked);
originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"), originClicked);
targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"), targetClicked);
Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
AnnotationFS clickedFs = jcas.getCas().createAnnotation(type, 0, 1);
clickedFs.setFeatureValue(sourceFeature, originClickedToken);
clickedFs.setFeatureValue(targetFeature, targetClickedToken);
jcas.addFsToIndexes(clickedFs);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS origin = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
AnnotationFS target = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
mergeCAs.addFsToIndexes(origin);
mergeCAs.addFsToIndexes(target);
AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);
mergeCAs.addFsToIndexes(originToken);
mergeCAs.addFsToIndexes(targetToken);
MergeCas.addRelationArcAnnotation(mergeCAs, clickedFs, true, false, originToken, targetToken);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 1).size());
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class CopyAnnotationTest method simpleCopyToDiffExistingAnnoWithNoStackingTest.
@Test
public void simpleCopyToDiffExistingAnnoWithNoStackingTest() throws Exception {
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NE");
mergeCAs.addFsToIndexes(existingFs);
MergeCas.addSpanAnnotation(new AnnotatorStateImpl(Mode.CURATION), annotationSchemaService, posLayer, mergeCAs, clickedFs, false);
assertEquals(1, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class CopyAnnotationTest method simpleCopyStackedRelationTest.
@Test
public void simpleCopyStackedRelationTest() throws Exception {
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());
Type posType = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);
AnnotationFS originClicked = createPOSAnno(jcas, posType, "NN", 0, 0);
AnnotationFS targetClicked = createPOSAnno(jcas, posType, "NN", 1, 1);
jcas.addFsToIndexes(originClicked);
jcas.addFsToIndexes(targetClicked);
originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"), originClicked);
targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"), targetClicked);
Feature sourceFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
Feature targetFeature = type.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
AnnotationFS clickedFs = jcas.getCas().createAnnotation(type, 0, 1);
clickedFs.setFeatureValue(sourceFeature, originClickedToken);
clickedFs.setFeatureValue(targetFeature, targetClickedToken);
jcas.addFsToIndexes(clickedFs);
JCas mergeCAs = JCasFactory.createJCas();
AnnotationFS origin = createPOSAnno(mergeCAs, posType, "NN", 0, 0);
AnnotationFS target = createPOSAnno(mergeCAs, posType, "NN", 1, 1);
mergeCAs.addFsToIndexes(origin);
mergeCAs.addFsToIndexes(target);
AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);
mergeCAs.addFsToIndexes(originToken);
mergeCAs.addFsToIndexes(targetToken);
AnnotationFS existing = mergeCAs.getCas().createAnnotation(type, 0, 1);
existing.setFeatureValue(sourceFeature, originToken);
existing.setFeatureValue(targetFeature, targetToken);
mergeCAs.addFsToIndexes(clickedFs);
exception.expect(AnnotationException.class);
MergeCas.addRelationArcAnnotation(mergeCAs, clickedFs, true, false, originToken, targetToken);
}
Aggregations