private void actionOpen(AjaxRequestTarget aTarget, ExternalSearchResult aResult, String aDocumentTitle) { selectedResult = aResult; getAnnotationPage().actionShowSelectedDocument(aTarget, documentService.getSourceDocument(project, aDocumentTitle)); }
private void searchDocuments(String aQuery) { documents.clear(); List<SearchResult> results = new ArrayList<SearchResult>(); try { results = searchService.query(currentUser, currentProject, aQuery); } catch (Exception e) { LOG.error("Unable to perform query", e); error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e)); } for (SearchResult result : results) { documents.add( documentService.getSourceDocument(currentProject, result.getDocumentTitle())); } }
private SourceDocument getDocumentFromParameters(Project aProject, StringValue documentParam) { SourceDocument document = null; if (documentParam != null && !documentParam.isEmpty()) { long documentId = documentParam.toLong(); document = documentService.getSourceDocument(aProject.getId(), documentId); } return document; }
private SourceDocument getDocument(Project aProject, long aDocumentId) throws ObjectNotFoundException { try { return documentService.getSourceDocument(aProject.getId(), aDocumentId); } catch (NoResultException e) { throw new ObjectNotFoundException( "Document [" + aDocumentId + "] in project [" + aProject.getId() + "] not found."); } }
private SourceDocument getDocumentFromParameters(Project aProject, StringValue documentParam) { SourceDocument document = null; if (documentParam != null && !documentParam.isEmpty()) { long documentId = documentParam.toLong(); document = documentService.getSourceDocument(aProject.getId(), documentId); } return document; }
private SourceDocument getDocument(Project aProject, long aDocumentId) throws ObjectNotFoundException { try { return documentService.getSourceDocument(aProject.getId(), aDocumentId); } catch (NoResultException e) { throw new ObjectNotFoundException( "Document [" + aDocumentId + "] in project [" + aProject.getId() + "] not found."); } }
private SourceDocument getDocumentFromParameters(Project aProject, StringValue documentParam) { SourceDocument document = null; if (documentParam != null && !documentParam.isEmpty()) { long documentId = documentParam.toLong(); document = documentService.getSourceDocument(aProject.getId(), documentId); } return document; }
private void actionImport(AjaxRequestTarget aTarget, ExternalSearchResult aResult, String aDocumentTitle) { selectedResult = aResult; try { documentImporter .importDocumentFromDocumentRepository(userRepository.getCurrentUser(), project, aDocumentTitle, currentRepository); getAnnotationPage().actionShowSelectedDocument(aTarget, documentService.getSourceDocument(project, aDocumentTitle)); } catch (IOException e) { LOG.error("{}", e.getMessage(), e); error(e.getMessage() + " - " + ExceptionUtils.getRootCauseMessage(e)); } }
private void actionJumpToSuggestion(AjaxRequestTarget aTarget) throws IOException { ActiveLearningUserState alState = alStateModel.getObject(); AnnotationSuggestion suggestion = alState.getSuggestion().get(); if (LOG.isDebugEnabled()) { LOG.debug("Active suggestion: {}", suggestion); Optional<AnnotationSuggestion> updatedSuggestion = getMatchingSuggestion( activeLearningService.getSuggestions(getModelObject().getUser(), alState.getLayer()), suggestion).stream().findFirst(); updatedSuggestion.ifPresent(s -> LOG.debug("Update suggestion: {}", s)); } actionShowSelectedDocument(aTarget, documentService.getSourceDocument(this.getModelObject().getProject(), suggestion.getDocumentName()), suggestion.getBegin(), suggestion.getEnd()); setHighlight(suggestion); }
private void actionJumpToSuggestion(AjaxRequestTarget aTarget) throws IOException { ActiveLearningUserState alState = alStateModel.getObject(); AnnotationSuggestion suggestion = alState.getSuggestion().get(); if (LOG.isDebugEnabled()) { LOG.debug("Active suggestion: {}", suggestion); Optional<AnnotationSuggestion> updatedSuggestion = getMatchingSuggestion( activeLearningService.getSuggestions(getModelObject().getUser(), alState.getLayer()), suggestion).stream().findFirst(); updatedSuggestion.ifPresent(s -> LOG.debug("Update suggestion: {}", s)); } actionShowSelectedDocument(aTarget, documentService.getSourceDocument(this.getModelObject().getProject(), suggestion.getDocumentName()), suggestion.getBegin(), suggestion.getEnd()); setHighlight(suggestion); }
@Override protected void onConfigure() { super.onConfigure(); setEnabled(state.getDocument() != null && !documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)); }
@Override protected void onConfigure() { super.onConfigure(); setEnabled(state.getDocument() != null && !documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)); }
@Override protected void onEvent(AjaxRequestTarget aTarget) { if (!projectService.isCurator(project, user)) { aTarget.appendJavaScript( "alert('the state can only be changed explicitly by the curator')"); return; } SourceDocument doc = documentService.getSourceDocument(project, value.substring(value.indexOf(":") + 1)); if (doc.getState().equals(CURATION_FINISHED)) { documentService.transitionSourceDocumentState(doc, CURATION_FINISHED_TO_CURATION_IN_PROGRESS); } else if (doc.getState().equals(CURATION_IN_PROGRESS)) { documentService.transitionSourceDocumentState(doc, CURATION_IN_PROGRESS_TO_CURATION_FINISHED); } else if (doc.getState().equals(ANNOTATION_IN_PROGRESS)) { documentService.transitionSourceDocumentState(doc, ANNOTATION_IN_PROGRESS_TO_CURATION_IN_PROGRESS); } aTarget.add(aCellItem); updateStats(aTarget, projectSelectionForm.getModelObject()); } });
@Override protected void onConfigure() { super.onConfigure(); AnnotatorState state = CurationPage.this.getModelObject(); setEnabled(state.getProject() != null && state.getDocument() != null && !documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)); } });
@Override protected String load() { AnnotatorState state = CurationPage.this.getModelObject(); if (state.getProject() != null && state.getDocument() != null) { if (documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()).getState() .equals(SourceDocumentState.CURATION_FINISHED)) { return "images/accept.png"; } else { return "images/inprogress.png"; } } else { return "images/inprogress.png"; } } }));
@Override protected void onConfigure() { super.onConfigure(); AnnotatorState state = CurationPage.this.getModelObject(); setEnabled(state.getProject() != null && state.getDocument() != null && !documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()) .getState().equals(SourceDocumentState.CURATION_FINISHED)); } });
@Override protected String load() { AnnotatorState state = CurationPage.this.getModelObject(); if (state.getProject() != null && state.getDocument() != null) { if (documentService .getSourceDocument(state.getDocument().getProject(), state.getDocument().getName()).getState() .equals(SourceDocumentState.CURATION_FINISHED)) { return "images/accept.png"; } else { return "images/inprogress.png"; } } else { return "images/inprogress.png"; } } }));
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 void writeLearningRecordInDatabaseAndEventLog(AnnotationSuggestion aSuggestion, LearningRecordType aUserAction, String aAnnotationValue) { AnnotatorState state = ActiveLearningSidebar.this.getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); AnnotationFeature feat = annotationService.getFeature(aSuggestion.getFeature(), alState.getLayer()); SourceDocument sourceDoc = documentService.getSourceDocument(state.getProject(), aSuggestion.getDocumentName()); // Log the action to the learning record learningRecordService.logRecord(sourceDoc, state.getUser().getUsername(), aSuggestion, aAnnotationValue, alState.getLayer(), feat, aUserAction, LearningRecordChangeLocation.AL_SIDEBAR); // Send an application event that the suggestion has been rejected List<AnnotationSuggestion> alternativeSuggestions = recommendationService .getPredictions(state.getUser(), state.getProject()) .getPredictionsByTokenAndFeature(aSuggestion.getDocumentName(), alState.getLayer(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getFeature()); applicationEventPublisherHolder.get() .publishEvent(new ActiveLearningRecommendationEvent(this, sourceDoc, aSuggestion, state.getUser().getUsername(), alState.getLayer(), aSuggestion.getFeature(), aUserAction, alternativeSuggestions)); }
private void writeLearningRecordInDatabaseAndEventLog(AnnotationSuggestion aSuggestion, LearningRecordType aUserAction, String aAnnotationValue) { AnnotatorState state = ActiveLearningSidebar.this.getModelObject(); ActiveLearningUserState alState = alStateModel.getObject(); AnnotationFeature feat = annotationService.getFeature(aSuggestion.getFeature(), alState.getLayer()); SourceDocument sourceDoc = documentService.getSourceDocument(state.getProject(), aSuggestion.getDocumentName()); // Log the action to the learning record learningRecordService.logRecord(sourceDoc, state.getUser().getUsername(), aSuggestion, aAnnotationValue, alState.getLayer(), feat, aUserAction, LearningRecordChangeLocation.AL_SIDEBAR); // Send an application event that the suggestion has been rejected List<AnnotationSuggestion> alternativeSuggestions = recommendationService .getPredictions(state.getUser(), state.getProject()) .getPredictionsByTokenAndFeature(aSuggestion.getDocumentName(), alState.getLayer(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getFeature()); applicationEventPublisherHolder.get() .publishEvent(new ActiveLearningRecommendationEvent(this, sourceDoc, aSuggestion, state.getUser().getUsername(), alState.getLayer(), aSuggestion.getFeature(), aUserAction, alternativeSuggestions)); }