mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r956957 - in /mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: impl/model/GenericBooleanPrefDataModel.java impl/model/GenericDataModel.java model/DataModel.java
Date Tue, 22 Jun 2010 17:16:24 GMT
Author: srowen
Date: Tue Jun 22 17:16:24 2010
New Revision: 956957

URL: http://svn.apache.org/viewvc?rev=956957&view=rev
Log:
MAHOUT-423

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java?rev=956957&r1=956956&r2=956957&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericBooleanPrefDataModel.java
Tue Jun 22 17:16:24 2010
@@ -217,26 +217,42 @@ public final class GenericBooleanPrefDat
   }
   
   @Override
-  public int getNumUsersWithPreferenceFor(long... itemIDs) throws NoSuchItemException {
-    if (itemIDs.length == 0) {
+  public int getNumUsersWithPreferenceFor(long... itemIDs) {
+    if (itemIDs == null || itemIDs.length == 0) {
+      throw new IllegalArgumentException("itemIDs is null or empty");
+    }
+    FastIDSet userIDs1 = preferenceForItems.get(itemIDs[0]);
+    if (userIDs1 == null) {
       return 0;
     }
-    FastIDSet userIDs = preferenceForItems.get(itemIDs[0]);
-    if (userIDs == null) {
-      throw new NoSuchItemException();
+
+    if (itemIDs.length == 1) {
+      return userIDs1.size();
     }
-    FastIDSet intersection = new FastIDSet(userIDs.size());
-    intersection.addAll(userIDs);
+    
+    if (itemIDs.length == 2) {
+      FastIDSet userIDs2 = preferenceForItems.get(itemIDs[1]);
+      if (userIDs2 == null) {
+        return 0;
+      }
+      return userIDs1.intersectionSize(userIDs2);
+    }
+
+    /*
+    FastIDSet intersection = new FastIDSet(userIDs1.size());
+    intersection.addAll(userIDs1);
     int i = 1;
     while (!intersection.isEmpty() && (i < itemIDs.length)) {
-      userIDs = preferenceForItems.get(itemIDs[i]);
-      if (userIDs == null) {
-        throw new NoSuchItemException();
+      userIDs1 = preferenceForItems.get(itemIDs[i]);
+      if (userIDs1 == null) {
+        return 0;
       }
-      intersection.retainAll(userIDs);
+      intersection.retainAll(userIDs1);
       i++;
     }
     return intersection.size();
+     */
+    throw new IllegalArgumentException("Illegal number of item IDs: " + itemIDs.length);
   }
   
   @Override

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java?rev=956957&r1=956956&r2=956957&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/GenericDataModel.java
Tue Jun 22 17:16:24 2010
@@ -235,20 +235,21 @@ public final class GenericDataModel exte
   
   @Override
   public int getNumUsersWithPreferenceFor(long... itemIDs) {
-    if (itemIDs == null) {
-      throw new IllegalArgumentException("itemIDs is null");
+    if (itemIDs == null || itemIDs.length == 0) {
+      throw new IllegalArgumentException("itemIDs is null or empty");
     }
-    int length = itemIDs.length;
-    if ((length == 0) || (length > 2)) {
-      throw new IllegalArgumentException("Illegal number of item IDs: " + length);
-    }
-    if (length == 1) {
-      PreferenceArray prefs = preferenceForItems.get(itemIDs[0]);
-      return prefs == null ? 0 : prefs.length();
-    } else {
-      PreferenceArray prefs1 = preferenceForItems.get(itemIDs[0]);
+    PreferenceArray prefs1 = preferenceForItems.get(itemIDs[0]);
+    if (prefs1 == null) {
+      return 0;
+    }
+
+    if (itemIDs.length == 1) {
+      return prefs1.length();
+    }
+
+    if (itemIDs.length == 2) {
       PreferenceArray prefs2 = preferenceForItems.get(itemIDs[1]);
-      if ((prefs1 == null) || (prefs2 == null)) {
+      if (prefs2 == null) {
         return 0;
       }
       FastIDSet users1 = new FastIDSet(prefs1.length());
@@ -264,6 +265,8 @@ public final class GenericDataModel exte
       users1.retainAll(users2);
       return users1.size();
     }
+
+    throw new IllegalArgumentException("Illegal number of item IDs: " + itemIDs.length);
   }
   
   @Override

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java?rev=956957&r1=956956&r2=956957&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/DataModel.java Tue Jun
22 17:16:24 2010
@@ -110,16 +110,12 @@ public interface DataModel extends Refre
   int getNumUsers() throws TasteException;
   
   /**
-   * @param itemIDs
-   *          item IDs to check for
+   * @param itemIDs item IDs to check for
    * @return the number of users who have expressed a preference for all of the items
-   * @throws TasteException
-   *           if an error occurs while accessing the data
+   * @throws TasteException if an error occurs while accessing the data
    * @throws IllegalArgumentException
-   *           if itemIDs is null, empty, or larger than 2 elements since currently only
queries of up to 2
-   *           items are needed and supported
-   * @throws org.apache.mahout.cf.taste.common.NoSuchItemException
-   *           if an item does not exist
+   *  if itemIDs is null or empty. Arguments larger than 2 elements are not necessarily supported
+   *  and may result in this exception
    */
   int getNumUsersWithPreferenceFor(long... itemIDs) throws TasteException;
   



Mime
View raw message