Skip to content

Commit

Permalink
#4990 - Non-trainable recommender may be invoked even though inherita…
Browse files Browse the repository at this point in the history
…ble predictions exist

- The inheritable annotations may be in the incoming predictions and not in the active predictions, so look at incoming first, if none are there, then look in active.
  • Loading branch information
reckart committed Aug 14, 2024
1 parent e2f4c4a commit 5798013
Showing 1 changed file with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ private Predictions generatePredictionsOnAllDocuments(List<SourceDocument> aDocu
var monitor = getMonitor();
var sessionOwner = getSessionOwner();
var project = getProject();
var activePredictions = isolated ? null
: recommendationService.getPredictions(sessionOwner, project);
var activePredictions = getPredecessorPredictions(sessionOwner, project);
var incomingPredictions = activePredictions != null ? new Predictions(activePredictions)
: new Predictions(sessionOwner, dataOwner, project);

Expand Down Expand Up @@ -260,14 +259,14 @@ private Predictions generatePredictionsOnSingleDocument(SourceDocument aCurrentD
{
var sessionOwner = getSessionOwner();
var project = getProject();
var activePredictions = isolated ? null
: recommendationService.getPredictions(sessionOwner, project);
var incomingPredictions = activePredictions != null ? new Predictions(activePredictions)
var predecessorPredictions = getPredecessorPredictions(sessionOwner, project);
var incomingPredictions = predecessorPredictions != null
? new Predictions(predecessorPredictions)
: new Predictions(sessionOwner, dataOwner, project);

aMonitor.setMaxProgress(1);

if (activePredictions != null) {
if (predecessorPredictions != null) {
// Limit prediction to a single document and inherit the rest
var documentsToInheritSuggestionsFor = aDocuments.stream() //
.filter(d -> !d.equals(currentDocument)) //
Expand All @@ -276,7 +275,7 @@ private Predictions generatePredictionsOnSingleDocument(SourceDocument aCurrentD
logPredictionStartedForOneDocumentWithInheritance(documentsToInheritSuggestionsFor);

for (var document : documentsToInheritSuggestionsFor) {
inheritSuggestionsAtDocumentLevel(project, document, activePredictions,
inheritSuggestionsAtDocumentLevel(project, document, predecessorPredictions,
incomingPredictions);
}
}
Expand All @@ -287,8 +286,8 @@ private Predictions generatePredictionsOnSingleDocument(SourceDocument aCurrentD
try (var casHolder = new PredictionCasHolder()) {

final CAS predictionCas = casHolder.cas;
applyAllRecommendersToDocument(activePredictions, incomingPredictions, predictionCas,
aCurrentDocument, predictionBegin, predictionEnd);
applyAllRecommendersToDocument(predecessorPredictions, incomingPredictions,
predictionCas, aCurrentDocument, predictionBegin, predictionEnd);
}
catch (ResourceInitializationException e) {
logErrorCreationPredictionCas(incomingPredictions);
Expand All @@ -299,6 +298,21 @@ private Predictions generatePredictionsOnSingleDocument(SourceDocument aCurrentD
return incomingPredictions;
}

private Predictions getPredecessorPredictions(User sessionOwner, Project project)
{
if (isolated) {
return null;
}

var incomingPredictions = recommendationService.getIncomingPredictions(sessionOwner,
project);
if (incomingPredictions != null) {
return incomingPredictions;
}

return recommendationService.getPredictions(sessionOwner, project);
}

/**
* @param aPredictions
* the predictions to populate
Expand Down

0 comments on commit 5798013

Please sign in to comment.