use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class AutomationUtil method loadDocument.
/**
* Repeat annotation will repeat annotations of same pattern to all documents on the project
* load CAS from document in case no initial CORRECTION_CAS is not created before
*/
public static void loadDocument(SourceDocument aDocument, AnnotationSchemaService annotationService, DocumentService aDocumentService, CorrectionDocumentService aCorrectionDocumentService, User logedInUser) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
JCas jCas = null;
if (!aCorrectionDocumentService.existsCorrectionCas(aDocument)) {
try {
AnnotationDocument logedInUserAnnotationDocument = aDocumentService.getAnnotationDocument(aDocument, logedInUser);
jCas = aDocumentService.readAnnotationCas(logedInUserAnnotationDocument);
annotationService.upgradeCas(jCas.getCas(), logedInUserAnnotationDocument);
aCorrectionDocumentService.writeCorrectionCas(jCas, aDocument);
} catch (DataRetrievalFailureException | NoResultException e) {
jCas = aDocumentService.readAnnotationCas(aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
// upgrade this cas
annotationService.upgradeCas(jCas.getCas(), aDocumentService.createOrGetAnnotationDocument(aDocument, logedInUser));
aCorrectionDocumentService.writeCorrectionCas(jCas, aDocument);
}
} else {
jCas = aCorrectionDocumentService.readCorrectionCas(aDocument);
// upgrade this automation cas
aCorrectionDocumentService.upgradeCorrectionCas(jCas.getCas(), aDocument);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class CorrectionPage method actionFinishDocument.
private void actionFinishDocument(AjaxRequestTarget aTarget) {
finishDocumentDialog.setConfirmAction((aCallbackTarget) -> {
ensureRequiredFeatureValuesSet(aCallbackTarget, getEditorCas());
AnnotatorState state = getModelObject();
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(state.getDocument(), state.getUser());
documentService.transitionAnnotationDocumentState(annotationDocument, ANNOTATION_IN_PROGRESS_TO_ANNOTATION_FINISHED);
aCallbackTarget.add(finishDocumentIcon);
aCallbackTarget.add(finishDocumentLink);
aCallbackTarget.add(detailEditor);
aCallbackTarget.add(createOrGetResetDocumentLink());
});
finishDocumentDialog.show(aTarget);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class CorrectionPage method getEditorCas.
@Override
protected JCas getEditorCas() throws IOException {
AnnotatorState state = getModelObject();
if (state.getDocument() == null) {
throw new IllegalStateException("Please open a document first!");
}
SourceDocument aDocument = getModelObject().getDocument();
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(aDocument, state.getUser());
// If there is no CAS yet for the annotation document, create one.
return documentService.readAnnotationCas(annotationDocument);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class AgreementPage method getJCases.
/**
* Get the finished CASes used to compute agreement.
*/
private Map<String, List<JCas>> getJCases() {
// Avoid reloading the CASes when switching features.
if (cachedCASes != null) {
return cachedCASes;
}
Project project = projectSelectionForm.getModelObject().project;
List<User> users = projectService.listProjectUsersWithPermissions(project, PermissionLevel.USER);
List<SourceDocument> sourceDocuments = documentService.listSourceDocuments(project);
cachedCASes = new LinkedHashMap<>();
for (User user : users) {
List<JCas> cases = new ArrayList<>();
for (SourceDocument document : sourceDocuments) {
JCas jCas = null;
// Load the CAS if there is a finished one.
if (documentService.existsAnnotationDocument(document, user)) {
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
try {
jCas = documentService.readAnnotationCas(annotationDocument);
annotationService.upgradeCas(jCas.getCas(), annotationDocument);
// REC: I think there is no need to write the CASes here. We would not
// want to interfere with currently active annotator users
// Set the CAS name in the DocumentMetaData so that we can pick it
// up in the Diff position for the purpose of debugging / transparency.
DocumentMetaData documentMetadata = DocumentMetaData.get(jCas);
documentMetadata.setDocumentId(annotationDocument.getDocument().getName());
documentMetadata.setCollectionId(annotationDocument.getProject().getName());
} catch (Exception e) {
LOG.error("Unable to load data", e);
error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
}
}
}
// The next line can enter null values into the list if a user didn't work on this
// source document yet.
cases.add(jCas);
}
cachedCASes.put(user.getUsername(), cases);
}
return cachedCASes;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument in project webanno by webanno.
the class MonitoringPage method getPercentageOfFinishedDocumentsPerUser.
private Map<String, Integer> getPercentageOfFinishedDocumentsPerUser(Project aProject) {
Map<String, Integer> annotatorsProgress = new HashMap<>();
if (aProject != null) {
for (User user : projectService.listProjectUsersWithPermissions(aProject, PermissionLevel.USER)) {
int finished = 0;
int ignored = 0;
int totalDocs = 0;
List<SourceDocument> documents = documentService.listSourceDocuments(aProject);
for (SourceDocument document : documents) {
totalDocs++;
if (documentService.isAnnotationFinished(document, user)) {
finished++;
} else if (documentService.existsAnnotationDocument(document, user)) {
AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
if (annotationDocument.getState().equals(AnnotationDocumentState.IGNORE)) {
ignored++;
}
}
}
annotatorsProgress.put(user.getUsername(), (int) Math.round((double) (finished * 100) / (totalDocs - ignored)));
}
}
return annotatorsProgress;
}
Aggregations