use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CurationPage method actionCompletePreferencesChange.
private void actionCompletePreferencesChange(AjaxRequestTarget aTarget) {
AnnotatorState state = CurationPage.this.getModelObject();
// Re-render the whole page because the width of the sidebar may have changed
aTarget.add(CurationPage.this);
aTarget.add(getOrCreatePositionInfoLabel());
JCas mergeCas = null;
try {
aTarget.add(getFeedbackPanel());
mergeCas = curationDocumentService.readCurationCas(state.getDocument());
// The number of visible sentences may have changed - let the state recalculate
// the visible sentences
Sentence sentence = selectByAddr(mergeCas, Sentence.class, state.getFirstVisibleUnitAddress());
state.setFirstVisibleUnit(sentence);
curationPanel.updatePanel(aTarget, curationContainer);
updatePanel(curationContainer, aTarget);
updateSentenceNumber(mergeCas, state.getFirstVisibleUnitAddress());
} catch (Exception e) {
handleException(aTarget, e);
}
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CurationPage method updateSentenceNumber.
private void updateSentenceNumber(JCas aJCas, int aAddress) {
AnnotatorState state = getModelObject();
Sentence sentence = selectByAddr(aJCas, Sentence.class, aAddress);
state.setFirstVisibleUnit(sentence);
state.setFocusUnitIndex(WebAnnoCasUtil.getSentenceNumber(aJCas, sentence.getBegin()));
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CorrectionPage method actionGotoPage.
private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
AnnotatorState state = getModelObject();
JCas editorCas = getEditorCas();
List<Sentence> sentences = new ArrayList<>(select(editorCas, Sentence.class));
int selectedSentence = gotoPageTextField.getModelObject();
selectedSentence = Math.min(selectedSentence, sentences.size());
gotoPageTextField.setModelObject(selectedSentence);
state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
state.setFocusUnitIndex(selectedSentence);
SuggestionBuilder builder = new SuggestionBuilder(casStorageService, documentService, correctionDocumentService, curationDocumentService, annotationService, userRepository);
curationContainer = builder.buildCurationContainer(state);
setCurationSegmentBeginEnd(editorCas);
curationContainer.setBratAnnotatorModel(state);
update(aTarget);
aTarget.add(gotoPageTextField);
annotationEditor.requestRender(aTarget);
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CurationPanel method commonUpdate.
private void commonUpdate() throws IOException {
JCas jCas = curationDocumentService.readCurationCas(state.getDocument());
// Determine the FIRST visible unit
final Sentence firstVisibleUnit = selectSentenceAt(jCas, state.getFirstVisibleUnitBegin(), state.getFirstVisibleUnitEnd());
state.setFirstVisibleUnit(firstVisibleUnit);
// Determine the LAST visible unit
List<Sentence> followingUnits = selectFollowing(jCas, Sentence.class, firstVisibleUnit, state.getPreferences().getWindowSize());
// Check also, when getting the last sentence address in the display window, if this is the
// last sentence or the ONLY sentence in the document
Sentence lastVisibleUnit = followingUnits.size() == 0 ? firstVisibleUnit : followingUnits.get(followingUnits.size() - 1);
curationView.setCurationBegin(firstVisibleUnit.getBegin());
curationView.setCurationEnd(lastVisibleUnit.getEnd());
// Determine the number of the first and last visible unit
int ws = state.getPreferences().getWindowSize();
Sentence fs = WebAnnoCasUtil.selectSentenceAt(jCas, state.getFirstVisibleUnitBegin(), state.getFirstVisibleUnitEnd());
Sentence ls = WebAnnoCasUtil.getLastSentenceInDisplayWindow(jCas, getAddr(fs), ws);
fSn = WebAnnoCasUtil.getSentenceNumber(jCas, fs.getBegin());
lSn = WebAnnoCasUtil.getSentenceNumber(jCas, ls.getBegin());
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class SuggestionBuilder method buildCurationContainer.
public CurationContainer buildCurationContainer(AnnotatorState aBModel) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
CurationContainer curationContainer = new CurationContainer();
// initialize Variables
SourceDocument sourceDocument = aBModel.getDocument();
Map<Integer, Integer> segmentBeginEnd = new HashMap<>();
Map<Integer, Integer> segmentNumber = new HashMap<>();
Map<String, Map<Integer, Integer>> segmentAdress = new HashMap<>();
// get annotation documents
List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(aBModel.getDocument())) {
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
finishedAnnotationDocuments.add(annotationDocument);
}
}
Map<String, JCas> jCases = new HashMap<>();
AnnotationDocument randomAnnotationDocument = null;
JCas mergeJCas;
// get the correction/automation JCas for the logged in user
if (aBModel.getMode().equals(Mode.AUTOMATION) || aBModel.getMode().equals(Mode.CORRECTION)) {
jCases = listJcasesforCorrection(randomAnnotationDocument, sourceDocument, aBModel.getMode());
mergeJCas = getMergeCas(aBModel, sourceDocument, jCases, randomAnnotationDocument, false);
String username = jCases.keySet().iterator().next();
updateSegment(aBModel, segmentBeginEnd, segmentNumber, segmentAdress, jCases.get(username), username, aBModel.getWindowBeginOffset(), aBModel.getWindowEndOffset());
} else {
jCases = listJcasesforCuration(finishedAnnotationDocuments, randomAnnotationDocument, aBModel.getMode());
mergeJCas = getMergeCas(aBModel, sourceDocument, jCases, randomAnnotationDocument, false);
updateSegment(aBModel, segmentBeginEnd, segmentNumber, segmentAdress, mergeJCas, WebAnnoConst.CURATION_USER, WebAnnoCasUtil.getFirstSentence(mergeJCas).getBegin(), mergeJCas.getDocumentText().length());
}
List<Type> entryTypes = null;
segmentAdress.put(WebAnnoConst.CURATION_USER, new HashMap<>());
for (Sentence sentence : selectCovered(mergeJCas, Sentence.class, diffRangeBegin, diffRangeEnd)) {
segmentAdress.get(WebAnnoConst.CURATION_USER).put(sentence.getBegin(), getAddr(sentence));
}
if (entryTypes == null) {
entryTypes = getEntryTypes(mergeJCas, aBModel.getAnnotationLayers(), annotationService);
}
// for cross-sentences annotation, update the end of the segment
if (firstload) {
long start = System.currentTimeMillis();
log.debug("Updating cross sentence annotation list...");
updateCrossSentAnnoList(segmentBeginEnd, segmentNumber, jCases, entryTypes);
firstload = false;
log.debug("Cross sentence annotation list complete in {}ms", (System.currentTimeMillis() - start));
}
long diffStart = System.currentTimeMillis();
log.debug("Calculating differences...");
int count = 0;
for (Integer begin : segmentBeginEnd.keySet()) {
Integer end = segmentBeginEnd.get(begin);
count++;
if (count % 100 == 0) {
log.debug("Processing differences: {} of {} sentences...", count, segmentBeginEnd.size());
}
DiffResult diff = CasDiff2.doDiffSingle(annotationService, aBModel.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, begin, end);
SourceListView curationSegment = new SourceListView();
curationSegment.setBegin(begin);
curationSegment.setEnd(end);
curationSegment.setSentenceNumber(segmentNumber.get(begin));
if (diff.hasDifferences() || !diff.getIncompleteConfigurationSets().isEmpty()) {
// Is this confSet a diff due to stacked annotations (with same configuration)?
boolean stackedDiff = false;
stackedDiffSet: for (ConfigurationSet d : diff.getDifferingConfigurationSets().values()) {
for (Configuration c : d.getConfigurations()) {
if (c.getCasGroupIds().size() != d.getCasGroupIds().size()) {
stackedDiff = true;
break stackedDiffSet;
}
}
}
if (stackedDiff) {
curationSegment.setSentenceState(SentenceState.DISAGREE);
} else if (!diff.getIncompleteConfigurationSets().isEmpty()) {
curationSegment.setSentenceState(SentenceState.DISAGREE);
} else {
curationSegment.setSentenceState(SentenceState.AGREE);
}
} else {
curationSegment.setSentenceState(SentenceState.AGREE);
}
for (String username : segmentAdress.keySet()) {
curationSegment.getSentenceAddress().put(username, segmentAdress.get(username).get(begin));
}
curationContainer.getCurationViewByBegin().put(begin, curationSegment);
}
log.debug("Difference calculation completed in {}ms", (System.currentTimeMillis() - diffStart));
return curationContainer;
}
Aggregations