private void writeLearningRecordInDatabaseAndEventLog( AnnotationSuggestion aCurrentRecommendation, LearningRecordType aUserAction) { writeLearningRecordInDatabaseAndEventLog(aCurrentRecommendation, aUserAction, aCurrentRecommendation.getLabel()); }
private void writeLearningRecordInDatabaseAndEventLog( AnnotationSuggestion aCurrentRecommendation, LearningRecordType aUserAction) { writeLearningRecordInDatabaseAndEventLog(aCurrentRecommendation, aUserAction, aCurrentRecommendation.getLabel()); }
/** * Returns the prediction used to generate the VID */ public Optional<AnnotationSuggestion> getPrediction(SourceDocument aDocument, int aBegin, int aEnd, String aLabel) { return predictions.values().stream() .filter(f -> f.getDocumentName().equals(aDocument.getName())) .filter(f -> f.getBegin() == aBegin && f.getEnd() == aEnd) .filter(f -> f.getLabel().equals(aLabel)) .max(Comparator.comparingInt(AnnotationSuggestion::getId)); }
private static boolean isAlreadyInCleanList(SuggestionGroup cleanRecommendationList, AnnotationSuggestion recommendationItem) { String source = recommendationItem.getRecommenderName(); String annotation = recommendationItem.getLabel(); String documentName = recommendationItem.getDocumentName(); for (AnnotationSuggestion existingRecommendation : cleanRecommendationList) { if ( existingRecommendation.getRecommenderName().equals(source) && existingRecommendation.getLabel().equals(annotation) && existingRecommendation.getDocumentName().equals(documentName) ) { return true; } } return false; }
private static boolean isAlreadyInCleanList(SuggestionGroup cleanRecommendationList, AnnotationSuggestion recommendationItem) { String source = recommendationItem.getRecommenderName(); String annotation = recommendationItem.getLabel(); String documentName = recommendationItem.getDocumentName(); for (AnnotationSuggestion existingRecommendation : cleanRecommendationList) { if ( existingRecommendation.getRecommenderName().equals(source) && existingRecommendation.getLabel().equals(annotation) && existingRecommendation.getDocumentName().equals(documentName) ) { return true; } } return false; }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, String aDocumentName, long aLayerId, String aFeature, int aBegin, int aEnd, String aLabel) { return aSuggestions.stream() .filter(group -> aDocumentName.equals(group.getDocumentName()) && aLayerId == group.getLayerId() && (aFeature == null || aFeature == group.getFeature()) && (aBegin == -1 || aBegin == group.getOffset().getBegin()) && (aEnd == -1 || aEnd == group.getOffset().getEnd())) .flatMap(group -> group.stream()) .filter(suggestion -> aLabel == null || aLabel.equals(suggestion.getLabel())) .collect(toList()); }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, String aDocumentName, long aLayerId, String aFeature, int aBegin, int aEnd, String aLabel) { return aSuggestions.stream() .filter(group -> aDocumentName.equals(group.getDocumentName()) && aLayerId == group.getLayerId() && (aFeature == null || aFeature == group.getFeature()) && (aBegin == -1 || aBegin == group.getOffset().getBegin()) && (aEnd == -1 || aEnd == group.getOffset().getEnd())) .flatMap(group -> group.stream()) .filter(suggestion -> aLabel == null || aLabel.equals(suggestion.getLabel())) .collect(toList()); }
/** * * @param aLayerId * @param aPredictions - list of sentences containing recommendations */ public void putPredictions(long aLayerId, List<AnnotationSuggestion> aPredictions) { aPredictions.forEach(prediction -> { if (prediction.getLabel() != null) { predictions.put(new ExtendedId(user.getUsername(), project.getId(), prediction.getDocumentName(), aLayerId, prediction.getOffset(), prediction.getRecommenderId(), prediction.getId(), -1), prediction); } }); }
private String formatLabel(AnnotationSuggestion aCurrentRecommendation) { AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alStateModel.getObject().getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); String labelValue = featureSupport.renderFeatureValue(feat, aCurrentRecommendation.getLabel()); return labelValue; }
private String formatLabel(AnnotationSuggestion aCurrentRecommendation) { AnnotationFeature feat = annotationService.getFeature(aCurrentRecommendation.getFeature(), alStateModel.getObject().getLayer()); FeatureSupport<?> featureSupport = featureSupportRegistry.getFeatureSupport(feat); String labelValue = featureSupport.renderFeatureValue(feat, aCurrentRecommendation.getLabel()); return labelValue; }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, AnnotationSuggestion aSuggestion) { return getMatchingSuggestion(aSuggestions, aSuggestion.getDocumentName(), aSuggestion.getLayerId(), aSuggestion.getFeature(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getLabel()); }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, AnnotationSuggestion aSuggestion) { return getMatchingSuggestion(aSuggestions, aSuggestion.getDocumentName(), aSuggestion.getLayerId(), aSuggestion.getFeature(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getLabel()); }
@Override public String getDetails(ActiveLearningSuggestionOfferedEvent aEvent) { try { Details details = new Details(); details.ann = new AnnotationDetails(); details.ann.setBegin(aEvent.getCurrentRecommendation().getBegin()); details.ann.setEnd(aEvent.getCurrentRecommendation().getEnd()); details.ann.setText(aEvent.getCurrentRecommendation().getCoveredText()); details.ann.setType(aEvent.getLayer().getName()); details.annotationFeature = aEvent.getAnnotationFeature(); details.currentLabel = aEvent.getCurrentRecommendation().getLabel(); details.confidence = aEvent.getCurrentRecommendation().getConfidence(); details.recommenderId = aEvent.getCurrentRecommendation().getRecommenderId(); List<String> allLabelList = aEvent.getAllRecommendations().stream() .map(ao -> ao.getLabel()).collect(Collectors.toList()); details.allLabels = String.join(", ", allLabelList); return JSONUtil.toJsonString(details); } catch (IOException e) { log.error("Unable to log event [{}]", aEvent, e); return "<ERROR>"; } }
@Override public String getDetails(ActiveLearningSuggestionOfferedEvent aEvent) { try { Details details = new Details(); details.ann = new AnnotationDetails(); details.ann.setBegin(aEvent.getCurrentRecommendation().getBegin()); details.ann.setEnd(aEvent.getCurrentRecommendation().getEnd()); details.ann.setText(aEvent.getCurrentRecommendation().getCoveredText()); details.ann.setType(aEvent.getLayer().getName()); details.annotationFeature = aEvent.getAnnotationFeature(); details.currentLabel = aEvent.getCurrentRecommendation().getLabel(); details.confidence = aEvent.getCurrentRecommendation().getConfidence(); details.recommenderId = aEvent.getCurrentRecommendation().getRecommenderId(); List<String> allLabelList = aEvent.getAllRecommendations().stream() .map(ao -> ao.getLabel()).collect(Collectors.toList()); details.allLabels = String.join(", ", allLabelList); return JSONUtil.toJsonString(details); } catch (IOException e) { log.error("Unable to log event [{}]", aEvent, e); return "<ERROR>"; } }
@Override public String getDetails(ActiveLearningRecommendationEvent aEvent) { try { ActiveLearningRecommendationDetails details = new ActiveLearningRecommendationDetails(); details.ann = new AnnotationDetails(); details.ann.setBegin(aEvent.getCurrentRecommendation().getBegin()); details.ann.setEnd(aEvent.getCurrentRecommendation().getEnd()); details.ann.setText(aEvent.getCurrentRecommendation().getCoveredText()); details.ann.setType(aEvent.getLayer().getName()); details.annotationFeature = aEvent.getAnnotationFeature(); details.userAction = aEvent.getAction(); details.currentLabel = aEvent.getCurrentRecommendation().getLabel(); details.confidence = aEvent.getCurrentRecommendation().getConfidence(); details.recommenderId = aEvent.getCurrentRecommendation().getRecommenderId(); List<String> allLabelList = aEvent.getAllRecommendations().stream() .map(ao -> ao.getLabel()).collect(Collectors.toList()); details.allLabels = String.join(", ", allLabelList); return JSONUtil.toJsonString(details); } catch (IOException e) { log.error("Unable to log event [{}]", aEvent, e); return "<ERROR>"; } }
@Override public String getDetails(ActiveLearningRecommendationEvent aEvent) { try { ActiveLearningRecommendationDetails details = new ActiveLearningRecommendationDetails(); details.ann = new AnnotationDetails(); details.ann.setBegin(aEvent.getCurrentRecommendation().getBegin()); details.ann.setEnd(aEvent.getCurrentRecommendation().getEnd()); details.ann.setText(aEvent.getCurrentRecommendation().getCoveredText()); details.ann.setType(aEvent.getLayer().getName()); details.annotationFeature = aEvent.getAnnotationFeature(); details.userAction = aEvent.getAction(); details.currentLabel = aEvent.getCurrentRecommendation().getLabel(); details.confidence = aEvent.getCurrentRecommendation().getConfidence(); details.recommenderId = aEvent.getCurrentRecommendation().getRecommenderId(); List<String> allLabelList = aEvent.getAllRecommendations().stream() .map(ao -> ao.getLabel()).collect(Collectors.toList()); details.allLabels = String.join(", ", allLabelList); return JSONUtil.toJsonString(details); } catch (IOException e) { log.error("Unable to log event [{}]", aEvent, e); return "<ERROR>"; } }
@Override public boolean isSuggestionVisible(LearningRecord aRecord) { User user = userService.get(aRecord.getUser()); List<SuggestionGroup> suggestions = getSuggestions(user, aRecord.getLayer()); for (SuggestionGroup listOfAO : suggestions) { if (listOfAO.stream().anyMatch(suggestion -> suggestion.getDocumentName().equals(aRecord.getSourceDocument().getName()) && suggestion.getFeature().equals(aRecord.getAnnotationFeature().getName()) && suggestion.getLabel().equals(aRecord.getAnnotation()) && suggestion.getBegin() == aRecord.getOffsetCharacterBegin() && suggestion.getEnd() == aRecord.getOffsetCharacterEnd() && suggestion.isVisible()) ) { return true; } } return false; }
@Override public boolean isSuggestionVisible(LearningRecord aRecord) { User user = userService.get(aRecord.getUser()); List<SuggestionGroup> suggestions = getSuggestions(user, aRecord.getLayer()); for (SuggestionGroup listOfAO : suggestions) { if (listOfAO.stream().anyMatch(suggestion -> suggestion.getDocumentName().equals(aRecord.getSourceDocument().getName()) && suggestion.getFeature().equals(aRecord.getAnnotationFeature().getName()) && suggestion.getLabel().equals(aRecord.getAnnotation()) && suggestion.getBegin() == aRecord.getOffsetCharacterBegin() && suggestion.getEnd() == aRecord.getOffsetCharacterEnd() && suggestion.isVisible()) ) { return true; } } return false; }
&& r.getOffsetCharacterBegin() == s.getBegin() && r.getOffsetCharacterEnd() == s.getEnd() && r.getAnnotation().equals(s.getLabel())) .forEach(record -> { if (REJECTED.equals(record.getUserAction())) {