private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, AnnotationSuggestion aSuggestion) { return getMatchingSuggestion(aSuggestions, aSuggestion.getDocumentName(), aSuggestion.getLayerId(), aSuggestion.getFeature(), aSuggestion.getBegin(), aSuggestion.getEnd(), aSuggestion.getLabel()); }
public Delta(AnnotationSuggestion aFirst, AnnotationSuggestion aSecond) { Validate.notNull(aFirst, "At least first item must be given to compute delta"); first = aFirst; second = aSecond; if (second == null) { delta = Math.abs(aFirst.getConfidence()); } else { delta = Math.abs(first.getConfidence() - second.getConfidence()); } }
/** * * @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); } }); }
public GroupKey(AnnotationSuggestion aSuggestion) { super(); begin = aSuggestion.getBegin(); end = aSuggestion.getEnd(); feature = aSuggestion.getFeature(); layerId = aSuggestion.getLayerId(); }
private void setHighlight(AnnotationSuggestion aSuggestion) { if (protectHighlight) { LOG.trace("Active learning sidebar not updating protected highlights"); protectHighlight = false; return; } LOG.trace("Active learning sidebar set highlight suggestion: {}", aSuggestion); highlightVID = aSuggestion.getVID(); highlightSpan = new Offset(aSuggestion.getBegin(), aSuggestion.getEnd()); highlightDocumentName = aSuggestion.getDocumentName(); }
@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>"; } }
if (!pref.isShowAllPredictions() && !ao.isVisible()) { continue; if (!labelMap.containsKey(ao.getLabel()) || !labelMap.get(ao.getLabel()) .containsKey(ao.getRecommenderId()) || labelMap.get(ao.getLabel()).get(ao.getRecommenderId()) .getConfidence() < ao.getConfidence()) { if (labelMap.get(ao.getLabel()) == null) { confidencePerClassifier = new HashMap<>(); } else { confidencePerClassifier = labelMap.get(ao.getLabel()); confidencePerClassifier.put(ao.getRecommenderId(), ao); labelMap.put(ao.getLabel(), confidencePerClassifier); for (Entry<Long, AnnotationSuggestion> classifier : labelMap.get(label) .entrySet()) { if (classifier.getValue().getConfidence() > maxConfidence) { maxConfidence = classifier.getValue().getConfidence(); .filter(p -> p.getLabel().equals(label)) .max(Comparator.comparingInt(AnnotationSuggestion::getId)).orElse(null); VID vid = canonicalRecommendation.getVID(); .getFeature(ao.getFeature(), layer);
AnnotationSuggestion representative = get(0); Validate.isTrue( representative.getBegin() == aSuggestion.getBegin() && representative.getEnd() == aSuggestion.getEnd(), "All suggestions in a group must be at the same position: expected [%d-%d] but got [%d-%d]", representative.getBegin(), representative.getEnd(), aSuggestion.getBegin(), aSuggestion.getEnd()); Validate.isTrue(representative.getDocumentName().equals(aSuggestion.getDocumentName()), "All suggestions in a group must come from the same document: expected [%s] but got [%s]", representative.getDocumentName(), aSuggestion.getDocumentName()); Validate.isTrue(representative.getLayerId() == aSuggestion.getLayerId(), "All suggestions in a group must be on the same layer: expected [%d] but got [%d]", representative.getLayerId(), aSuggestion.getLayerId()); Validate.isTrue(representative.getFeature().equals(aSuggestion.getFeature()), "All suggestions in a group must be for the same feature: expected [%s] but got [%s]", representative.getFeature(), aSuggestion.getFeature()); offset = aSuggestion.getOffset(); feature = aSuggestion.getFeature(); layerId = aSuggestion.getLayerId(); documentName = aSuggestion.getDocumentName();
if (s.isVisible()) { records.stream() .filter(r -> r.getSourceDocument().getName().equals(s.getDocumentName()) && r.getOffsetCharacterBegin() == s.getBegin() && r.getOffsetCharacterEnd() == s.getEnd() && r.getAnnotation().equals(s.getLabel())) .forEach(record -> { if (REJECTED.equals(record.getUserAction())) { s.hide(FLAG_REJECTED); s.hide(FLAG_SKIPPED);
if (aSuggestion.getLabel() == null) { aSuggestion.hide(FLAG_NO_LABEL); return; if (record.getOffsetCharacterBegin() == aSuggestion.getBegin() && record.getOffsetCharacterEnd() == aSuggestion.getEnd() && record.getAnnotation().equals(aSuggestion.getLabel())) aSuggestion.hide(FLAG_REJECTED); break; case SKIPPED: aSuggestion.hide(FLAG_SKIPPED); break; default:
public SuggestionGroup(AnnotationSuggestion... aItems) { suggestions = new ArrayList<>(asList(aItems)); sorted = suggestions.size() < 2; if (!suggestions.isEmpty()) { offset = suggestions.get(0).getOffset(); feature = get(0).getFeature(); layerId = get(0).getLayerId(); documentName = get(0).getDocumentName(); } }
.setParameter("user", aUsername) .setParameter("sourceDocument", aDocument) .setParameter("offsetCharacterBegin", aSuggestion.getBegin()) .setParameter("offsetCharacterEnd", aSuggestion.getEnd()) .setParameter("layer", aLayer) .setParameter("annotationFeature", aFeature) record.setSourceDocument(aDocument); record.setUserAction(aUserAction); record.setOffsetCharacterBegin(aSuggestion.getBegin()); record.setOffsetCharacterEnd(aSuggestion.getEnd()); record.setOffsetTokenBegin(-1); record.setOffsetTokenEnd(-1); record.setTokenText(aSuggestion.getCoveredText()); record.setAnnotation(aAlternativeLabel); record.setLayer(aLayer);
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 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; }
/** * Returns the first prediction that matches recommendationId and recommenderId * in the given document. */ public Optional<AnnotationSuggestion> getPredictionByVID(SourceDocument aDocument, VID aVID) { return predictions.values().stream() .filter(f -> f.getDocumentName().equals(aDocument.getName())) .filter(f -> f.getId() == aVID.getSubId()) .filter(f -> f.getRecommenderId() == aVID.getId()) .findFirst(); }
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; }
suggestion.hide(FLAG_TRANSIENT_REJECTED); aBegin, aEnd, suggestion.getCoveredText(), feature, suggestion.getLabel()));
if (top.isVisible()) { return singletonMap(top.getRecommenderId(), new Delta(top));
@Override public String toString() { return new ToStringBuilder(this).append("id", id).append("recommenderId", recommenderId) .append("recommenderName", recommenderName).append("layerId", layerId) .append("feature", feature).append("documentName", documentName) .append("begin", begin).append("end", end) .append("coveredText", coveredText).append("label", label) .append("uiLabel", uiLabel).append("confidence", confidence) .append("visible", isVisible()) .append("reasonForHiding", getReasonForHiding()).toString(); } }
private void writeLearningRecordInDatabaseAndEventLog( AnnotationSuggestion aCurrentRecommendation, LearningRecordType aUserAction) { writeLearningRecordInDatabaseAndEventLog(aCurrentRecommendation, aUserAction, aCurrentRecommendation.getLabel()); }