public class ExternalProcessItemScorerBuilder extends Object implements javax.inject.Provider<ItemScorer>
Build a PrecomputedItemScorer
using an external process. This class implements Provider
, but is not itself instantiable with dependency injection.
The external process can receive string arguments, as well as arguments derived from rating, user, and item DAOs. For DAOs, the contents of the DAO will be written to a file and that file will be provided on the command line.
The external process is expected to produce its scores on standard output in comma-separated user, item, score format.
Warning: if you use this code to build item scorers in the evaluator, be careful with the file-based caching (componentCacheDirectory). The cache will likely not rerun the external process.
Constructor and Description |
---|
ExternalProcessItemScorerBuilder() |
public ExternalProcessItemScorerBuilder setWorkingDir(File dir)
Set the working directory to use.
dir
- The working directory.public ExternalProcessItemScorerBuilder setWorkingDir(String dir)
Set the working directory to use.
dir
- The working directory.public ExternalProcessItemScorerBuilder setExecutable(String exe)
Set the executable to use.
exe
- The name or path of the executable to run.public ExternalProcessItemScorerBuilder addArgument(String arg)
Add a command line argument.
arg
- The argument to add.public ExternalProcessItemScorerBuilder addArguments(Collection<String> args)
Add some command line arguments.
args
- The arguments to add.public ExternalProcessItemScorerBuilder addArguments(String... args)
Add some command line arguments.
args
- The arguments to add.public ExternalProcessItemScorerBuilder addRatingFileArgument(EventDAO ratings, @Nullable String name)
Add a list of ratings as a command-line argument. The ratings will be provided as a CSV file in the format (user, item, rating, timestamp).
ratings
- A DAO of ratings to provide to the process. Only ratings will be considered.name
- A file name (optional). If provided, the ratings will be stored in this file name in the working directory; otherwise, a fresh name will be generated.public ExternalProcessItemScorerBuilder addRatingFileArgument(EventDAO ratings)
Add a list of ratings as a command-line argument. The ratings will be provided as a CSV file in the format (user, item, rating, timestamp).
ratings
- A DAO of ratings to provide to the process. Only ratings will be considered.public ExternalProcessItemScorerBuilder addItemFileArgument(ItemDAO items, @Nullable String name)
Add a list of items as a command-line argument. The items will be provided as a text file with one item per line.
items
- A DAO of items to provide to the process.name
- A file name (optional). If provided, the items will be stored in this file name in the working directory; otherwise, a fresh name will be generated.public ExternalProcessItemScorerBuilder addItemFileArgument(ItemDAO items)
Add a list of items as a command-line argument. The items will be provided as a CSV file in the format (user, item, item, timestamp).
items
- A DAO of items to provide to the process.public ExternalProcessItemScorerBuilder addUserFileArgument(UserDAO users, @Nullable String name)
Add a list of users as a command-line argument. The users will be provided as a text file with one user per line.
users
- A DAO of users to provide to the process.name
- A file name (optional). If provided, the users will be stored in this file name in the working directory; otherwise, a fresh name will be generated.public ExternalProcessItemScorerBuilder addUserFileArgument(UserDAO users)
Add a list of users as a command-line argument. The users will be provided as a text file with one user per line.
users
- A DAO of users to provide to the process.public ItemScorer build()
Build the item scorer.
public ItemScorer get()
get
in interface javax.inject.Provider<ItemScorer>