use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CurationPage method actionGotoPage.
private void actionGotoPage(AjaxRequestTarget aTarget, Form<?> aForm) throws Exception {
AnnotatorState state = getModelObject();
JCas jcas = getEditorCas();
List<Sentence> sentences = new ArrayList<>(select(jcas, Sentence.class));
int selectedSentence = gotoPageTextField.getModelObject();
selectedSentence = Math.min(selectedSentence, sentences.size());
gotoPageTextField.setModelObject(selectedSentence);
state.setFirstVisibleUnit(sentences.get(selectedSentence - 1));
state.setFocusUnitIndex(selectedSentence);
actionRefreshDocument(aTarget);
curationPanel.updatePanel(aTarget, curationContainer);
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class CurationPanel method updateCurationView.
private void updateCurationView(final CurationContainer curationContainer, final SourceListView curationViewItem, AjaxRequestTarget aTarget, JCas jCas) {
Sentence currentSent = WebAnnoCasUtil.getCurrentSentence(jCas, curationViewItem.getBegin(), curationViewItem.getEnd());
state.setFirstVisibleUnit(WebAnnoCasUtil.findWindowStartCenteringOnSelection(jCas, currentSent, curationViewItem.getBegin(), state.getProject(), state.getDocument(), state.getPreferences().getWindowSize()));
curationContainer.setBratAnnotatorModel(state);
onChange(aTarget);
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence 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.dkpro.core.api.segmentation.type.Sentence 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);
}
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class SuggestionBuilder method getSentenceByAnnoEnd.
/**
* Get a sentence at the end of an annotation
*/
private static Sentence getSentenceByAnnoEnd(List<Sentence> aSentences, int aEnd) {
int prevEnd = 0;
Sentence sent = null;
for (Sentence sentence : aSentences) {
if (prevEnd >= aEnd) {
return sent;
}
sent = sentence;
prevEnd = sent.getEnd();
}
return sent;
}
Aggregations