/** * Get the predictions of a given window for each document, where the outer list is a list of * tokens and the inner list is a list of predictions for a token. The method filters all tokens * which already have an annotation and don't need further recommendation. */ public Map<String, SuggestionDocumentGroup> getPredictionsForWholeProject( AnnotationLayer aLayer, DocumentService aDocumentService) { Map<String, SuggestionDocumentGroup> result = new HashMap<>(); List<AnnotationDocument> docs = aDocumentService.listAnnotationDocuments(project, user); for (AnnotationDocument doc : docs) { // TODO #176 use the document Id once it it available in the CAS SuggestionDocumentGroup p = getPredictions(doc.getName(), aLayer, -1, -1); result.put(doc.getName(), p); } return result; }
/** * TODO #176 use the document Id once it it available in the CAS * * Get the predictions of a given window, where the outer list is a list of tokens and the inner * list is a list of predictions for a token */ public SuggestionDocumentGroup getPredictions(String aDocumentName, AnnotationLayer aLayer, int aWindowBegin, int aWindowEnd) { return new SuggestionDocumentGroup(getFlattenedPredictions(aDocumentName, aLayer, aWindowBegin, aWindowEnd)); }
@Override public List<SuggestionGroup> getSuggestions(User aUser, AnnotationLayer aLayer) { Predictions model = recommendationService.getPredictions(aUser, aLayer.getProject()); if (model == null) { return Collections.emptyList(); } Map<String, SuggestionDocumentGroup> recommendationsMap = model .getPredictionsForWholeProject(aLayer, documentService); return recommendationsMap.values().stream() .flatMap(docMap -> docMap.stream()) .collect(toList()); }
SourceDocument document = eventState.getDocument(); VID vid = aEvent.getVid(); Optional<AnnotationSuggestion> prediction = model.getPredictionByVID(document, vid); rejectedRecommendation, annotatorState.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getFeature(), REJECTED, model.getPredictionsByTokenAndFeature( rejectedRecommendation.getDocumentName(), eventState.getSelectedAnnotationLayer(),
state.getProject()); List<AnnotationSuggestion> allRecommendations = model.getPredictionsByTokenAndFeature( aCurrentRecommendation.getDocumentName(), alState.getLayer(), aCurrentRecommendation.getBegin(), aCurrentRecommendation.getEnd(),
Optional<AnnotationSuggestion> oPrediction = model.getPredictionByVID(document, aVID);
Predictions model = new Predictions(project, getUser()); List<SourceDocument> documents = documentService.listSourceDocuments(project); jCas.get().getDocumentText().length()); model.putPredictions(layer.getId(), predictions);
public void removePredictions(Recommender aRecommender) { // Remove incoming predictions if (incomingPredictions != null) { incomingPredictions.removePredictions(aRecommender.getId()); } // Remove active predictions if (activePredictions != null) { activePredictions.removePredictions(aRecommender.getId()); } // Remove trainedModel contexts.remove(aRecommender); // Remove from activeRecommenders map. // We have to do this, otherwise training and prediction continues for the // recommender when a new task is triggered. MultiValuedMap<AnnotationLayer, Recommender> newActiveRecommenders = new HashSetValuedHashMap<>(); MapIterator<AnnotationLayer, Recommender> it = activeRecommenders.mapIterator(); while (it.hasNext()) { AnnotationLayer layer = it.next(); Recommender rec = it.getValue(); if (!rec.equals(aRecommender)) { newActiveRecommenders.put(layer, rec); } } setActiveRecommenders(newActiveRecommenders); } }
VID vid = aEvent.getVid(); Optional<AnnotationSuggestion> oRecommendation = model.getPredictionByVID(document, vid); if (!oRecommendation.isPresent()) { LOG.error("Could not find prediction in [{}] with id [{}]", document, vid); acceptedSuggestion, state.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), acceptedSuggestion.getFeature(), ACCEPTED, model.getPredictionsByTokenAndFeature( acceptedSuggestion.getDocumentName(), eventState.getSelectedAnnotationLayer(),
state.getProject()); List<AnnotationSuggestion> allRecommendations = model.getPredictionsByTokenAndFeature( aCurrentRecommendation.getDocumentName(), alState.getLayer(), aCurrentRecommendation.getBegin(), aCurrentRecommendation.getEnd(),
Predictions model = recommendationService.getPredictions(aState.getUser(), aState.getProject()); Optional<AnnotationSuggestion> prediction = model.getPredictionByVID(document, aVID);
SourceDocument document = eventState.getDocument(); VID vid = aEvent.getVid(); Optional<AnnotationSuggestion> prediction = model.getPredictionByVID(document, vid); rejectedRecommendation, annotatorState.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), rejectedRecommendation.getFeature(), REJECTED, model.getPredictionsByTokenAndFeature( rejectedRecommendation.getDocumentName(), eventState.getSelectedAnnotationLayer(),
SuggestionDocumentGroup groups = model.getPredictions( DocumentMetaData.get(aJcas).getDocumentTitle(), layer, windowBegin, windowEnd);
.getPredictionsByTokenAndFeature(suggestion.getDocumentName(), alState.getLayer(), suggestion.getBegin(), suggestion.getEnd(), suggestion.getFeature());
@Override public List<SuggestionGroup> getSuggestions(User aUser, AnnotationLayer aLayer) { Predictions model = recommendationService.getPredictions(aUser, aLayer.getProject()); if (model == null) { return Collections.emptyList(); } Map<String, SuggestionDocumentGroup> recommendationsMap = model .getPredictionsForWholeProject(aLayer, documentService); return recommendationsMap.values().stream() .flatMap(docMap -> docMap.stream()) .collect(toList()); }
VID vid = aEvent.getVid(); Optional<AnnotationSuggestion> oRecommendation = model.getPredictionByVID(document, vid); if (!oRecommendation.isPresent()) { LOG.error("Could not find prediction in [{}] with id [{}]", document, vid); acceptedSuggestion, state.getUser().getUsername(), eventState.getSelectedAnnotationLayer(), acceptedSuggestion.getFeature(), ACCEPTED, model.getPredictionsByTokenAndFeature( acceptedSuggestion.getDocumentName(), eventState.getSelectedAnnotationLayer(),
.getPredictionsByTokenAndFeature(suggestion.getDocumentName(), alState.getLayer(), suggestion.getBegin(), suggestion.getEnd(), suggestion.getFeature());
.getPredictionsByTokenAndFeature(suggestion.getDocumentName(), alStateModel.getObject().getLayer(), suggestion.getBegin(), suggestion.getEnd(), feat.getName());
.getPredictionsByTokenAndFeature(suggestion.getDocumentName(), alStateModel.getObject().getLayer(), suggestion.getBegin(), suggestion.getEnd(), feat.getName());
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)); }