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 2010/04/20 13:37:02 UTC
svn commit: r935877 -
/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
Author: srowen
Date: Tue Apr 20 11:37:01 2010
New Revision: 935877
URL: http://svn.apache.org/viewvc?rev=935877&view=rev
Log:
Changes for Ch 5 of the book -- handle null prefs
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java?rev=935877&r1=935876&r2=935877&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java Tue Apr 20 11:37:01 2010
@@ -51,7 +51,7 @@ import org.apache.mahout.cf.taste.model.
* </p>
*
* <p>
- * But, continue to use <code>realModel</code> as input to other components. To recommend, first construct and
+ * But, you may continue to use <code>realModel</code> as input to other components. To recommend, first construct and
* set the temporary user information on the model and then simply call the recommender. The
* <code>synchronized</code> block exists to remind you that this is of course not thread-safe. Only one set
* of temp data can be inserted into the model and used at one time.
@@ -66,6 +66,7 @@ import org.apache.mahout.cf.taste.model.
* PreferenceArray tempPrefs = ...;
* plusModel.setTempPrefs(tempPrefs);
* recommender.recommend(PlusAnonymousUserDataModel.TEMP_USER_ID, 10);
+ * plusModel.setTempPrefs(null);
* }
* </pre>
*
@@ -87,8 +88,10 @@ public final class PlusAnonymousUserData
public void setTempPrefs(PreferenceArray prefs) {
this.tempPrefs = prefs;
this.prefItemIDs.clear();
- for (int i = 0; i < prefs.length(); i++) {
- this.prefItemIDs.add(prefs.getItemID(i));
+ if (prefs != null) {
+ for (int i = 0; i < prefs.length(); i++) {
+ this.prefItemIDs.add(prefs.getItemID(i));
+ }
}
}