public class ExternalProcessItemScorerBuilder extends java.lang.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() |
Modifier and Type | Method and Description |
---|---|
ExternalProcessItemScorerBuilder |
addArgument(java.lang.String arg)
Add a command line argument.
|
ExternalProcessItemScorerBuilder |
addArguments(java.util.Collection<java.lang.String> args)
Add some command line arguments.
|
ExternalProcessItemScorerBuilder |
addArguments(java.lang.String... args)
Add some command line arguments.
|
ExternalProcessItemScorerBuilder |
addItemFileArgument(LongSet items)
Add a list of items as a command-line argument.
|
ExternalProcessItemScorerBuilder |
addItemFileArgument(LongSet items,
java.lang.String name)
Add a list of items as a command-line argument.
|
ExternalProcessItemScorerBuilder |
addRatingFileArgument(DataAccessObject dao)
Add a list of ratings as a command-line argument.
|
ExternalProcessItemScorerBuilder |
addRatingFileArgument(DataAccessObject dao,
java.lang.String name)
Add a list of ratings as a command-line argument.
|
ExternalProcessItemScorerBuilder |
addUserFileArgument(LongSet users)
Add a list of users as a command-line argument.
|
ExternalProcessItemScorerBuilder |
addUserFileArgument(LongSet users,
java.lang.String name)
Add a list of users as a command-line argument.
|
PrecomputedItemScorer |
build()
Build the item scorer.
|
ItemScorer |
get() |
ExternalProcessItemScorerBuilder |
setExecutable(java.lang.String exe)
Set the executable to use.
|
ExternalProcessItemScorerBuilder |
setWorkingDir(java.io.File dir)
Set the working directory to use.
|
ExternalProcessItemScorerBuilder |
setWorkingDir(java.lang.String dir)
Set the working directory to use.
|
public ExternalProcessItemScorerBuilder setWorkingDir(java.io.File dir)
Set the working directory to use.
dir
- The working directory.public ExternalProcessItemScorerBuilder setWorkingDir(java.lang.String dir)
Set the working directory to use.
dir
- The working directory.public ExternalProcessItemScorerBuilder setExecutable(java.lang.String exe)
Set the executable to use.
exe
- The name or path of the executable to run.public ExternalProcessItemScorerBuilder addArgument(java.lang.String arg)
Add a command line argument.
arg
- The argument to add.public ExternalProcessItemScorerBuilder addArguments(java.util.Collection<java.lang.String> args)
Add some command line arguments.
args
- The arguments to add.public ExternalProcessItemScorerBuilder addArguments(java.lang.String... args)
Add some command line arguments.
args
- The arguments to add.public ExternalProcessItemScorerBuilder addRatingFileArgument(DataAccessObject dao, @Nullable java.lang.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).
dao
- 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(DataAccessObject dao)
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).
dao
- A DAO of ratings to provide to the process. Only ratings will be considered.public ExternalProcessItemScorerBuilder addItemFileArgument(LongSet items, @Nullable java.lang.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(LongSet 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(LongSet users, @Nullable java.lang.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(LongSet 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 PrecomputedItemScorer build()
Build the item scorer.
public ItemScorer get()
get
in interface javax.inject.Provider<ItemScorer>