mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r964366 - in /mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model: PlusAnonymousUserDataModel.java jdbc/AbstractJDBCDataModel.java
Date Thu, 15 Jul 2010 10:14:04 GMT
Author: srowen
Date: Thu Jul 15 10:14:04 2010
New Revision: 964366

URL: http://svn.apache.org/viewvc?rev=964366&view=rev
Log:
Avoid problem when anonymous user has item that is not in the model. Make sure JDBC models
do throw an exception for unknown items

Modified:
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java?rev=964366&r1=964365&r2=964366&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/PlusAnonymousUserDataModel.java
Thu Jul 15 10:14:04 2010
@@ -19,6 +19,7 @@ package org.apache.mahout.cf.taste.impl.
 
 import java.util.Collection;
 
+import org.apache.mahout.cf.taste.common.NoSuchItemException;
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
@@ -124,10 +125,15 @@ public final class PlusAnonymousUserData
   
   @Override
   public PreferenceArray getPreferencesForItem(long itemID) throws TasteException {
-    PreferenceArray delegatePrefs = delegate.getPreferencesForItem(itemID);
+    PreferenceArray delegatePrefs = null;
+    try {
+      delegatePrefs = delegate.getPreferencesForItem(itemID);
+    } catch (NoSuchItemException nsie) {
+      // OK. Probably an item that only the anonymous user has
+    }
     for (int i = 0; i < tempPrefs.length(); i++) {
       if (tempPrefs.getItemID(i) == itemID) {
-        int length = delegatePrefs.length();
+        int length = delegatePrefs == null ? 0 : delegatePrefs.length();
         PreferenceArray newPreferenceArray = new GenericItemPreferenceArray(length + 1);
         for (int j = 0; j < length; j++) {
           newPreferenceArray.setUserID(j, delegatePrefs.getUserID(j));
@@ -141,6 +147,10 @@ public final class PlusAnonymousUserData
         return newPreferenceArray;
       }
     }
+    if (delegatePrefs == null) {
+      // No, didn't find it among the anonymous user prefs
+      throw new NoSuchItemException();
+    }
     return delegatePrefs;
   }
   
@@ -156,7 +166,7 @@ public final class PlusAnonymousUserData
     }
     return delegate.getPreferenceValue(userID, itemID);
   }
-  
+
   @Override
   public int getNumItems() throws TasteException {
     return delegate.getNumItems();

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java?rev=964366&r1=964365&r2=964366&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
(original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
Thu Jul 15 10:14:04 2010
@@ -29,6 +29,7 @@ import java.util.NoSuchElementException;
 
 import javax.sql.DataSource;
 
+import org.apache.mahout.cf.taste.common.NoSuchItemException;
 import org.apache.mahout.cf.taste.common.NoSuchUserException;
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
@@ -75,13 +76,15 @@ public abstract class AbstractJDBCDataMo
   public static final String DEFAULT_USER_ID_COLUMN = "user_id";
   public static final String DEFAULT_ITEM_ID_COLUMN = "item_id";
   public static final String DEFAULT_PREFERENCE_COLUMN = "preference";
-  
+  public static final String DEFAULT_PREFERENCE_TIME_COLUMN = "timestamp";
+
   private final DataSource dataSource;
   private final String preferenceTable;
   private final String userIDColumn;
   private final String itemIDColumn;
   private final String preferenceColumn;
   private final String getPreferenceSQL;
+  private final String getPreferenceTimeSQL;
   private final String getUserSQL;
   private final String getAllUsersSQL;
   private final String getNumItemsSQL;
@@ -442,7 +445,7 @@ public abstract class AbstractJDBCDataMo
       IOUtils.quietClose(rs, stmt, conn);
     }
   }
-  
+
   @Override
   public LongPrimitiveIterator getItemIDs() throws TasteException {
     log.debug("Retrieving all items...");
@@ -452,6 +455,9 @@ public abstract class AbstractJDBCDataMo
   @Override
   public PreferenceArray getPreferencesForItem(long itemID) throws TasteException {
     List<Preference> list = doGetPreferencesForItem(itemID);
+    if (list.isEmpty()) {
+      throw new NoSuchItemException();
+    }
     return new GenericItemPreferenceArray(list);
   }
   



Mime
View raw message