Author: srowen
Date: Thu Apr  1 14:25:28 2010
New Revision: 929988

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

Modified:
    
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java
    
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java
    
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java
    
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java

Modified: 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java
URL: 
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java?rev=929988&r1=929987&r2=929988&view=diff
==============================================================================
--- 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java
 (original)
+++ 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderMapper.java
 Thu Apr  1 14:25:28 2010
@@ -116,7 +116,9 @@ public final class RecommenderMapper ext
           throw new IOException(te.getCause());
         }
       }
-      columnVector.times(value).addTo(recommendationVector);
+      if (columnVector != null) {
+        columnVector.times(value).addTo(recommendationVector);
+      }
     }
     
     Queue<RecommendedItem> topItems = new 
PriorityQueue<RecommendedItem>(recommendationsPerUser + 1,
@@ -171,11 +173,11 @@ public final class RecommenderMapper ext
         throw new TasteException(ioe);
       }
       if (writable == null) {
-        throw new TasteException("Could not load column vector from map 
files");
+        return null;
       }
       Vector value = writable.get();
       if (value == null) {
-        throw new TasteException("Vector in map file was empty?");
+        throw new IllegalStateException("Vector in map file was empty?");
       }
       columnVector = new VectorWritable();
       columnVector.set(new RandomAccessSparseVector(Integer.MAX_VALUE, 1000));

Modified: 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java
URL: 
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java?rev=929988&r1=929987&r2=929988&view=diff
==============================================================================
--- 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java
 (original)
+++ 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Cache.java
 Thu Apr  1 14:25:28 2010
@@ -27,7 +27,7 @@ import org.apache.mahout.cf.taste.common
  * </p>
  * 
  * <p>
- * The cache does not support <code>null</code> values or keys.
+ * The cache does not support <code>null</code> keys.
  * </p>
  * 
  * <p>
@@ -36,6 +36,8 @@ import org.apache.mahout.cf.taste.common
  * </p>
  */
 public final class Cache<K,V> implements Retriever<K,V> {
+
+  private static final Object NULL = new Object();
   
   private final FastMap<K,V> cache;
   private final Retriever<? super K,? extends V> retriever;
@@ -93,7 +95,7 @@ public final class Cache<K,V> implements
     if (value == null) {
       return getAndCacheValue(key);
     }
-    return value;
+    return value == NULL ? null : value;
   }
   
   /**
@@ -124,7 +126,7 @@ public final class Cache<K,V> implements
   private V getAndCacheValue(K key) throws TasteException {
     V value = retriever.get(key);
     synchronized (cache) {
-      cache.put(key, value);
+      cache.put(key, value == null ? (V) NULL : value);
     }
     return value;
   }

Modified: 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java
URL: 
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java?rev=929988&r1=929987&r2=929988&view=diff
==============================================================================
--- 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java
 (original)
+++ 
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/common/Retriever.java
 Thu Apr  1 14:25:28 2010
@@ -27,11 +27,9 @@ import org.apache.mahout.cf.taste.common
 public interface Retriever<K,V> {
   
   /**
-   * @param key
-   *          key for which a value should be retrieved
-   * @return value for key. Implementations should not return null.
-   * @throws TasteException
-   *           if an error occurs while retrieving the value
+   * @param key key for which a value should be retrieved
+   * @return value for key
+   * @throws TasteException if an error occurs while retrieving the value
    */
   V get(K key) throws TasteException;
   

Modified: 
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
URL: 
http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java?rev=929988&r1=929987&r2=929988&view=diff
==============================================================================
--- 
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
 (original)
+++ 
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/common/CacheTest.java
 Thu Apr  1 14:25:28 2010
@@ -52,9 +52,6 @@ public final class CacheTest extends Tas
   private static class IdentityRetriever implements Retriever<Object,Object> {
     @Override
     public Object get(Object key) throws TasteException {
-      if (key == null) {
-        throw new TasteException("key is null");
-      }
       return key;
     }
   }


Reply via email to