use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationDetailEditorPanel method actionDelete.
@Override
public void actionDelete(AjaxRequestTarget aTarget) throws IOException, AnnotationException {
JCas jCas = getEditorCas();
AnnotatorState state = getModelObject();
AnnotationFS fs = selectByAddr(jCas, state.getSelection().getAnnotation().getId());
AnnotationLayer layer = annotationService.getLayer(state.getProject(), fs);
TypeAdapter adapter = annotationService.getAdapter(layer);
if (layer.isReadonly()) {
error("Cannot delete an annotation on a read-only layer.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
if (checkAttachStatus(aTarget, state.getProject(), fs).readOnlyAttached) {
error("Cannot delete an annotation to which annotations on read-only layers attach.");
aTarget.addChildren(getPage(), IFeedback.class);
return;
}
deleteAnnotation(jCas, state, fs, layer, adapter);
// Store CAS again
writeEditorCas(jCas);
// Update progress information
int sentenceNumber = getSentenceNumber(jCas, state.getSelection().getBegin());
state.setFocusUnitIndex(sentenceNumber);
state.getDocument().setSentenceAccessed(sentenceNumber);
// Auto-scroll
if (state.getPreferences().isScrollPage()) {
autoScroll(jCas, false);
}
state.rememberFeatures();
info(generateMessage(state.getSelectedAnnotationLayer(), null, true));
state.getSelection().clear();
// after delete will follow annotation
aTarget.add(annotationFeatureForm);
onChange(aTarget);
onDelete(aTarget, fs);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationDetailEditorPanel method refresh.
private void refresh(AnnotatorState state) {
// This already happens in loadFeatureEditorModels() above - probably not needed
// here again
// annotationFeatureForm.updateLayersDropdown();
LOG.trace("actionAnnotate() setting selected layer (not sure why)");
if (annotationFeatureForm.getAnnotationLayers().isEmpty()) {
state.setSelectedAnnotationLayer(new AnnotationLayer());
} else if (state.getSelectedAnnotationLayer() == null) {
if (state.getRememberedSpanLayer() == null) {
state.setSelectedAnnotationLayer(annotationFeatureForm.getAnnotationLayers().get(0));
} else {
state.setSelectedAnnotationLayer(state.getRememberedSpanLayer());
}
}
LOG.trace("actionAnnotate() selectedLayer: {}", state.getSelectedAnnotationLayer().getUiName());
// Actually not sure why we would want to clear these here - in fact, they should
// still be around for the rendering phase of the feature editors...
// clearFeatureEditorModels(aTarget);
// This already happens in loadFeatureEditorModels() above - probably not needed
// here again
// annotationFeatureForm.updateRememberLayer();
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationDetailEditorPanel method actionCreateOrUpdate.
@Override
public void actionCreateOrUpdate(AjaxRequestTarget aTarget, JCas aJCas) throws IOException, AnnotationException {
LOG.trace("actionAnnotate");
if (isAnnotationFinished()) {
throw new AnnotationException("This document is already closed. Please ask your " + "project manager to re-open it via the Monitoring page");
}
AnnotatorState state = getModelObject();
// switches from the selected span layer to the relation layer that is attached to the span
if (state.getSelection().isArc()) {
LOG.trace("actionAnnotate() relation annotation - looking for attached layer");
// FIXME REC I think this whole section which meddles around with the selected
// annotation layer should be moved out of there to the place where we originally set
// the annotation layer...!
AnnotationFS originFS = selectByAddr(aJCas, state.getSelection().getOrigin());
AnnotationLayer spanLayer = annotationService.getLayer(state.getProject(), originFS);
if (state.getPreferences().isRememberLayer() && // i.e. new annotation
state.getSelection().getAnnotation().isNotSet() && !spanLayer.equals(state.getDefaultAnnotationLayer())) {
throw new AnnotationException("No relation annotation allowed on layer [" + state.getDefaultAnnotationLayer().getUiName() + "]");
}
AnnotationLayer previousLayer = state.getSelectedAnnotationLayer();
// Chain layers consist of arcs and spans
if (spanLayer.getType().equals(WebAnnoConst.CHAIN_TYPE)) {
// one layer both for the span and arc annotation
state.setSelectedAnnotationLayer(spanLayer);
} else // Otherwise, look up the possible relation layer(s) in the database.
{
for (AnnotationLayer l : annotationService.listAnnotationLayer(state.getProject())) {
if ((l.getAttachType() != null && l.getAttachType().equals(spanLayer)) || (l.getAttachFeature() != null && l.getAttachFeature().getType().equals(spanLayer.getName()))) {
if (state.getAnnotationLayers().contains(l)) {
state.setSelectedAnnotationLayer(l);
} else {
state.setSelectedAnnotationLayer(null);
}
break;
}
}
}
state.setDefaultAnnotationLayer(spanLayer);
// If we switched layers, we need to initialize the feature editors for the new layer
if (!Objects.equals(previousLayer, state.getSelectedAnnotationLayer())) {
LOG.trace("Layer changed from {} to {} - need to reload feature editors", previousLayer, state.getSelectedAnnotationLayer());
loadFeatureEditorModels(aJCas, aTarget);
}
} else {
// Re-set the selected layer from the drop-down since it might have changed if we
// have previously created a relation annotation
state.setSelectedAnnotationLayer(annotationFeatureForm.getLayerSelector().getModelObject());
}
internalCommitAnnotation(aTarget, aJCas);
internalCompleteAnnotation(aTarget, aJCas);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer 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 de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AnnotationFeatureForm method isForwardable.
private boolean isForwardable() {
AnnotatorState state = getModelObject();
AnnotationLayer selectedLayer = state.getSelectedAnnotationLayer();
if (isNull(selectedLayer) || isNull(selectedLayer.getId())) {
return false;
}
if (!selectedLayer.getType().equals(WebAnnoConst.SPAN_TYPE)) {
return false;
}
if (!selectedLayer.isLockToTokenOffset()) {
return false;
}
// which are are both enabled and visible).
if (getEnabledFeatures(selectedLayer).size() != 1) {
return false;
}
// we allow forward annotation only for a feature with a tagset
if (annotationService.listAnnotationFeature(selectedLayer).get(0).getTagset() != null) {
// there should be at least one tag in the tagset
TagSet tagSet = annotationService.listAnnotationFeature(selectedLayer).get(0).getTagset();
return !annotationService.listTags(tagSet).isEmpty();
}
// Or layers with a single visible/enabled free-text feature.
return true;
}
Aggregations