private void actionOpen(AjaxRequestTarget aTarget, ExternalSearchResult aResult, String aDocumentTitle) { selectedResult = aResult; getAnnotationPage().actionShowSelectedDocument(aTarget, documentService.getSourceDocument(project, aDocumentTitle)); }
private void indexAllDocuments() { int users = 0; int annotationDocs = 0; int sourceDocs = 0; try { log.info("Indexing all annotation documents of project [{}]({})", project.getName(), project.getId()); for (User user : projectService.listProjectUsersWithPermissions(project)) { users++; for (AnnotationDocument document : documentService.listAnnotationDocuments(project, user)) { indexDocument(document, documentService.readAnnotationCas(document)); annotationDocs++; } } log.info("Indexing all source documents of project [{}]({})", project.getName(), project.getId()); for (SourceDocument document : documentService.listSourceDocuments(project)) { indexDocument(document, documentService.createOrReadInitialCas(document)); sourceDocs++; } } catch (IOException e) { log.error("Unable to index document", e); } log.info(String.format( "Indexing results: %d source doc(s), %d annotation doc(s) for %d user(s)", sourceDocs, annotationDocs, users)); }
public void upgradeCasAndSave(SourceDocument aDocument, String aUsername) throws IOException { User user = userRepository.get(aUsername); if (documentService.existsAnnotationDocument(aDocument, user)) { AnnotationDocument annotationDocument = documentService.getAnnotationDocument(aDocument, user); try { CAS cas = documentService.readAnnotationCas(annotationDocument).getCas(); annotationService.upgradeCas(cas, annotationDocument); documentService.writeAnnotationCas(cas.getJCas(), annotationDocument, false); } catch (Exception e) { // no need to catch, it is acceptable that no curation document // exists to be upgraded while there are annotation documents } } }
/** * change the state of an annotation document. used to re-open closed documents */ private void changeAnnotationDocumentState(SourceDocument aSourceDocument, User aUser, AnnotationDocumentStateTransition aAnnotationDocumentStateTransition) { AnnotationDocument annotationDocument = documentService .getAnnotationDocument(aSourceDocument, aUser); documentService.transitionAnnotationDocumentState(annotationDocument, aAnnotationDocumentStateTransition); } }
@EventListener public void beforeProjectRemove(BeforeProjectRemovedEvent aEvent) throws IOException { for (SourceDocument document : service.listSourceDocuments(aEvent.getProject())) { service.removeSourceDocument(document); } } }
private Map<String, JCas> listJcasesforCorrection(AnnotationDocument randomAnnotationDocument, SourceDocument aDocument, Mode aMode) throws UIMAException, ClassNotFoundException, IOException { Map<String, JCas> jCases = new HashMap<>(); User user = userRepository .get(SecurityContextHolder.getContext().getAuthentication().getName()); randomAnnotationDocument = documentService.getAnnotationDocument(aDocument, user); // Upgrading should be an explicit action during the opening of a document at the end // of the open dialog - it must not happen during editing because the CAS addresses // are used as IDs in the UI // repository.upgradeCasAndSave(aDocument, aMode, user.getUsername()); JCas jCas = documentService.readAnnotationCas(randomAnnotationDocument); jCases.put(user.getUsername(), jCas); return jCases; }
.createOrGetAnnotationDocument(state.getDocument(), user); correctionCas = documentService.createOrReadInitialCas(state.getDocument()); if (documentService.existsCas(state.getDocument(), user.getUsername())) { editorCas = documentService.readAnnotationCas(annotationDocument); editorCas = documentService.createOrReadInitialCas(state.getDocument()); editorCas = BratAnnotatorUtility.clearJcasAnnotations(editorCas); documentService.writeAnnotationCas(editorCas, state.getDocument(), user, false); documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument.getDocument(), user, false); correctionDocumentService.writeCorrectionCas(correctionCas, state.getDocument()); .getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername())); documentService.transitionSourceDocumentState(state.getDocument(), SourceDocumentStateTransition.NEW_TO_ANNOTATION_IN_PROGRESS);
throws UIMAException, ClassNotFoundException, IOException, AnnotationException AnnotationDocument annoDoc = aDocumentService.getAnnotationDocument(aBModel.getDocument(), aBModel.getUser()); JCas annoCas = aDocumentService.readAnnotationCas(annoDoc); for (SourceDocument d : aDocumentService.listSourceDocuments(aBModel.getProject())) { loadDocument(d, aAnnotationService, aDocumentService, aCorrectionDocumentService, aBModel.getUser());
SourceDocument sourceDoc = documentService.getSourceDocument(state.getProject(), suggestion.getDocumentName()); String username = state.getUser().getUsername(); JCas jCas = documentService.readAnnotationCas(sourceDoc, username); documentService.writeAnnotationCas(jCas, sourceDoc, state.getUser(), true); Optional<Long> diskTimestamp = documentService.getAnnotationCasTimestamp(sourceDoc, username); if (diskTimestamp.isPresent()) {
List<SourceDocument> documents = documentService.listSourceDocuments(project); int i = 1; int initProgress = aRequest.progress; documentService.createOrReadInitialCas(sourceDocument); File initialCasFile = documentService.getCasFile(sourceDocument, INITIAL_CAS_PSEUDO_USER); documentService.listAnnotationDocuments(sourceDocument)) { FileUtils.forceMkdir(annotationDocumentDir); File annotationFileAsSerialisedCas = documentService.getCasFile( sourceDocument, annotationDocument.getUser()); File correctionCasFile = documentService.getCasFile(sourceDocument, CORRECTION_USER); if (correctionCasFile.exists()) {
private Map<String, Integer> getPercentageOfFinishedDocumentsPerUser(Project aProject) { Map<String, Integer> annotatorsProgress = new HashMap<>(); if (aProject != null) { for (User user : projectService.listProjectUsersWithPermissions(aProject, PermissionLevel.ANNOTATOR)) { 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; }
AnnotationDocument annotationDocument = documentService.getAnnotationDocument( sourceDocument, user); jCases.put(user.getUsername(), documentService.readAnnotationCas(annotationDocument)); aAnnotationSelectionByUsernameAndAddress.put(CURATION_USER, new HashMap<>()); .listAnnotationDocuments(sourceDocument); for (AnnotationDocument annotationDocument : annotationDocuments) { String username = annotationDocument.getUser(); if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED) || username.equals(CURATION_USER)) { JCas jCas = documentService.readAnnotationCas(annotationDocument); jCases.put(username, jCas);
.createOrGetAnnotationDocument(state.getDocument(), state.getUser()); JCas editorCas = documentService.readAnnotationCas(annotationDocument); documentService.writeAnnotationCas(editorCas.getCas().getJCas(), annotationDocument, false); .getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername())); documentService.transitionSourceDocumentState(state.getDocument(), NEW_TO_ANNOTATION_IN_PROGRESS);
for (SourceDocument sd : documentService.listSourceDocuments(project)) { casDoctor.repair(project, correctionCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(correctionCas, documentService.getCasFile(sd, CORRECTION_USER)); casDoctor.repair(project, curationCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(curationCas, documentService.getCasFile(sd, CURATION_USER)); for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) { if (documentService.existsAnnotationCas(ad)) { LogMessageSet messageSet = new LogMessageSet( sd.getName() + " [" + ad.getUser() + "]"); casDoctor.repair(project, userCas.getCas(), messageSet.messages); CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
@Override public JCas getEditorCas() throws IOException { AnnotatorState state = getModelObject(); if (state.getDocument() == null) { throw new IllegalStateException("Please open a document first!"); } // If we have a timestamp, then use it to detect if there was a concurrent access verifyAndUpdateDocumentTimestamp(state, documentService .getAnnotationCasTimestamp(state.getDocument(), state.getUser().getUsername())); return documentService.readAnnotationCas(state.getDocument(), state.getUser().getUsername()); }
public static boolean isDocumentFinished(DocumentService aRepository, AnnotatorState aBratAnnotatorModel) { try { if (aBratAnnotatorModel.getMode().equals(Mode.CURATION)) { // Load document freshly from DB so we get the latest state. The document state // in the annotator state might be stale. SourceDocument doc = aRepository.getSourceDocument( aBratAnnotatorModel.getDocument().getProject().getId(), aBratAnnotatorModel.getDocument().getId()); return doc.getState().equals(SourceDocumentState.CURATION_FINISHED); } else { // if annotationDocument is finished, disable editing AnnotationDocument adoc = aRepository.getAnnotationDocument( aBratAnnotatorModel.getDocument(), aBratAnnotatorModel.getUser()); return adoc.getState().equals(AnnotationDocumentState.FINISHED); } } catch (Exception e) { return false; } }
private List<CAS> readCasses(Project aProject, String aUserName) { List<CAS> casses = new ArrayList<>(); for (SourceDocument document : documentService.listSourceDocuments(aProject)) { try { JCas jCas = documentService.readAnnotationCas(document, aUserName); annoService.upgradeCasIfRequired(jCas.getCas(), document, aUserName); casses.add(jCas.getCas()); } catch (IOException e) { log.error("Cannot read annotation CAS.", e); } catch (UIMAException e) { log.error("Cannot upgrade annotation CAS.", e); } } return casses; } }
for (SourceDocument sd : documentService.listSourceDocuments(project)) { for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) { if (documentService.existsAnnotationCas(ad)) { LogMessageSet messageSet = new LogMessageSet( sd.getName() + " [" + ad.getUser() + "]");
public Map<String, JCas> listJcasesforCuration(List<AnnotationDocument> annotationDocuments, AnnotationDocument randomAnnotationDocument, Mode aMode) throws UIMAException, ClassNotFoundException, IOException { Map<String, JCas> jCases = new HashMap<>(); for (AnnotationDocument annotationDocument : annotationDocuments) { String username = annotationDocument.getUser(); if (!annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) { continue; } if (randomAnnotationDocument == null) { randomAnnotationDocument = annotationDocument; } // Upgrading should be an explicit action during the opening of a document at the end // of the open dialog - it must not happen during editing because the CAS addresses // are used as IDs in the UI // repository.upgradeCasAndSave(annotationDocument.getDocument(), aMode, username); JCas jCas = documentService.readAnnotationCas(annotationDocument); jCases.put(username, jCas); } return jCases; }
private void exportAnnotationDocuments(Project aProject, ExportedProject aExProject) { List<ExportedAnnotationDocument> annotationDocuments = new ArrayList<>(); // add source documents to a project List<SourceDocument> documents = documentService.listSourceDocuments(aProject); for (SourceDocument sourceDocument : documents) { // add annotation document to Project for (AnnotationDocument annotationDocument : documentService .listAnnotationDocuments(sourceDocument)) { ExportedAnnotationDocument exAnnotationDocument = new ExportedAnnotationDocument(); exAnnotationDocument.setName(annotationDocument.getName()); exAnnotationDocument.setState(annotationDocument.getState()); exAnnotationDocument.setUser(annotationDocument.getUser()); exAnnotationDocument.setTimestamp(annotationDocument.getTimestamp()); exAnnotationDocument.setSentenceAccessed(annotationDocument.getSentenceAccessed()); exAnnotationDocument.setCreated(annotationDocument.getCreated()); exAnnotationDocument.setUpdated(annotationDocument.getUpdated()); annotationDocuments.add(exAnnotationDocument); } } aExProject.setAnnotationDocuments(annotationDocuments); }