You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2008/10/24 18:01:40 UTC
svn commit: r707666 -
/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
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 {@link 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 {@link #processLine(String, Map)},
+ * {@link #buildItem(String)}, {@link #buildUser(String, List)}
+ * and {@link #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 {@link 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 {@link List} of {@link Preference}s to
+ * the data.</p>
+ *
+ * <p>The method should use {@link #buildItem(String)} to create an {@link Item} representing
+ * the item in question if needed, and use {@link #buildPreference(User, Item, double)} to
+ * build {@link 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 {@link User} implementation.
+ * The default implemenation always builds a new {@link GenericUser}. This may not
+ * be desirable; it may be better to return an existing {@link 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 {@link Item} implementation.
+ * The default implementation always builds a new {@link GenericItem}; likewise
+ * it may be better here to return an existing object encapsulating the item
+ * instead.
*
* @param id item ID
* @return {@link GenericItem} by default
@@ -229,6 +257,7 @@
/**
* Subclasses may override to return a different {@link Preference} implementation.
+ * The default implementation builds a new {@link GenericPreference}.
*
* @param user {@link User} who expresses the preference
* @param item preferred {@link Item}