use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class LinkFeatureEditor method actionDel.
private void actionDel(AjaxRequestTarget aTarget) {
@SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) LinkFeatureEditor.this.getModelObject().value;
AnnotatorState state = LinkFeatureEditor.this.stateModel.getObject();
links.remove(state.getArmedSlot());
state.clearArmedSlot();
aTarget.add(content);
// Auto-commit if working on existing annotation
if (state.getSelection().getAnnotation().isSet()) {
try {
actionHandler.actionCreateOrUpdate(aTarget, actionHandler.getEditorCas());
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class LinkFeatureEditor method actionSet.
private void actionSet(AjaxRequestTarget aTarget) {
@SuppressWarnings("unchecked") List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) LinkFeatureEditor.this.getModelObject().value;
AnnotatorState state = LinkFeatureEditor.this.stateModel.getObject();
// Update the slot
LinkWithRoleModel m = links.get(state.getArmedSlot());
m.role = (String) field.getModelObject();
// avoid reordering
links.set(state.getArmedSlot(), m);
aTarget.add(content);
// and leaves behind an armed slot pointing to a removed slot.
if (m.targetAddr != -1) {
try {
actionHandler.actionCreateOrUpdate(aTarget, actionHandler.getEditorCas());
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class AnnotationDetailEditorPanel method getAttachedLinks.
private Set<AnnotationFS> getAttachedLinks(AnnotationFS aFs, AnnotationLayer aLayer) {
CAS cas = aFs.getCAS();
Set<AnnotationFS> attachedLinks = new HashSet<>();
TypeAdapter adapter = annotationService.getAdapter(aLayer);
if (adapter instanceof SpanAdapter) {
for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(aLayer)) {
if (MultiValueMode.ARRAY.equals(linkFeature.getMultiValueMode()) && LinkMode.WITH_ROLE.equals(linkFeature.getLinkMode())) {
// Fetch slot hosts that could link to the current FS and check if any of
// them actually links to the current FS
Type linkType = CasUtil.getType(cas, linkFeature.getLayer().getName());
for (AnnotationFS linkFS : CasUtil.select(cas, linkType)) {
List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
for (int li = 0; li < links.size(); li++) {
LinkWithRoleModel link = links.get(li);
AnnotationFS linkTarget = selectByAddr(cas, AnnotationFS.class, link.targetAddr);
// our list of attached links.
if (isSame(linkTarget, aFs)) {
attachedLinks.add(linkFS);
}
}
}
}
}
}
return attachedLinks;
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class AnnotationDetailEditorPanel method setSlot.
@SuppressWarnings("unchecked")
private void setSlot(AjaxRequestTarget aTarget, JCas aJCas, int aAnnotationId) {
AnnotatorState state = getModelObject();
// Set an armed slot
if (!state.getSelection().isArc() && state.isSlotArmed()) {
List<LinkWithRoleModel> links = (List<LinkWithRoleModel>) state.getFeatureState(state.getArmedFeature()).value;
LinkWithRoleModel link = links.get(state.getArmedSlot());
link.targetAddr = aAnnotationId;
link.label = selectByAddr(aJCas, aAnnotationId).getCoveredText();
}
// Auto-commit if working on existing annotation
if (state.getSelection().getAnnotation().isSet()) {
try {
actionCreateOrUpdate(aTarget, aJCas);
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
state.clearArmedSlot();
}
use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel in project webanno by webanno.
the class AnnotationDetailEditorPanel method deleteAnnotation.
private void deleteAnnotation(JCas jCas, AnnotatorState state, AnnotationFS fs, AnnotationLayer layer, TypeAdapter adapter) {
// is no longer set after UNATTACH SPANS!
if (adapter instanceof SpanAdapter) {
for (AnnotationFS attachedFs : getAttachedRels(fs, layer)) {
jCas.getCas().removeFsFromIndexes(attachedFs);
info("The attached annotation for relation type [" + annotationService.getLayer(attachedFs.getType().getName(), state.getProject()).getUiName() + "] is deleted");
}
}
// to look at span annotations that have the same offsets as the FS to be deleted.
if (adapter instanceof SpanAdapter && layer.getAttachType() != null && layer.getAttachFeature() != null) {
Type spanType = CasUtil.getType(jCas.getCas(), layer.getAttachType().getName());
Feature attachFeature = spanType.getFeatureByBaseName(layer.getAttachFeature().getName());
for (AnnotationFS attachedFs : getAttachedSpans(fs, layer)) {
attachedFs.setFeatureValue(attachFeature, null);
LOG.debug("Unattached [" + attachFeature.getShortName() + "] on annotation [" + getAddr(attachedFs) + "]");
}
}
// to be deleted: the link feature must be the type of the FS or it must be generic.
if (adapter instanceof SpanAdapter) {
for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(layer)) {
Type linkType = CasUtil.getType(jCas.getCas(), linkFeature.getLayer().getName());
for (AnnotationFS linkFS : CasUtil.select(jCas.getCas(), linkType)) {
List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
Iterator<LinkWithRoleModel> i = links.iterator();
boolean modified = false;
while (i.hasNext()) {
LinkWithRoleModel link = i.next();
if (link.targetAddr == getAddr(fs)) {
i.remove();
LOG.debug("Cleared slot [" + link.role + "] in feature [" + linkFeature.getName() + "] on annotation [" + getAddr(linkFS) + "]");
modified = true;
}
}
if (modified) {
setFeature(linkFS, linkFeature, links);
}
}
}
}
// relation.
if (adapter instanceof ArcAdapter) {
// Do nothing ;)
}
// Actually delete annotation
adapter.delete(state, jCas, state.getSelection().getAnnotation());
}
Aggregations