org.grouplens.lenskit.external

## Class ExternalProcessItemScorerBuilder

• java.lang.Object
• org.grouplens.lenskit.external.ExternalProcessItemScorerBuilder
• All Implemented Interfaces:
javax.inject.Provider<ItemScorer>

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.

Since:
2.1
• ### Constructor Summary

Constructors
Constructor and Description
ExternalProcessItemScorerBuilder()
• ### Method Summary

All Methods
Modifier and Type Method and Description
ExternalProcessItemScorerBuilder addArgument(String arg)
Add a command line argument.
ExternalProcessItemScorerBuilder addArguments(Collection<String> args)
Add some command line arguments.
ExternalProcessItemScorerBuilder addArguments(String... args)
Add some command line arguments.
ExternalProcessItemScorerBuilder addItemFileArgument(ItemDAO items)
Add a list of items as a command-line argument.
ExternalProcessItemScorerBuilder addItemFileArgument(ItemDAO items, String name)
Add a list of items as a command-line argument.
ExternalProcessItemScorerBuilder addRatingFileArgument(EventDAO ratings)
Add a list of ratings as a command-line argument.
ExternalProcessItemScorerBuilder addRatingFileArgument(EventDAO ratings, String name)
Add a list of ratings as a command-line argument.
ExternalProcessItemScorerBuilder addUserFileArgument(UserDAO users)
Add a list of users as a command-line argument.
ExternalProcessItemScorerBuilder addUserFileArgument(UserDAO users, String name)
Add a list of users as a command-line argument.
ItemScorer build()
Build the item scorer.
ItemScorer get()
ExternalProcessItemScorerBuilder setExecutable(String exe)
Set the executable to use.
ExternalProcessItemScorerBuilder setWorkingDir(File dir)
Set the working directory to use.
ExternalProcessItemScorerBuilder setWorkingDir(String dir)
Set the working directory to use.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### ExternalProcessItemScorerBuilder

public ExternalProcessItemScorerBuilder()
• ### Method Detail

• #### setWorkingDir

public ExternalProcessItemScorerBuilder setWorkingDir(File dir)
Set the working directory to use.
Parameters:
dir - The working directory.
Returns:
The builder (for chaining).
• #### setWorkingDir

public ExternalProcessItemScorerBuilder setWorkingDir(String dir)
Set the working directory to use.
Parameters:
dir - The working directory.
Returns:
The builder (for chaining).
• #### setExecutable

public ExternalProcessItemScorerBuilder setExecutable(String exe)
Set the executable to use.
Parameters:
exe - The name or path of the executable to run.
Returns:
The builder (for chaining).

public ExternalProcessItemScorerBuilder addArgument(String arg)
Add a command line argument.
Parameters:
arg - The argument to add.
Returns:
The builder (for chaining).

public ExternalProcessItemScorerBuilder addArguments(Collection<String> args)
Add some command line arguments.
Parameters:
args - The arguments to add.
Returns:
The builder (for chaining).

public ExternalProcessItemScorerBuilder addArguments(String... args)
Add some command line arguments.
Parameters:
args - The arguments to add.
Returns:
The builder (for chaining).

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).
Parameters:
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.
Returns:
The builder (for chaining).

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).
Parameters:
ratings - A DAO of ratings to provide to the process. Only ratings will be considered.
Returns:
The builder (for chaining).

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.
Parameters:
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.
Returns:
The builder (for chaining).

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).
Parameters:
items - A DAO of items to provide to the process.
Returns:
The builder (for chaining).

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.
Parameters:
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.
Returns:
The builder (for chaining).

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.
Parameters:
users - A DAO of users to provide to the process.
Returns:
The builder (for chaining).
• #### build

public ItemScorer build()
Build the item scorer.
Returns:
An item scorer that will return the scores provided by the external algorithm.
• #### get

public ItemScorer get()
Specified by:
get in interface javax.inject.Provider<ItemScorer>