public abstract class AbstractScoringGreedyRerankStrategy extends java.lang.Object implements GreedyRerankStrategy
Abstract class designed to make implementation of a GreedyRerankStrategy easier. Implements a method of selecting the maximum scoring item that satisfies a constraint Has abstract methods for the method of choosing how many items to consider before returning the best candidate. note - While this class does have code for hard constraints, it is not a good option for implementing only a hard constraint, in those cases an AbstractFilteringGreedyRerankStrategy
should be used.
Constructor and Description |
---|
AbstractScoringGreedyRerankStrategy() |
Modifier and Type | Method and Description |
---|---|
protected int |
computeNumToInspect(int numRequested,
int numSelected,
int numCandidates)
A method to compute how many of the items in the list to inspect before returning the best item found so far.
|
Result |
nextItem(long userId,
int n,
java.util.List<? extends Result> items,
java.util.List<? extends Result> candidates)
A method to select the next item to be recommended.
|
protected boolean |
satisfiesConstraint(long userId,
int n,
java.util.List<? extends Result> items,
Result candidate)
Tests if adding the candidate item to the list of recommended items would satisfy a constraint.
|
protected abstract double |
scoreCandidate(long userId,
int n,
java.util.List<? extends Result> items,
Result candidate)
Computes an objective metric score for adding a given candidate item to a list of recommended items.
|
@Nullable public Result nextItem(long userId, int n, java.util.List<? extends Result> items, java.util.List<? extends Result> candidates)
GreedyRerankStrategy
A method to select the next item to be recommended. This method will be called many times in the process of generating recommendations. Therefore this method should consider optimzation options such as only searching a constant number of the candidates list before picking an item.
nextItem
in interface GreedyRerankStrategy
userId
- the id of the user receiving these recommendation.n
- the total number of items that will be recommended.items
- The list of items already chosen to be recommended in recommendation ordercandidates
- A ranked list of all items in the system that can still be recommended in this context. Given in ranking order (which is not strictly guaranteed to be in score order, but often will be).Result
object noting which candidate item should be added to the recommendation list. The object returned will be directly added to the result list, therefore implementations should use a custom Result subclass if there is any interesting information about the recommendation process to be returned. Alternatively, this method can return a null to indicate that there is no item that can be added to the list without violating a constraint and that the recommendation list should be prematurely terminated.protected abstract double scoreCandidate(long userId, int n, java.util.List<? extends Result> items, Result candidate)
Computes an objective metric score for adding a given candidate item to a list of recommended items. This method will only be called on items that satisfy the constraint.
userId
- the id of the user to recommend forn
- the number of recommended items requesteditems
- the list of items already chosen for recommendationcandidate
- the candidate item to recommendprotected boolean satisfiesConstraint(long userId, int n, java.util.List<? extends Result> items, Result candidate)
Tests if adding the candidate item to the list of recommended items would satisfy a constraint.
The default implementation returns true, effectively disabling the constraint by default.
userId
- the id of the user to recommend forn
- the number of recommended items requesteditems
- the list of items already chosen for recommendationcandidate
- the candidate item to recommendprotected int computeNumToInspect(int numRequested, int numSelected, int numCandidates)
A method to compute how many of the items in the list to inspect before returning the best item found so far. The default implementation searches the whole list. Override this method if you want to only search some prefix of the ranking order for an optimal item.
numRequested
- the number of items requested for recommendationnumSelected
- the number of items which have already been selectednumCandidates
- the number of items which can still be selected from