use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class MergeCas method addSlotArcAnnotation.
private static void addSlotArcAnnotation(SpanAdapter aAdapter, JCas aJcas, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException {
List<AnnotationFS> merges = MergeCas.getMergeFS(aClickedFS, aJcas).collect(Collectors.toList());
AnnotationFS targetFs;
if (merges.size() == 0) {
throw new AnnotationException("The base annotation do not exist. Please add it first. ");
}
AnnotationFS mergeFs = merges.get(0);
int fiIndex = Integer.parseInt(aFSArcaddress.split("\\.")[1]);
int liIndex = Integer.parseInt(aFSArcaddress.split("\\.")[2]);
AnnotationFeature slotFeature = null;
LinkWithRoleModel linkRole = null;
int fi = 0;
f: for (AnnotationFeature feat : aAdapter.listFeatures()) {
if (MultiValueMode.ARRAY.equals(feat.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(feat.getLinkMode())) {
List<LinkWithRoleModel> links = aAdapter.getFeatureValue(feat, aClickedFS);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
if (fi == fiIndex && li == liIndex) {
slotFeature = feat;
List<AnnotationFS> targets = checkAndGetTargets(aJcas, aClickedJCas, selectByAddr(aClickedJCas, link.targetAddr));
targetFs = targets.get(0);
link.targetAddr = getAddr(targetFs);
linkRole = link;
break f;
}
}
}
fi++;
}
List<LinkWithRoleModel> links = aAdapter.getFeatureValue(slotFeature, mergeFs);
//
LinkWithRoleModel duplicateLink = null;
for (LinkWithRoleModel lr : links) {
if (lr.targetAddr == linkRole.targetAddr) {
duplicateLink = lr;
break;
}
}
links.add(linkRole);
links.remove(duplicateLink);
setFeature(mergeFs, slotFeature, links);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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 de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class CopyAnnotationTest method setup.
@Before
public void setup() {
project = new Project();
tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
tokenPosFeature = new AnnotationFeature();
tokenPosFeature.setName("pos");
tokenPosFeature.setEnabled(true);
tokenPosFeature.setType(POS.class.getName());
tokenPosFeature.setUiName("pos");
tokenPosFeature.setLayer(tokenLayer);
tokenPosFeature.setProject(project);
tokenPosFeature.setVisible(true);
posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
posLayer.setAttachType(tokenLayer);
posLayer.setAttachFeature(tokenPosFeature);
posFeature = new AnnotationFeature();
posFeature.setName("PosValue");
posFeature.setEnabled(true);
posFeature.setType(CAS.TYPE_NAME_STRING);
posFeature.setUiName("PosValue");
posFeature.setLayer(posLayer);
posFeature.setProject(project);
posFeature.setVisible(true);
slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
slotFeature = new AnnotationFeature();
slotFeature.setName("links");
slotFeature.setEnabled(true);
slotFeature.setType(Token.class.getName());
slotFeature.setLinkMode(LinkMode.WITH_ROLE);
slotFeature.setUiName("f1");
slotFeature.setLayer(slotLayer);
slotFeature.setProject(project);
slotFeature.setVisible(true);
stringFeature = new AnnotationFeature();
stringFeature.setName("f1");
stringFeature.setEnabled(true);
stringFeature.setType(CAS.TYPE_NAME_STRING);
stringFeature.setUiName("f1");
stringFeature.setLayer(slotLayer);
stringFeature.setProject(project);
stringFeature.setVisible(true);
annotationSchemaService = new MockUp<AnnotationSchemaService>() {
@Mock
List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
if (type.getName().equals(POS.class.getName())) {
return asList(posFeature);
}
if (type.getName().equals(DiffUtils.HOST_TYPE)) {
return asList(slotFeature, stringFeature);
}
throw new IllegalStateException("Unknown layer type: " + type.getName());
}
@Mock
TypeAdapter getAdapter(AnnotationLayer aLayer) {
return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
}
}.getMockInstance();
featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
featureSupportRegistry.init();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class ProjectLayersPanel method onModelChanged.
@Override
protected void onModelChanged() {
super.onModelChanged();
layerSelectionForm.getModelObject().layerSelection = null;
featureSelectionForm.getModelObject().feature = null;
layerDetailForm.setModelObject(new AnnotationLayer());
layerDetailForm.setVisible(false);
featureSelectionForm.setVisible(false);
featureDetailForm.setModelObject(new AnnotationFeature());
featureDetailForm.setVisible(false);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class CasDiff2 method getAdapters.
public static List<DiffAdapter> getAdapters(AnnotationSchemaService annotationService, Project project) {
List<DiffAdapter> adapters = new ArrayList<>();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(project)) {
Set<String> labelFeatures = new LinkedHashSet<>();
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!f.isEnabled()) {
continue;
}
// Link features are treated separately from primitive label features
if (!LinkMode.NONE.equals(f.getLinkMode())) {
continue;
}
labelFeatures.add(f.getName());
}
DiffAdapter_ImplBase adpt;
switch(layer.getType()) {
case SPAN_TYPE:
{
adpt = new SpanDiffAdapter(layer.getName(), labelFeatures);
break;
}
case RELATION_TYPE:
{
ArcAdapter typeAdpt = (ArcAdapter) annotationService.getAdapter(layer);
adpt = new ArcDiffAdapter(layer.getName(), typeAdpt.getSourceFeatureName(), typeAdpt.getTargetFeatureName(), labelFeatures);
break;
}
case CHAIN_TYPE:
// FIXME Currently, these are ignored.
continue;
default:
throw new IllegalStateException("Unknown layer type [" + layer.getType() + "]");
}
adapters.add(adpt);
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!f.isEnabled()) {
continue;
}
switch(f.getLinkMode()) {
case NONE:
// Nothing to do here
break;
case SIMPLE:
adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), null);
break;
case WITH_ROLE:
adpt.addLinkFeature(f.getName(), f.getLinkTypeRoleFeatureName(), f.getLinkTypeTargetFeatureName());
break;
default:
throw new IllegalStateException("Unknown link mode [" + f.getLinkMode() + "]");
}
labelFeatures.add(f.getName());
}
}
return adapters;
}
Aggregations