use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument 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.SourceDocument 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.SourceDocument 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;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class DocumentServiceImpl method listAnnotatableDocuments.
@Override
public Map<SourceDocument, AnnotationDocument> listAnnotatableDocuments(Project aProject, User aUser) {
// First get the source documents
List<SourceDocument> sourceDocuments = entityManager.createQuery("FROM SourceDocument " + "WHERE project = (:project)", SourceDocument.class).setParameter("project", aProject).getResultList();
// Next we get all the annotation document records. We can use these to filter out
// documents which are IGNOREed for given users.
List<AnnotationDocument> annotationDocuments = entityManager.createQuery("FROM AnnotationDocument " + "WHERE user = (:username) AND project = (:project)", AnnotationDocument.class).setParameter("username", aUser.getUsername()).setParameter("project", aProject).getResultList();
// First we add all the source documents
Map<SourceDocument, AnnotationDocument> map = new TreeMap<>(SourceDocument.NAME_COMPARATOR);
for (SourceDocument doc : sourceDocuments) {
map.put(doc, null);
}
// documents
for (AnnotationDocument adoc : annotationDocuments) {
switch(adoc.getState()) {
case IGNORE:
map.remove(adoc.getDocument());
break;
default:
map.put(adoc.getDocument(), adoc);
break;
}
}
return map;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class DocumentServiceImpl method listSourceDocuments.
@Override
@Transactional(noRollbackFor = NoResultException.class)
public List<SourceDocument> listSourceDocuments(Project aProject) {
List<SourceDocument> sourceDocuments = entityManager.createQuery("FROM SourceDocument where project =:project ORDER BY name ASC", SourceDocument.class).setParameter("project", aProject).getResultList();
List<SourceDocument> tabSepDocuments = new ArrayList<>();
for (SourceDocument sourceDocument : sourceDocuments) {
if (sourceDocument.getFormat().equals(WebAnnoConst.TAB_SEP)) {
tabSepDocuments.add(sourceDocument);
}
}
sourceDocuments.removeAll(tabSepDocuments);
return sourceDocuments;
}
Aggregations