Author: srowen
Date: Fri Oct 24 09:01:39 2008
New Revision: 707666
URL: http://svn.apache.org/viewvc?rev=707666&view=rev
Log:
mahout-88 patch submission
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
URL:
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java?rev=707666&r1=707665&r2=707666&view=diff
==============================================================================
---
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
(original)
+++
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
Fri Oct 24 09:01:39 2008
@@ -52,6 +52,11 @@
* <p>This class is not intended for use with very large amounts of data
(over, say, a million rows). For
* that, a JDBC-backed [EMAIL PROTECTED] DataModel} and a database are more
appropriate.
* The file will be periodically reloaded if a change is detected.</p>
+ *
+ * <p>It is possible and likely useful to subclass this class and customize
its behavior to accommodate
+ * application-specific needs and input formats. See [EMAIL PROTECTED]
#processLine(String, Map)},
+ * [EMAIL PROTECTED] #buildItem(String)}, [EMAIL PROTECTED] #buildUser(String,
List)}
+ * and [EMAIL PROTECTED] #buildPreference(User, Item, double)}.</p>
*/
public class FileDataModel implements DataModel {
@@ -118,7 +123,24 @@
}
}
- private void processLine(String line, Map<String, List<Preference>> data) {
+ /**
+ * <p>Reads one line from the input file and adds the data to a [EMAIL
PROTECTED] Map} data structure
+ * which maps user IDs to preferences. This assumes that each line of the
input file
+ * corresponds to one preference. After reading a line and determining which
user and item
+ * the preference pertains to, the method should look to see if the data
contains a mapping
+ * for the user ID already, and if not, add an empty [EMAIL PROTECTED] List}
of [EMAIL PROTECTED] Preference}s to
+ * the data.</p>
+ *
+ * <p>The method should use [EMAIL PROTECTED] #buildItem(String)} to create
an [EMAIL PROTECTED] Item} representing
+ * the item in question if needed, and use [EMAIL PROTECTED]
#buildPreference(User, Item, double)} to
+ * build [EMAIL PROTECTED] Preference} objects as needed.</p>
+ *
+ * @param line line from input data file
+ * @param data all data read so far, as a mapping from user IDs to
preferences
+ * @see #buildPreference(User, Item, double)
+ * @see #buildItem(String)
+ */
+ protected void processLine(String line, Map<String, List<Preference>> data) {
int commaOne = line.indexOf((int) ',');
int commaTwo = line.indexOf((int) ',', commaOne + 1);
if (commaOne < 0 || commaTwo < 0) {
@@ -208,6 +230,9 @@
/**
* Subclasses may override to return a different [EMAIL PROTECTED] User}
implementation.
+ * The default implemenation always builds a new [EMAIL PROTECTED]
GenericUser}. This may not
+ * be desirable; it may be better to return an existing [EMAIL PROTECTED]
User} object
+ * in some applications rather than create a new object.
*
* @param id user ID
* @param prefs user preferences
@@ -219,6 +244,9 @@
/**
* Subclasses may override to return a different [EMAIL PROTECTED] Item}
implementation.
+ * The default implementation always builds a new [EMAIL PROTECTED]
GenericItem}; likewise
+ * it may be better here to return an existing object encapsulating the item
+ * instead.
*
* @param id item ID
* @return [EMAIL PROTECTED] GenericItem} by default
@@ -229,6 +257,7 @@
/**
* Subclasses may override to return a different [EMAIL PROTECTED]
Preference} implementation.
+ * The default implementation builds a new [EMAIL PROTECTED]
GenericPreference}.
*
* @param user [EMAIL PROTECTED] User} who expresses the preference
* @param item preferred [EMAIL PROTECTED] Item}