Skip to content

Commit

Permalink
#1185 - Relax from AnnotationFS to FeatureStructure when dealing with…
Browse files Browse the repository at this point in the history
… feature value

- Switch to FeatureStructure where possible
- Also move writing editor JCas code from ADEP to AnnotationPageBase to be more easily accessible and to be at the same place as the getEditorCas() method
  • Loading branch information
reckart committed Jan 10, 2019
1 parent 5f8d884 commit 839b49c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 42 deletions.
Expand Up @@ -81,7 +81,7 @@ public Collection<AnnotationFeature> listFeatures()
public void setFeatureValue(SourceDocument aDocument, String aUsername, JCas aJcas,
int aAddress, AnnotationFeature aFeature, Object aValue)
{
FeatureStructure fs = selectByAddr(aJcas, aAddress);
FeatureStructure fs = selectByAddr(aJcas, FeatureStructure.class, aAddress);

Object oldValue = getValue(fs, aFeature);

Expand Down
Expand Up @@ -26,7 +26,6 @@
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.fit.util.FSUtil;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.metadata.TypeDescription;
Expand Down Expand Up @@ -218,7 +217,7 @@ FeatureEditor createEditor(String aId, MarkupContainer aOwner, AnnotationActionH
* the feature structure from which to obtain the label.
* @return the UI label.
*/
default String renderFeatureValue(AnnotationFeature aFeature, AnnotationFS aFs)
default String renderFeatureValue(AnnotationFeature aFeature, FeatureStructure aFs)
{
Feature labelFeature = aFs.getType().getFeatureByBaseName(aFeature.getName());
return renderFeatureValue(aFeature, aFs.getFeatureValueAsString(labelFeature));
Expand Down
Expand Up @@ -25,6 +25,7 @@
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.uima.cas.FeatureStructure;
import org.apache.uima.cas.text.AnnotationFS;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
Expand Down Expand Up @@ -66,7 +67,7 @@ public class VID
private final int slot;
private final String extensionId;

public VID(AnnotationFS aFS)
public VID(FeatureStructure aFS)
{
this(null, getAddr(aFS), NONE, NONE, NONE);
}
Expand Down
Expand Up @@ -62,7 +62,7 @@ void render(JCas aJcas, List<AnnotationFeature> aFeatures, VDocument aBuffer,

FeatureSupportRegistry getFeatureSupportRegistry();

default Map<String, String> getFeatures(TypeAdapter aAdapter, AnnotationFS aFs,
default Map<String, String> getFeatures(TypeAdapter aAdapter, FeatureStructure aFs,
List<AnnotationFeature> aFeatures)
{
FeatureSupportRegistry fsr = getFeatureSupportRegistry();
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.uima.cas.CAS;
Expand All @@ -47,8 +48,10 @@
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState;
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.preferences.UserPreferencesService;
import de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil;
import de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.model.Mode;
import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument;
import de.tudarmstadt.ukp.clarin.webanno.support.dialog.ChallengeResponseDialog;
import de.tudarmstadt.ukp.clarin.webanno.support.lambda.ActionBarLink;
Expand All @@ -65,6 +68,7 @@ public abstract class AnnotationPageBase

private @SpringBean AnnotationSchemaService annotationService;
private @SpringBean DocumentService documentService;
private @SpringBean CurationDocumentService curationDocumentService;
private @SpringBean UserPreferencesService userPreferenceService;

private ChallengeResponseDialog resetDocumentDialog;
Expand Down Expand Up @@ -307,9 +311,34 @@ protected void handleException(AjaxRequestTarget aTarget, Exception aException)

protected abstract List<SourceDocument> getListOfDocs();

protected abstract JCas getEditorCas()
throws IOException;

protected abstract JCas getEditorCas() throws IOException;

public void writeEditorCas(JCas aJCas) throws IOException
{
AnnotatorState state = getModelObject();
if (state.getMode().equals(Mode.ANNOTATION) || state.getMode().equals(Mode.AUTOMATION)
|| state.getMode().equals(Mode.CORRECTION)) {
documentService.writeAnnotationCas(aJCas, state.getDocument(), state.getUser(), true);

// Update timestamp in state
Optional<Long> diskTimestamp = documentService
.getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername());
if (diskTimestamp.isPresent()) {
state.setAnnotationDocumentTimestamp(diskTimestamp.get());
}
}
else if (state.getMode().equals(Mode.CURATION)) {
curationDocumentService.writeCurationCas(aJCas, state.getDocument(), true);

// Update timestamp in state
Optional<Long> diskTimestamp = curationDocumentService
.getCurationCasTimestamp(state.getDocument());
if (diskTimestamp.isPresent()) {
state.setAnnotationDocumentTimestamp(diskTimestamp.get());
}
}
}

/**
* Open a document or to a different document. This method should be used only the first time
* that a document is accessed. It reset the annotator state and upgrades the CAS.
Expand Down
Expand Up @@ -33,7 +33,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import javax.persistence.NoResultException;
Expand Down Expand Up @@ -81,7 +80,6 @@
import de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue;
import de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.RulesIndicator;
import de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator;
import de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature;
import de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer;
import de.tudarmstadt.ukp.clarin.webanno.model.LinkMode;
Expand All @@ -104,7 +102,6 @@ public abstract class AnnotationDetailEditorPanel

private @SpringBean ProjectService projectService;
private @SpringBean DocumentService documentService;
private @SpringBean CurationDocumentService curationDocumentService;
private @SpringBean AnnotationSchemaService annotationService;
private @SpringBean AnnotationEditorExtensionRegistry extensionRegistry;

Expand Down Expand Up @@ -653,7 +650,7 @@ private void internalCommitAnnotation(AjaxRequestTarget aTarget, JCas aJCas)
state.getDocument().setSentenceAccessed(sentenceNumber);

// persist changes
writeEditorCas(aJCas);
page.writeEditorCas(aJCas);

// Remember the current feature values independently for spans and relations
LOG.trace("actionAnnotate() remembering feature editor values");
Expand Down Expand Up @@ -738,7 +735,7 @@ public void actionDelete(AjaxRequestTarget aTarget)
deleteAnnotation(jCas, state, fs, layer, adapter);

// Store CAS again
writeEditorCas(jCas);
page.writeEditorCas(jCas);

// Update progress information
int sentenceNumber = getSentenceNumber(jCas, state.getSelection().getBegin());
Expand Down Expand Up @@ -884,7 +881,7 @@ public void actionReverse(AjaxRequestTarget aTarget)
}

// persist changes
writeEditorCas(jCas);
page.writeEditorCas(jCas);
int sentenceNumber = getSentenceNumber(jCas, originFs.getBegin());
state.setFocusUnitIndex(sentenceNumber);
state.getDocument().setSentenceAccessed(sentenceNumber);
Expand Down Expand Up @@ -912,33 +909,6 @@ public void actionClear(AjaxRequestTarget aTarget)
onChange(aTarget);
}

private void writeEditorCas(JCas aJCas)
throws IOException
{
AnnotatorState state = getModelObject();
if (state.getMode().equals(Mode.ANNOTATION) || state.getMode().equals(Mode.AUTOMATION)
|| state.getMode().equals(Mode.CORRECTION)) {
documentService.writeAnnotationCas(aJCas, state.getDocument(), state.getUser(), true);

// Update timestamp in state
Optional<Long> diskTimestamp = documentService
.getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername());
if (diskTimestamp.isPresent()) {
state.setAnnotationDocumentTimestamp(diskTimestamp.get());
}
}
else if (state.getMode().equals(Mode.CURATION)) {
curationDocumentService.writeCurationCas(aJCas, state.getDocument(), true);

// Update timestamp in state
Optional<Long> diskTimestamp = curationDocumentService
.getCurationCasTimestamp(state.getDocument());
if (diskTimestamp.isPresent()) {
state.setAnnotationDocumentTimestamp(diskTimestamp.get());
}
}
}

/**
* Scroll the window of visible annotations.
* @param aForward
Expand Down
Expand Up @@ -42,7 +42,6 @@ class UserSelectionPanel
public UserSelectionPanel(String id, IModel<User> aModel)
{
super(id);
setOutputMarkupId(true);
setOutputMarkupPlaceholderTag(true);

overviewList = new OverviewListChoice<>("user");
Expand Down

0 comments on commit 839b49c

Please sign in to comment.