Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/4158-Exception-when-annotating-someth…
Browse files Browse the repository at this point in the history
…ing-after-a-longer-pause

* main:
  #4150 - Upgrade dependencies
  #4155 - Better annotation suggestion IDs
  #4155 - Better annotation suggestion IDs
  #4150 - Upgrade dependencies
  #4150 - Upgrade dependencies
  #1861 - Add viewport offsets to external recommender
  #4155 - Better annotation suggestion IDs
  #4155 - Better annotation suggestion IDs
  #4139 - Reusable popover component for annotation editors
  #4139 - Reusable popover component for annotation editors
  #4139 - Reusable popover component for annotation editors
  Issue #4148: Switch PDF editor to compact model v2
  #4139 - Reusable popover component for annotation editors
  Issue #4139: Reusable popover component for annotation editors
  #4140 - Simplify lazy detail lookup
  Issue #4139: Reusable popover component for annotation editors
  No issue. Set version to 30.0-SNAPSHOT

% Conflicts:
%	Jenkinsfile
%	inception/inception-active-learning/src/main/java/de/tudarmstadt/ukp/inception/active/learning/sidebar/ActiveLearningSidebar.java
%	inception/inception-brat-editor/src/main/ts/src/annotator_ui/ResizeManager.ts
  • Loading branch information
reckart committed Sep 2, 2023
2 parents d98af44 + ec95327 commit 3584db3
Show file tree
Hide file tree
Showing 273 changed files with 9,693 additions and 9,024 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
config = [
agentLabel: '',
maven: 'Maven 3',
jdk: 'Zulu 11',
jdk: 'Zulu 17',
extraMavenArguments: '-U -Ddkpro.core.testCachePath="${WORKSPACE}/cache/dkpro-core-datasets" -Dmaven.artifact.threads=15',
wipeWorkspaceBeforeBuild: true,
wipeWorkspaceAfterBuild: true
Expand Down
2 changes: 1 addition & 1 deletion inception/inception-active-learning/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>de.tudarmstadt.ukp.inception.app</groupId>
<artifactId>inception-app</artifactId>
<version>29.1-SNAPSHOT</version>
<version>30.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>inception-active-learning</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument;
import de.tudarmstadt.ukp.clarin.webanno.security.model.User;
import de.tudarmstadt.ukp.inception.active.learning.ActiveLearningServiceImpl.ActiveLearningUserState;
import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecord;
import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecordType;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionGroup;
Expand All @@ -44,15 +43,6 @@ public interface ActiveLearningService
*/
List<SuggestionGroup<SpanSuggestion>> getSuggestions(User aDataOwner, AnnotationLayer aLayer);

/**
* @param aRecord
* record to check
* @return if the suggestions from which the given record was created (or an equivalent one) is
* visible to the user. This is useful to check if the suggestion can be highlighted
* when clicking on a history record.
*/
boolean isSuggestionVisible(LearningRecord aRecord);

/**
* @return if the are any records of type {@link LearningRecordType#SKIPPED} in the history of
* the given layer for the given user.
Expand All @@ -64,8 +54,8 @@ public interface ActiveLearningService
*/
boolean hasSkippedSuggestions(String aSessionOwner, User aDataOwner, AnnotationLayer aLayer);

void hideRejectedOrSkippedAnnotations(String aSessionOwner, User aDataOwner, AnnotationLayer aLayer,
boolean aFilterSkippedRecommendation,
void hideRejectedOrSkippedAnnotations(String aSessionOwner, User aDataOwner,
AnnotationLayer aLayer, boolean aFilterSkippedRecommendation,
List<SuggestionGroup<SpanSuggestion>> aSuggestionGroups);

Optional<Delta<SpanSuggestion>> generateNextSuggestion(String aSessionOwner, User aDataOwner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

import java.io.IOException;
import java.io.Serializable;
import java.lang.invoke.MethodHandles;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.slf4j.Logger;
Expand All @@ -49,10 +49,7 @@
import de.tudarmstadt.ukp.inception.recommendation.api.LearningRecordService;
import de.tudarmstadt.ukp.inception.recommendation.api.RecommendationService;
import de.tudarmstadt.ukp.inception.recommendation.api.model.AnnotationSuggestion;
import de.tudarmstadt.ukp.inception.recommendation.api.model.LearningRecord;
import de.tudarmstadt.ukp.inception.recommendation.api.model.Predictions;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SpanSuggestion;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionDocumentGroup;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionGroup;
import de.tudarmstadt.ukp.inception.recommendation.api.model.SuggestionGroup.Delta;
import de.tudarmstadt.ukp.inception.schema.AnnotationSchemaService;
Expand All @@ -68,7 +65,7 @@
public class ActiveLearningServiceImpl
implements ActiveLearningService
{
private final Logger log = LoggerFactory.getLogger(getClass());
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final ApplicationEventPublisher applicationEventPublisher;
private final DocumentService documentService;
Expand Down Expand Up @@ -97,39 +94,20 @@ public ActiveLearningServiceImpl(DocumentService aDocumentService,
@Override
public List<SuggestionGroup<SpanSuggestion>> getSuggestions(User aUser, AnnotationLayer aLayer)
{
Predictions predictions = recommendationService.getPredictions(aUser, aLayer.getProject());
var predictions = recommendationService.getPredictions(aUser, aLayer.getProject());

if (predictions == null) {
return emptyList();
}

Map<String, SuggestionDocumentGroup<SpanSuggestion>> recommendationsMap = predictions
.getPredictionsForWholeProject(SpanSuggestion.class, aLayer, documentService);
var recommendationsMap = predictions.getPredictionsForWholeProject(SpanSuggestion.class,
aLayer, documentService);

return recommendationsMap.values().stream() //
.flatMap(docMap -> docMap.stream()) //
.collect(toList());
}

@Override
public boolean isSuggestionVisible(LearningRecord aRecord)
{
var aSessionOwner = userService.get(aRecord.getUser());
var suggestionGroups = getSuggestions(aSessionOwner, aRecord.getLayer());
for (var suggestionGroup : suggestionGroups) {
if (suggestionGroup.stream().anyMatch(suggestion -> suggestion.getDocumentName()
.equals(aRecord.getSourceDocument().getName())
&& suggestion.getFeature().equals(aRecord.getAnnotationFeature().getName())
&& suggestion.labelEquals(aRecord.getAnnotation())
&& suggestion.getBegin() == aRecord.getOffsetBegin()
&& suggestion.getEnd() == aRecord.getOffsetEnd() //
&& suggestion.isVisible())) {
return true;
}
}
return false;
}

@Override
public boolean hasSkippedSuggestions(String aSessionOwner, User aDataOwner,
AnnotationLayer aLayer)
Expand Down Expand Up @@ -174,27 +152,31 @@ public Optional<Delta<SpanSuggestion>> generateNextSuggestion(String aSessionOwn
long startTimer = System.currentTimeMillis();
var suggestionGroups = alState.getSuggestions();
long getRecommendationsFromRecommendationService = System.currentTimeMillis();
log.trace("Getting recommendations from recommender system took {} ms.",
LOG.trace("Getting recommendations from recommender system took {} ms.",
(getRecommendationsFromRecommendationService - startTimer));

// remove duplicate recommendations
suggestionGroups = suggestionGroups.stream() //
.map(it -> removeDuplicateRecommendations(it)) //
.collect(toList());
long removeDuplicateRecommendation = System.currentTimeMillis();
log.trace("Removing duplicate recommendations took {} ms.",
(removeDuplicateRecommendation - getRecommendationsFromRecommendationService));

// hide rejected recommendations
hideRejectedOrSkippedAnnotations(aSessionOwner, aDataOwner, alState.getLayer(), true,
suggestionGroups);
long removeRejectedSkippedRecommendation = System.currentTimeMillis();
log.trace("Removing rejected or skipped ones took {} ms.",
(removeRejectedSkippedRecommendation - removeDuplicateRecommendation));
LOG.trace("Hiding rejected or skipped ones took {} ms.",
(removeRejectedSkippedRecommendation
- getRecommendationsFromRecommendationService));

// remove duplicate recommendations
suggestionGroups = suggestionGroups.stream() //
.map(it -> removeDuplicatesAndHiddenSuggestions(it)) //
.filter(it -> !it.isEmpty()) //
.collect(toList());
long removeDuplicateRecommendation = System.currentTimeMillis();
LOG.trace("Removing duplicate recommendations took {} ms.",
(removeDuplicateRecommendation - removeRejectedSkippedRecommendation));

var pref = recommendationService.getPreferences(aDataOwner,
alState.getLayer().getProject());
return alState.getStrategy().generateNextSuggestion(pref, suggestionGroups);
var nextSuggestion = alState.getStrategy().generateNextSuggestion(pref, suggestionGroups);
assert nextSuggestion.get().getFirst().isVisible() : "Generated suggestion must be visible";
return nextSuggestion;
}

@Override
Expand Down Expand Up @@ -296,35 +278,40 @@ public void skipSpanSuggestion(String aSessionOwner, User aDataOwner, Annotation
alternativeSuggestions));
}

private static SuggestionGroup<SpanSuggestion> removeDuplicateRecommendations(
SuggestionGroup<SpanSuggestion> unmodifiedRecommendationList)
private static SuggestionGroup<SpanSuggestion> removeDuplicatesAndHiddenSuggestions(
SuggestionGroup<SpanSuggestion> aSuggestionGroup)
{
SuggestionGroup<SpanSuggestion> cleanRecommendationList = new SuggestionGroup<>();
var cleanSuggestionGroup = new SuggestionGroup<SpanSuggestion>();

unmodifiedRecommendationList.forEach(recommendationItem -> {
if (!isAlreadyInCleanList(cleanRecommendationList, recommendationItem)) {
cleanRecommendationList.add(recommendationItem);
aSuggestionGroup.forEach(suggestion -> {
if (!suggestion.isVisible()) {
return;
}

if (!isAlreadyInCleanList(cleanSuggestionGroup, suggestion)) {
cleanSuggestionGroup.add(suggestion);
}
});

return cleanRecommendationList;
return cleanSuggestionGroup;
}

private static boolean isAlreadyInCleanList(
SuggestionGroup<SpanSuggestion> cleanRecommendationList,
AnnotationSuggestion recommendationItem)
{
String source = recommendationItem.getRecommenderName();
String annotation = recommendationItem.getLabel();
String documentName = recommendationItem.getDocumentName();
var source = recommendationItem.getRecommenderName();
var annotation = recommendationItem.getLabel();
var documentName = recommendationItem.getDocumentName();

for (AnnotationSuggestion existingRecommendation : cleanRecommendationList) {
boolean areLabelsEqual = existingRecommendation.labelEquals(annotation);
for (var existingRecommendation : cleanRecommendationList) {
var areLabelsEqual = existingRecommendation.labelEquals(annotation);
if (existingRecommendation.getRecommenderName().equals(source) && areLabelsEqual
&& existingRecommendation.getDocumentName().equals(documentName)) {
return true;
}
}

return false;
}

Expand Down
Loading

0 comments on commit 3584db3

Please sign in to comment.