use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class AutomationPage 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 AutomationUtil method deleteSpanAnnotation.
public static void deleteSpanAnnotation(AnnotatorState aBModel, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, int aStart, int aEnd, AnnotationFeature aFeature, String aValue) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
AnnotationDocument annoDoc = aDocumentService.getAnnotationDocument(aBModel.getDocument(), aBModel.getUser());
JCas annoCas = aDocumentService.readAnnotationCas(annoDoc);
// get selected text, concatenations of tokens
String selectedText = WebAnnoCasUtil.getSelectedText(annoCas, aStart, aEnd);
for (SourceDocument d : aDocumentService.listSourceDocuments(aBModel.getProject())) {
loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aBModel.getUser());
JCas jCas = aCorrectionDocumentService.readCorrectionCas(d);
AutomationTypeAdapter adapter = (AutomationTypeAdapter) aAnnotationService.getAdapter(aFeature.getLayer());
for (Sentence sentence : select(jCas, Sentence.class)) {
String sentenceText = sentence.getCoveredText().toLowerCase();
for (int i = -1; (i = sentenceText.indexOf(selectedText.toLowerCase(), i)) != -1; i = i + selectedText.length()) {
if (selectCovered(jCas, Token.class, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length()).size() > 0) {
adapter.delete(aBModel, jCas, aFeature, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length() - 1, aValue);
}
}
}
aCorrectionDocumentService.writeCorrectionCas(jCas, d);
}
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class AutomationUtil method addOtherFeatureTrainDocument.
// generates training document that will be used to predict the training document
// to add extra features, for example add POS tag as a feature for NE classifier
public static void addOtherFeatureTrainDocument(MiraTemplate aTemplate, AnnotationSchemaService aAnnotationService, AutomationService aAutomationService, UserDao aUserDao) throws IOException, UIMAException, ClassNotFoundException {
File miraDir = aAutomationService.getMiraDir(aTemplate.getTrainFeature());
if (!miraDir.exists()) {
FileUtils.forceMkdir(miraDir);
}
AutomationStatus status = aAutomationService.getAutomationStatus(aTemplate);
for (AnnotationFeature feature : aTemplate.getOtherFeatures()) {
File trainFile = new File(miraDir, feature.getId() + ".train");
boolean documentChanged = false;
for (TrainingDocument document : aAutomationService.listTrainingDocuments(feature.getProject())) {
if (!document.isProcessed() && (document.getFeature() != null && document.getFeature().equals(feature))) {
documentChanged = true;
break;
}
}
if (!documentChanged && trainFile.exists()) {
continue;
}
BufferedWriter trainOut = new BufferedWriter(new FileWriter(trainFile));
AutomationTypeAdapter adapter = (AutomationTypeAdapter) aAnnotationService.getAdapter(feature.getLayer());
for (TrainingDocument trainingDocument : aAutomationService.listTrainingDocuments(feature.getProject())) {
if ((trainingDocument.getFeature() != null && trainingDocument.getFeature().equals(feature))) {
JCas jCas = aAutomationService.readTrainingAnnotationCas(trainingDocument);
for (Sentence sentence : select(jCas, Sentence.class)) {
trainOut.append(getMiraLine(sentence, feature, adapter).toString()).append("\n");
}
trainingDocument.setProcessed(false);
status.setTrainDocs(status.getTrainDocs() - 1);
}
}
trainOut.close();
}
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class AutomationUtil method repeateSpanAnnotation.
public static void repeateSpanAnnotation(AnnotatorState aState, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, AnnotationSchemaService aAnnotationService, int aStart, int aEnd, AnnotationFeature aFeature, String aValue) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
AnnotationDocument annoDoc = aDocumentService.getAnnotationDocument(aState.getDocument(), aState.getUser());
JCas annoCas = aDocumentService.readAnnotationCas(annoDoc);
// get selected text, concatenations of tokens
String selectedText = WebAnnoCasUtil.getSelectedText(annoCas, aStart, aEnd);
SpanAdapter adapter = (SpanAdapter) aAnnotationService.getAdapter(aFeature.getLayer());
for (SourceDocument d : aDocumentService.listSourceDocuments(aState.getProject())) {
loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aState.getUser());
JCas jCas = aCorrectionDocumentService.readCorrectionCas(d);
for (Sentence sentence : select(jCas, Sentence.class)) {
String sentenceText = sentence.getCoveredText().toLowerCase();
for (int i = -1; (i = sentenceText.indexOf(selectedText.toLowerCase(), i)) != -1; i = i + selectedText.length()) {
if (selectCovered(jCas, Token.class, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length()).size() > 0) {
int addr = adapter.add(aState, jCas, sentence.getBegin() + i, sentence.getBegin() + i + selectedText.length() - 1);
adapter.setFeatureValue(aState, jCas, addr, aFeature, aValue);
}
}
}
aCorrectionDocumentService.writeCorrectionCas(jCas, d);
}
}
use of de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence in project webanno by webanno.
the class AnnotationSidebar_ImplBase method actionShowSelectedDocumentByTokenPosition.
/**
* Show the next document if it exists, starting in a certain token position
*/
@Deprecated
protected void actionShowSelectedDocumentByTokenPosition(AjaxRequestTarget aTarget, SourceDocument aDocument, int aTokenNumber) throws IOException {
annotationPage.actionShowSelectedDocument(aTarget, aDocument);
AnnotatorState state = getModelObject();
JCas jCas = annotationPage.getEditorCas();
Collection<Token> tokenCollection = JCasUtil.select(jCas, Token.class);
Token[] tokens = tokenCollection.toArray(new Token[tokenCollection.size()]);
int sentenceNumber = WebAnnoCasUtil.getSentenceNumber(jCas, tokens[aTokenNumber].getBegin());
Sentence sentence = WebAnnoCasUtil.getSentence(jCas, tokens[aTokenNumber].getBegin());
annotationPage.getGotoPageTextField().setModelObject(sentenceNumber);
state.setFirstVisibleUnit(sentence);
state.setFocusUnitIndex(sentenceNumber);
annotationPage.actionRefreshDocument(aTarget);
}
Aggregations