private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, LearningRecord aRecord) { return getMatchingSuggestion(aSuggestions, aRecord.getSourceDocument().getName(), aRecord.getLayer().getId(), aRecord.getAnnotationFeature().getName(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd(), aRecord.getAnnotation()); }
.executeUpdate(); LearningRecord record = new LearningRecord(); record.setUser(aUsername); 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); record.setChangeLocation(aLocation); record.setAnnotationFeature(aFeature);
private void setHighlight(LearningRecord aRecord) { LOG.trace("Active learning sidebar set highlight history record: {}", aRecord); highlightVID = null; highlightSpan = new Offset(aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); highlightDocumentName = aRecord.getSourceDocument().getName(); // This is a bit of hack. Consider the following case: // - use removes an ACCEPT history item // - user clicks then on another history item // - ... but during the subsequent rendering the "moveToNextSuggestion" method sets or // clears the highlight. protectHighlight = true; }
private Optional<AnnotationFS> getMatchingAnnotation(CAS aCas, LearningRecord aRecord) { Type type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName()); Feature feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName()); return selectAt(aCas, type, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()).stream() .filter(fs -> aRecord.getAnnotation().equals(fs.getFeatureValueAsString(feature))) .findFirst(); }
if (record.getOffsetCharacterBegin() == aSuggestion.getBegin() && record.getOffsetCharacterEnd() == aSuggestion.getEnd() && record.getAnnotation().equals(aSuggestion.getLabel())) switch (record.getUserAction()) { case REJECTED: aSuggestion.hide(FLAG_REJECTED);
if (asList(ACCEPTED, CORRECTED).contains(aRecord.getUserAction())) { JCas jCas = documentService.readAnnotationCas(aRecord.getSourceDocument(), aRecord.getUser()); if (getMatchingAnnotation(jCas.getCas(), aRecord).isPresent()) { actionShowSelectedDocument(aTarget, aRecord.getSourceDocument(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); confirmationDialog.setTitleModel(new StringResourceModel( "alSidebar.history.delete.confirmation.title", this));
@Override protected void populateItem(ListItem<LearningRecord> item) { LearningRecord rec = item.getModelObject(); AnnotationFeature recAnnotationFeature = rec.getAnnotationFeature(); String recFeatureValue; if (recAnnotationFeature != null) { FeatureSupport featureSupport = featureSupportRegistry .getFeatureSupport(recAnnotationFeature); recFeatureValue = featureSupport .renderFeatureValue(recAnnotationFeature, rec.getAnnotation()); } else { recFeatureValue = rec.getAnnotation(); } LambdaAjaxLink textLink = new LambdaAjaxLink(CID_JUMP_TO_ANNOTATION, _target -> actionSelectHistoryItem(_target, item.getModelObject())); textLink.setBody(rec::getTokenText); item.add(textLink); item.add(new Label(CID_RECOMMENDED_ANNOTATION, recFeatureValue)); item.add(new Label(CID_USER_ACTION, rec.getUserAction())); item.add( new LambdaAjaxLink(CID_REMOVE_RECORD, t -> actionRemoveHistoryItem(t, rec))); } };
private void deleteAnnotationByHistory(AjaxRequestTarget aTarget, LearningRecord aRecord) throws IOException, AnnotationException { AnnotatorState state = getModelObject(); JCas jCas = this.getJCasProvider().get(); Optional<AnnotationFS> anno = getMatchingAnnotation(jCas.getCas(), aRecord); if (anno.isPresent()) { state.getSelection().selectSpan(new VID(anno.get()), jCas, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); getActionHandler().actionDelete(aTarget); } }
.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); && SKIPPED.equals(record.getUserAction())) { s.hide(FLAG_SKIPPED);
if (asList(ACCEPTED, CORRECTED).contains(aRecord.getUserAction())) { JCas jCas = documentService.readAnnotationCas(aRecord.getSourceDocument(), aRecord.getUser()); if (getMatchingAnnotation(jCas.getCas(), aRecord).isPresent()) { actionShowSelectedDocument(aTarget, aRecord.getSourceDocument(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); confirmationDialog.setTitleModel(new StringResourceModel( "alSidebar.history.delete.confirmation.title", this));
private void setHighlight(LearningRecord aRecord) { LOG.trace("Active learning sidebar set highlight history record: {}", aRecord); highlightVID = null; highlightSpan = new Offset(aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); highlightDocumentName = aRecord.getSourceDocument().getName(); // This is a bit of hack. Consider the following case: // - use removes an ACCEPT history item // - user clicks then on another history item // - ... but during the subsequent rendering the "moveToNextSuggestion" method sets or // clears the highlight. protectHighlight = true; }
private Optional<AnnotationFS> getMatchingAnnotation(CAS aCas, LearningRecord aRecord) { Type type = CasUtil.getType(aCas, alStateModel.getObject().getLayer().getName()); Feature feature = type.getFeatureByBaseName(aRecord.getAnnotationFeature().getName()); return selectAt(aCas, type, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()).stream() .filter(fs -> aRecord.getAnnotation().equals(fs.getFeatureValueAsString(feature))) .findFirst(); }
@Override protected void populateItem(ListItem<LearningRecord> item) { LearningRecord rec = item.getModelObject(); AnnotationFeature recAnnotationFeature = rec.getAnnotationFeature(); String recFeatureValue; if (recAnnotationFeature != null) { FeatureSupport featureSupport = featureSupportRegistry .getFeatureSupport(recAnnotationFeature); recFeatureValue = featureSupport .renderFeatureValue(recAnnotationFeature, rec.getAnnotation()); } else { recFeatureValue = rec.getAnnotation(); } LambdaAjaxLink textLink = new LambdaAjaxLink(CID_JUMP_TO_ANNOTATION, _target -> actionSelectHistoryItem(_target, item.getModelObject())); textLink.setBody(rec::getTokenText); item.add(textLink); item.add(new Label(CID_RECOMMENDED_ANNOTATION, recFeatureValue)); item.add(new Label(CID_USER_ACTION, rec.getUserAction())); item.add( new LambdaAjaxLink(CID_REMOVE_RECORD, t -> actionRemoveHistoryItem(t, rec))); } };
private void deleteAnnotationByHistory(AjaxRequestTarget aTarget, LearningRecord aRecord) throws IOException, AnnotationException { AnnotatorState state = getModelObject(); JCas jCas = this.getJCasProvider().get(); Optional<AnnotationFS> anno = getMatchingAnnotation(jCas.getCas(), aRecord); if (anno.isPresent()) { state.getSelection().selectSpan(new VID(anno.get()), jCas, aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); getActionHandler().actionDelete(aTarget); } }
private List<AnnotationSuggestion> getMatchingSuggestion(List<SuggestionGroup> aSuggestions, LearningRecord aRecord) { return getMatchingSuggestion(aSuggestions, aRecord.getSourceDocument().getName(), aRecord.getLayer().getId(), aRecord.getAnnotationFeature().getName(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd(), aRecord.getAnnotation()); }
.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); && SKIPPED.equals(record.getUserAction())) { s.hide(FLAG_SKIPPED);
throws IOException actionShowSelectedDocument(aTarget, aRecord.getSourceDocument(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); setHighlight(aRecord.getSourceDocument(), annotation.get());
@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; }
throws IOException actionShowSelectedDocument(aTarget, aRecord.getSourceDocument(), aRecord.getOffsetCharacterBegin(), aRecord.getOffsetCharacterEnd()); setHighlight(aRecord.getSourceDocument(), annotation.get());
@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; }