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; }
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; }
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; } }
private List<TrainingDocument> readCasses(Project aProject, User aUser) { List<TrainingDocument> casses = new ArrayList<>(); Map<SourceDocument, AnnotationDocument> allDocuments = documentService.listAllDocuments(aProject, aUser); for (Map.Entry<SourceDocument, AnnotationDocument> entry : allDocuments.entrySet()) { try { SourceDocument sourceDocument = entry.getKey(); AnnotationDocument annotationDocument = entry.getValue(); AnnotationDocumentState state = annotationDocument != null ? annotationDocument.getState() : AnnotationDocumentState.NEW; JCas jCas = documentService.readAnnotationCas(sourceDocument, aUser.getUsername()); casses.add(new TrainingDocument(jCas.getCas(), state)); } catch (IOException e) { log.error("Cannot read annotation CAS.", e); } } return casses; }
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; }
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 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)); }
private JCas getJCas(AnnotatorState aState, AnnotationDocument aDocument) throws IOException { if (aState.getMode().equals(Mode.AUTOMATION) || aState.getMode().equals(Mode.CORRECTION)) { return correctionDocumentService.readCorrectionCas(aState.getDocument()); } else { return documentService.readAnnotationCas(aDocument); } }
@Test public void thatReadingNonExistentAnnotationCasCreatesNewCas() throws Exception { SourceDocument sourceDocument = makeSourceDocument(1l, 1l, "test"); User user = makeUser(); when(userRepository.get(user.getUsername())).thenReturn(user); when(entityManager.createQuery(anyString(), any())).thenThrow(NoResultException.class); when(importExportService.importCasFromFile(any(File.class), any(Project.class), any())).thenReturn(JCasFactory.createText("Test")); JCas cas = sut.readAnnotationCas(sourceDocument, user.getUsername()); assertThat(cas).isNotNull(); assertThat(cas.getDocumentText()).isEqualTo("Test"); assertThat(storageService.getCasFile(sourceDocument, user.getUsername())).exists(); }
private JCas getJCas(AnnotatorState aState, AnnotationDocument aDocument) throws IOException { if (aState.getMode().equals(Mode.AUTOMATION) || aState.getMode().equals(Mode.CORRECTION)) { return correctionDocumentService.readCorrectionCas(aState.getDocument()); } else { return documentService.readAnnotationCas(aDocument); } }
JCas annoCas = aDocumentService.readAnnotationCas(annoDoc);
private JCas createCorrectionCas(JCas mergeJCas, AnnotatorState aState, AnnotationDocument aRandomAnnotationDocument) throws UIMAException, ClassNotFoundException, IOException { User user = userRepository.getCurrentUser(); mergeJCas = documentService.readAnnotationCas(aState.getDocument(), user); correctionDocumentService.writeCorrectionCas(mergeJCas, aRandomAnnotationDocument.getDocument()); updateDocumentTimestampAfterWrite(aState, correctionDocumentService .getCorrectionCasTimestamp(aState.getDocument())); return mergeJCas; } }
@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()); }
private JCas createCorrectionCas(JCas mergeJCas, AnnotatorState aState, AnnotationDocument aRandomAnnotationDocument) throws UIMAException, ClassNotFoundException, IOException { User user = userRepository.getCurrentUser(); mergeJCas = documentService.readAnnotationCas(aState.getDocument(), user); correctionDocumentService.writeCorrectionCas(mergeJCas, aRandomAnnotationDocument.getDocument()); updateDocumentTimestampAfterWrite(aState, correctionDocumentService .getCorrectionCasTimestamp(aState.getDocument())); return mergeJCas; } }
@Override protected 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(getModelObject().getDocument(), state.getUser().getUsername()); }
@Override protected 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(getModelObject().getDocument(), state.getUser().getUsername()); }
@Override protected 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(getModelObject().getDocument(), state.getUser().getUsername()); }
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 } } }
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 } } }
JCas annoCas = aDocumentService.readAnnotationCas(annoDoc);