mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r765140 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/file/FileDataModel.java
Date Wed, 15 Apr 2009 11:30:32 GMT
Author: srowen
Date: Wed Apr 15 11:30:32 2009
New Revision: 765140

URL: http://svn.apache.org/viewvc?rev=765140&view=rev
Log:
Per conversation with Otis, make FileDataModel create BooleanPrefUser objects when BooleanPreference
objects are used

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=765140&r1=765139&r2=765140&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
Wed Apr 15 11:30:32 2009
@@ -21,11 +21,13 @@
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastMap;
 import org.apache.mahout.cf.taste.impl.common.FileLineIterable;
+import org.apache.mahout.cf.taste.impl.common.FastSet;
 import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
 import org.apache.mahout.cf.taste.impl.model.GenericItem;
 import org.apache.mahout.cf.taste.impl.model.GenericPreference;
 import org.apache.mahout.cf.taste.impl.model.GenericUser;
 import org.apache.mahout.cf.taste.impl.model.BooleanPreference;
+import org.apache.mahout.cf.taste.impl.model.BooleanPrefUser;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.Item;
 import org.apache.mahout.cf.taste.model.Preference;
@@ -351,9 +353,18 @@
    *
    * @param id user ID
    * @param prefs user preferences
-   * @return {@link GenericUser} by default
+   * @return {@link GenericUser} by default, or, a {@link BooleanPrefUser} if the prefs supplied
+   *  are in fact {@link BooleanPreference}s
    */
   protected User buildUser(String id, List<Preference> prefs) {
+    if (!prefs.isEmpty() || prefs.get(0) instanceof BooleanPreference) {
+      // If first is a BooleanPreference, assuming all are, so, want to use BooleanPrefUser
+      FastSet<Object> itemIDs = new FastSet<Object>(prefs.size());
+      for (Preference pref : prefs) {
+        itemIDs.add(pref.getItem().getID());
+      }
+      return new BooleanPrefUser<String>(id, itemIDs);
+    }
     return new GenericUser<String>(id, prefs);
   }
 



Mime
View raw message