use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class AutomationPage method createDetailEditor.
private AnnotationDetailEditorPanel createDetailEditor() {
return new AnnotationDetailEditorPanel("annotationDetailEditorPanel", getModel()) {
private static final long serialVersionUID = 2857345299480098279L;
@Override
protected void onChange(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
aTarget.addChildren(getPage(), IFeedback.class);
try {
annotationEditor.requestRender(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
return;
}
try {
SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
curationContainer = builder.buildCurationContainer(state);
setCurationSegmentBeginEnd(getEditorCas());
curationContainer.setBratAnnotatorModel(state);
suggestionView.updatePanel(aTarget, curationContainer, annotationSelectionByUsernameAndAddress, curationSegment);
update(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
@Override
public void onAnnotate(AjaxRequestTarget aTarget) {
AnnotatorState state = getModelObject();
if (state.isForwardAnnotation()) {
return;
}
AnnotationLayer layer = state.getSelectedAnnotationLayer();
int address = state.getSelection().getAnnotation().getId();
try {
JCas jCas = getEditorCas();
AnnotationFS fs = selectByAddr(jCas, address);
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
Type type = CasUtil.getType(fs.getCAS(), layer.getName());
Feature feat = type.getFeatureByBaseName(f.getName());
if (!automationService.existsMiraTemplate(f)) {
continue;
}
if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
continue;
}
TagSet tagSet = f.getTagset();
boolean isRepeatable = false;
// repeat only if the value is in the tagset
for (Tag tag : annotationService.listTags(tagSet)) {
if (fs.getFeatureValueAsString(feat) == null) {
// this is new annotation without values
break;
}
if (fs.getFeatureValueAsString(feat).equals(tag.getName())) {
isRepeatable = true;
break;
}
}
if (automationService.getMiraTemplate(f) != null && isRepeatable) {
if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
AutomationUtil.repeateRelationAnnotation(state, documentService, correctionDocumentService, annotationService, fs, f, fs.getFeatureValueAsString(feat));
update(aTarget);
break;
} else if (layer.getType().endsWith(WebAnnoConst.SPAN_TYPE)) {
AutomationUtil.repeateSpanAnnotation(state, documentService, correctionDocumentService, annotationService, fs.getBegin(), fs.getEnd(), f, fs.getFeatureValueAsString(feat));
update(aTarget);
break;
}
}
}
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
@Override
protected void onAutoForward(AjaxRequestTarget aTarget) {
annotationEditor.requestRender(aTarget);
}
@Override
public void onDelete(AjaxRequestTarget aTarget, AnnotationFS aFS) {
AnnotatorState state = getModelObject();
AnnotationLayer layer = state.getSelectedAnnotationLayer();
for (AnnotationFeature f : annotationService.listAnnotationFeature(layer)) {
if (!automationService.existsMiraTemplate(f)) {
continue;
}
if (!automationService.getMiraTemplate(f).isAnnotateAndRepeat()) {
continue;
}
try {
Type type = CasUtil.getType(aFS.getCAS(), layer.getName());
Feature feat = type.getFeatureByBaseName(f.getName());
if (layer.getType().endsWith(WebAnnoConst.RELATION_TYPE)) {
AutomationUtil.deleteRelationAnnotation(state, documentService, correctionDocumentService, annotationService, aFS, f, aFS.getFeatureValueAsString(feat));
} else {
AutomationUtil.deleteSpanAnnotation(state, documentService, correctionDocumentService, annotationService, aFS.getBegin(), aFS.getEnd(), f, aFS.getFeatureValueAsString(feat));
}
update(aTarget);
} catch (Exception e) {
handleException(this, aTarget, e);
}
}
}
};
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class MergeCas method addArcAnnotation.
public static void addArcAnnotation(TypeAdapter aAdapter, JCas aJcas, int aAddressOriginClicked, int aAddressTargetClicked, String aFSArcaddress, JCas aClickedJCas, AnnotationFS aClickedFS) throws AnnotationException {
AnnotationFS originFsClicked = selectByAddr(aClickedJCas, aAddressOriginClicked);
AnnotationFS targetFsClicked = selectByAddr(aClickedJCas, aAddressTargetClicked);
// this is a slot arc
if (aFSArcaddress.contains(".")) {
addSlotArcAnnotation((SpanAdapter) aAdapter, aJcas, aFSArcaddress, aClickedJCas, aClickedFS);
} else // normal relation annotation arc is clicked
{
AnnotationLayer layer = aAdapter.getLayer();
addRelationArcAnnotation(aJcas, aClickedFS, layer.getAttachType() != null, layer.isAllowStacking(), originFsClicked, targetFsClicked);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class SuggestionViewPanel method mergeArc.
private void mergeArc(IRequestParameters aRequest, UserAnnotationSegment aCurationUserSegment, JCas aJcas) throws AnnotationException, IOException, UIMAException, ClassNotFoundException {
int addressOriginClicked = aRequest.getParameterValue(PARAM_ORIGIN_SPAN_ID).toInt();
int addressTargetClicked = aRequest.getParameterValue(PARAM_TARGET_SPAN_ID).toInt();
String arcType = removePrefix(aRequest.getParameterValue(PARAM_TYPE).toString());
String fsArcaddress = aRequest.getParameterValue(PARAM_ARC_ID).toString();
AnnotatorState bModel = aCurationUserSegment.getAnnotatorState();
SourceDocument sourceDocument = bModel.getDocument();
// for correction and automation, the lower panel is the clickedJcase, from the suggestions
JCas clickedJCas;
if (!aCurationUserSegment.getAnnotatorState().getMode().equals(Mode.CURATION)) {
clickedJCas = correctionDocumentService.readCorrectionCas(sourceDocument);
} else {
User user = userRepository.get(aCurationUserSegment.getUsername());
AnnotationDocument clickedAnnotationDocument = documentService.getAnnotationDocument(sourceDocument, user);
clickedJCas = getJCas(bModel, clickedAnnotationDocument);
}
long layerId = TypeUtil.getLayerId(arcType);
AnnotationLayer layer = annotationService.getLayer(layerId);
TypeAdapter adapter = annotationService.getAdapter(layer);
int address = Integer.parseInt(fsArcaddress.split("\\.")[0]);
AnnotationFS clickedFS = selectByAddr(clickedJCas, address);
if (isCorefType(clickedFS)) {
throw new AnnotationException(" Coreference Annotation not supported in curation");
}
MergeCas.addArcAnnotation(adapter, aJcas, addressOriginClicked, addressTargetClicked, fsArcaddress, clickedJCas, clickedFS);
writeEditorCas(bModel, aJcas);
int sentenceNumber = getSentenceNumber(clickedJCas, clickedFS.getBegin());
bModel.setFocusUnitIndex(sentenceNumber);
// Update timestamp
bModel.getDocument().setSentenceAccessed(sentenceNumber);
if (bModel.getPreferences().isScrollPage()) {
Sentence sentence = selectSentenceAt(aJcas, bModel.getFirstVisibleUnitBegin(), bModel.getFirstVisibleUnitEnd());
sentence = findWindowStartCenteringOnSelection(aJcas, sentence, clickedFS.getBegin(), bModel.getProject(), bModel.getDocument(), bModel.getPreferences().getWindowSize());
bModel.setFirstVisibleUnit(sentence);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class SuggestionViewPanel method addSuggestionColor.
/**
* For each {@link ConfigurationSet}, where there are some differences in users annotation and
* the curation annotation.
*/
private void addSuggestionColor(Project aProject, Mode aMode, Map<String, JCas> aCasMap, Map<String, Map<VID, AnnotationState>> aSuggestionColors, Collection<ConfigurationSet> aCfgSet, boolean aI, boolean aAgree) {
for (ConfigurationSet cs : aCfgSet) {
boolean use = false;
for (String u : cs.getCasGroupIds()) {
Map<VID, AnnotationState> colors = aSuggestionColors.get(u);
if (colors == null) {
colors = new HashMap<>();
aSuggestionColors.put(u, colors);
}
for (Configuration c : cs.getConfigurations(u)) {
FeatureStructure fs = c.getFs(u, aCasMap);
AnnotationLayer layer = annotationService.getLayer(fs.getType().getName(), aProject);
TypeAdapter typeAdapter = annotationService.getAdapter(layer);
VID vid;
// link FS
if (c.getPosition().getFeature() != null) {
int fi = 0;
for (AnnotationFeature f : typeAdapter.listFeatures()) {
if (f.getName().equals(c.getPosition().getFeature())) {
break;
}
fi++;
}
vid = new VID(WebAnnoCasUtil.getAddr(fs), fi, c.getAID(u).index);
} else {
vid = new VID(WebAnnoCasUtil.getAddr(fs));
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
continue;
}
// automation and correction projects
if (!aMode.equals(Mode.CURATION) && !aAgree) {
if (cs.getCasGroupIds().size() == 2) {
colors.put(vid, AnnotationState.DO_NOT_USE);
} else {
colors.put(vid, AnnotationState.DISAGREE);
}
continue;
}
// this set agree with the curation annotation
if (c.getCasGroupIds().contains(CURATION_USER)) {
use = true;
} else {
use = false;
}
// this curation view
if (u.equals(CURATION_USER)) {
continue;
}
if (aAgree) {
colors.put(vid, AnnotationState.AGREE);
} else if (use) {
colors.put(vid, AnnotationState.USE);
} else if (aI) {
colors.put(vid, AnnotationState.DISAGREE);
} else if (!cs.getCasGroupIds().contains(CURATION_USER)) {
colors.put(vid, AnnotationState.DISAGREE);
} else {
colors.put(vid, AnnotationState.DO_NOT_USE);
}
}
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.
the class SuggestionViewPanel method createSpan.
private void createSpan(String spanType, AnnotatorState aBModel, JCas aMergeJCas, AnnotationDocument aAnnotationDocument, int aAddress) throws IOException, UIMAException, ClassNotFoundException, AnnotationException {
JCas clickedJCas = getJCas(aBModel, aAnnotationDocument);
AnnotationFS fsClicked = selectByAddr(clickedJCas, aAddress);
if (isCorefType(fsClicked)) {
throw new AnnotationException("Coreference Annotation not supported in curation");
}
long layerId = TypeUtil.getLayerId(spanType);
AnnotationLayer layer = annotationService.getLayer(layerId);
MergeCas.addSpanAnnotation(aBModel, annotationService, layer, aMergeJCas, fsClicked, layer.isAllowStacking());
writeEditorCas(aBModel, aMergeJCas);
// update timestamp
int sentenceNumber = getSentenceNumber(clickedJCas, fsClicked.getBegin());
aBModel.setFocusUnitIndex(sentenceNumber);
aBModel.getDocument().setSentenceAccessed(sentenceNumber);
if (aBModel.getPreferences().isScrollPage()) {
Sentence sentence = selectSentenceAt(aMergeJCas, aBModel.getFirstVisibleUnitBegin(), aBModel.getFirstVisibleUnitEnd());
sentence = findWindowStartCenteringOnSelection(aMergeJCas, sentence, fsClicked.getBegin(), aBModel.getProject(), aBModel.getDocument(), aBModel.getPreferences().getWindowSize());
aBModel.setFirstVisibleUnit(sentence);
}
}
Aggregations