public abstract class AbstractFilteringGreedyRerankStrategy extends java.lang.Object implements GreedyRerankStrategy
Abstract class designed to make implementation of a GreedyRerankStrategy easier. Implements a method of selecting the first item that satisfies a constraint method. Has abstract methods for the method of choosing how many items to consider before returning the best candidate.
If you want items chosen based on optimizing some objective metric (or both an objective and a constraint) see: AbstractScoringGreedyRerankStrategy
.
Constructor and Description |
---|
AbstractFilteringGreedyRerankStrategy() |
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 abstract 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.
|
public AbstractFilteringGreedyRerankStrategy()
@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 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.
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