mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r1592656 - in /mahout/trunk: ./ examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/ examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/ examples/src/main/java/org/apache/mahout/cf/taste/example/kddcu...
Date Tue, 06 May 2014 05:01:52 GMT
Author: ssc
Date: Tue May  6 05:01:51 2014
New Revision: 1592656

URL: http://svn.apache.org/r1592656
Log:
MAHOUT-1428 Recommending already consumed items

Modified:
    mahout/trunk/CHANGELOG
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingBooleanRecommender.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Recommender.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Recommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractCandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllSimilarItemsCandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/CandidateItemsStrategy.java
    mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategyTest.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/MockRecommender.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategyTest.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategyTest.java
    mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommenderTest.java

Modified: mahout/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/mahout/trunk/CHANGELOG?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/CHANGELOG (original)
+++ mahout/trunk/CHANGELOG Tue May  6 05:01:51 2014
@@ -2,6 +2,8 @@ Mahout Change Log
 
 Release 1.0 - unreleased
 
+  MAHOUT-1428: Recommending already consumed items (Dodi Hakim via ssc)
+
   MAHOUT-1533: Remove Frequent Pattern Mining (ssc)
 
   MAHOUT-1526: Ant file in examples (ssc)

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingBooleanRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingBooleanRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingBooleanRecommender.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingBooleanRecommender.java Tue May  6 05:01:51 2014
@@ -54,11 +54,22 @@ public final class BookCrossingBooleanRe
   }
 
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
-    return recommender.recommend(userID, howMany, rescorer);
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
   }
 
   @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+    return recommender.recommend(userID, howMany, rescorer, false);
+  }
+  
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
+    return recommender.recommend(userID, howMany, rescorer, includeKnownItems);
+  }
+  
+  @Override
   public float estimatePreference(long userID, long itemID) throws TasteException {
     return recommender.estimatePreference(userID, itemID);
   }

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/bookcrossing/BookCrossingRecommender.java Tue May  6 05:01:51 2014
@@ -51,10 +51,21 @@ public final class BookCrossingRecommend
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
     return recommender.recommend(userID, howMany);
   }
+
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
+  }
   
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
-    return recommender.recommend(userID, howMany, rescorer);
+    return recommender.recommend(userID, howMany, rescorer, false);
+  }
+  
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
+    return recommender.recommend(userID, howMany, rescorer, false);
   }
   
   @Override

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Recommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Recommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Recommender.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track1/Track1Recommender.java Tue May  6 05:01:51 2014
@@ -44,10 +44,21 @@ public final class Track1Recommender imp
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
     return recommender.recommend(userID, howMany);
   }
-  
+
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
+  }
+
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
-    return recommender.recommend(userID, howMany, rescorer);
+    return recommender.recommend(userID, howMany, rescorer, false);
+  }
+  
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
+    return recommender.recommend(userID, howMany, rescorer, includeKnownItems);
   }
   
   @Override

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Recommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Recommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Recommender.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/cf/taste/example/kddcup/track2/Track2Recommender.java Tue May  6 05:01:51 2014
@@ -50,10 +50,21 @@ public final class Track2Recommender imp
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
     return recommender.recommend(userID, howMany);
   }
-  
+
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
+  }
+
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
-    return recommender.recommend(userID, howMany, rescorer);
+    return recommender.recommend(userID, howMany, rescorer, false);
+  }
+  
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
+    return recommender.recommend(userID, howMany, rescorer, includeKnownItems);
   }
   
   @Override

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractCandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractCandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractCandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractCandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -33,20 +33,25 @@ import java.util.Collection;
 public abstract class AbstractCandidateItemsStrategy implements CandidateItemsStrategy,
     MostSimilarItemsCandidateItemsStrategy {
 
-  @Override
-  public FastIDSet getCandidateItems(long userID, PreferenceArray preferencesFromUser, DataModel dataModel)
-    throws TasteException {
-    return doGetCandidateItems(preferencesFromUser.getIDs(), dataModel);
+  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException{
+      return doGetCandidateItems(preferredItemIDs, dataModel, false);
   }
-
+  
   @Override
-  public FastIDSet getCandidateItems(long[] itemIDs, DataModel dataModel) throws TasteException {
-    return doGetCandidateItems(itemIDs, dataModel);
+  public FastIDSet getCandidateItems(long userID, PreferenceArray preferencesFromUser, DataModel dataModel,
+      boolean includeKnownItems) throws TasteException {
+    return doGetCandidateItems(preferencesFromUser.getIDs(), dataModel, includeKnownItems);
   }
-
-  protected abstract FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException;
-
+  
   @Override
-  public void refresh(Collection<Refreshable> alreadyRefreshed) {
+  public FastIDSet getCandidateItems(long[] itemIDs, DataModel dataModel)
+    throws TasteException {
+    return doGetCandidateItems(itemIDs, dataModel, false);
   }
+     
+  protected abstract FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel,
+      boolean includeKnownItems) throws TasteException;
+  
+  @Override
+  public void refresh(Collection<Refreshable> alreadyRefreshed) {}
 }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java Tue May  6 05:01:51 2014
@@ -19,11 +19,13 @@ package org.apache.mahout.cf.taste.impl.
 
 import org.apache.mahout.cf.taste.model.PreferenceArray;
 import org.apache.mahout.cf.taste.recommender.CandidateItemsStrategy;
+
 import java.util.List;
 
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
 import org.apache.mahout.cf.taste.model.DataModel;
+import org.apache.mahout.cf.taste.recommender.IDRescorer;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.cf.taste.recommender.Recommender;
 import org.slf4j.Logger;
@@ -51,6 +53,7 @@ public abstract class AbstractRecommende
     return new PreferredItemsNeighborhoodCandidateItemsStrategy();
   }
 
+
   /**
    * <p>
    * Default implementation which just calls
@@ -60,7 +63,27 @@ public abstract class AbstractRecommende
    */
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
-    return recommend(userID, howMany, null);
+    return recommend(userID, howMany, null, false);
+  }
+
+  /**
+   * <p>
+   * Default implementation which just calls
+   * {@link Recommender#recommend(long, int, org.apache.mahout.cf.taste.recommender.IDRescorer)}, with a
+   * {@link org.apache.mahout.cf.taste.recommender.Rescorer} that does nothing.
+   * </p>
+   */
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
+  }
+  
+  /**
+   * <p> Delegates to {@link Recommender#recommend(long, int, IDRescorer, boolean)}
+   */
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException{
+    return recommend(userID, howMany,rescorer, false);  
   }
   
   /**
@@ -96,19 +119,22 @@ public abstract class AbstractRecommende
   public DataModel getDataModel() {
     return dataModel;
   }
-  
+
   /**
    * @param userID
    *          ID of user being evaluated
    * @param preferencesFromUser
    *          the preferences from the user
+   * @param includeKnownItems
+   *          whether to include items already known by the user in recommendations
    * @return all items in the {@link DataModel} for which the user has not expressed a preference and could
    *         possibly be recommended to the user
    * @throws TasteException
    *           if an error occurs while listing items
    */
-  protected FastIDSet getAllOtherItems(long userID, PreferenceArray preferencesFromUser) throws TasteException {
-    return candidateItemsStrategy.getCandidateItems(userID, preferencesFromUser, dataModel);
+  protected FastIDSet getAllOtherItems(long userID, PreferenceArray preferencesFromUser, boolean includeKnownItems)
+      throws TasteException {
+    return candidateItemsStrategy.getCandidateItems(userID, preferencesFromUser, dataModel, includeKnownItems);
   }
   
 }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllSimilarItemsCandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllSimilarItemsCandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllSimilarItemsCandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllSimilarItemsCandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -36,12 +36,15 @@ public class AllSimilarItemsCandidateIte
   }
 
   @Override
-  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException {
+  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel, boolean includeKnownItems)
+    throws TasteException {
     FastIDSet candidateItemIDs = new FastIDSet();
     for (long itemID : preferredItemIDs) {
       candidateItemIDs.addAll(similarity.allSimilarItemIDs(itemID));
     }
-    candidateItemIDs.removeAll(preferredItemIDs);
+    if (!includeKnownItems) {
+      candidateItemIDs.removeAll(preferredItemIDs);
+    }
     return candidateItemIDs;
   }
 }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -24,17 +24,18 @@ import org.apache.mahout.cf.taste.model.
 
 public final class AllUnknownItemsCandidateItemsStrategy extends AbstractCandidateItemsStrategy {
 
-  /**
-   * return all items the user has not yet seen
-   */
+  /** return all items the user has not yet seen */
   @Override
-  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException {
+  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel, boolean includeKnownItems)
+    throws TasteException {
     FastIDSet possibleItemIDs = new FastIDSet(dataModel.getNumItems());
     LongPrimitiveIterator allItemIDs = dataModel.getItemIDs();
     while (allItemIDs.hasNext()) {
       possibleItemIDs.add(allItemIDs.nextLong());
     }
-    possibleItemIDs.removeAll(preferredItemIDs);
+    if (!includeKnownItems) {
+      possibleItemIDs.removeAll(preferredItemIDs);
+    }
     return possibleItemIDs;
   }
 }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java Tue May  6 05:01:51 2014
@@ -41,6 +41,8 @@ import com.google.common.base.Preconditi
 /**
  * <p>
  * A {@link Recommender} which caches the results from another {@link Recommender} in memory.
+ *
+ * TODO: Should be checked for thread safety
  * </p>
  */
 public final class CachingRecommender implements Recommender {
@@ -54,6 +56,7 @@ public final class CachingRecommender im
   private final Cache<LongPair,Float> estimatedPrefCache;
   private final RefreshHelper refreshHelper;
   private IDRescorer currentRescorer;
+  private boolean currentlyIncludeKnownItems;
   
   public CachingRecommender(Recommender recommender) throws TasteException {
     Preconditions.checkArgument(recommender != null, "recommender is null");
@@ -87,14 +90,29 @@ public final class CachingRecommender im
       }
     }
   }
-  
+
+  public void setCurrentlyIncludeKnownItems(boolean currentlyIncludeKnownItems) {
+    this.currentlyIncludeKnownItems = currentlyIncludeKnownItems;
+  }
+
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
-    return recommend(userID, howMany, null);
+    return recommend(userID, howMany, null, false);
   }
-  
+
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException {
+    return recommend(userID, howMany, null, includeKnownItems);
+  }
+
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany,IDRescorer rescorer) throws TasteException {
+      return recommend(userID, howMany, rescorer, false);
+  }
+ 
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany,IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
     synchronized (maxHowMany) {
       if (howMany > maxHowMany[0]) {
@@ -108,6 +126,7 @@ public final class CachingRecommender im
     }
 
     setCurrentRescorer(rescorer);
+    setCurrentlyIncludeKnownItems(includeKnownItems);
 
     Recommendations recommendations = recommendationCache.get(userID);
     if (recommendations.getItems().size() < howMany && !recommendations.isNoMoreRecommendableItems()) {
@@ -191,7 +210,8 @@ public final class CachingRecommender im
       int howMany = maxHowMany[0];
       IDRescorer rescorer = currentRescorer;
       List<RecommendedItem> recommendations =
-          rescorer == null ? recommender.recommend(key, howMany) : recommender.recommend(key, howMany, rescorer);
+          rescorer == null ? recommender.recommend(key, howMany, null, currentlyIncludeKnownItems) :
+              recommender.recommend(key, howMany, rescorer, currentlyIncludeKnownItems);
       return new Recommendations(Collections.unmodifiableList(recommendations));
     }
   }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java Tue May  6 05:01:51 2014
@@ -61,13 +61,16 @@ public final class GenericBooleanPrefUse
   }
   
   @Override
-  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
+  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID, boolean includeKnownItems)
+      throws TasteException {
     DataModel dataModel = getDataModel();
     FastIDSet possibleItemIDs = new FastIDSet();
     for (long userID : theNeighborhood) {
       possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
     }
-    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
+    if (!includeKnownItems) {
+      possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
+    }
     return possibleItemIDs;
   }
   

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java Tue May  6 05:01:51 2014
@@ -117,7 +117,8 @@ public class GenericItemBasedRecommender
   }
   
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
     log.debug("Recommending items for user ID '{}'", userID);
 
@@ -126,7 +127,7 @@ public class GenericItemBasedRecommender
       return Collections.emptyList();
     }
 
-    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser);
+    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser, includeKnownItems);
 
     TopItems.Estimator<Long> estimator = new Estimator(userID, preferencesFromUser);
 

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java Tue May  6 05:01:51 2014
@@ -79,7 +79,8 @@ public class GenericUserBasedRecommender
   }
   
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
 
     log.debug("Recommending items for user ID '{}'", userID);
@@ -90,7 +91,7 @@ public class GenericUserBasedRecommender
       return Collections.emptyList();
     }
 
-    FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID);
+    FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID, includeKnownItems);
 
     TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood);
 
@@ -165,13 +166,16 @@ public class GenericUserBasedRecommender
     return estimate;
   }
   
-  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
+  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID, boolean includeKnownItems)
+    throws TasteException {
     DataModel dataModel = getDataModel();
     FastIDSet possibleItemIDs = new FastIDSet();
     for (long userID : theNeighborhood) {
       possibleItemIDs.addAll(dataModel.getItemIDsFromUser(userID));
     }
-    possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
+    if (!includeKnownItems) {
+      possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
+    }
     return possibleItemIDs;
   }
   

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemAverageRecommender.java Tue May  6 05:01:51 2014
@@ -72,12 +72,13 @@ public final class ItemAverageRecommende
   }
   
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
     log.debug("Recommending items for user ID '{}'", userID);
 
     PreferenceArray preferencesFromUser = getDataModel().getPreferencesFromUser(userID);
-    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser);
+    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser, includeKnownItems);
 
     TopItems.Estimator<Long> estimator = new Estimator();
 

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ItemUserAverageRecommender.java Tue May  6 05:01:51 2014
@@ -77,12 +77,13 @@ public final class ItemUserAverageRecomm
   }
   
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
     log.debug("Recommending items for user ID '{}'", userID);
 
     PreferenceArray preferencesFromUser = getDataModel().getPreferencesFromUser(userID);
-    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser);
+    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser, includeKnownItems);
 
     TopItems.Estimator<Long> estimator = new Estimator(userID);
 

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -29,7 +29,8 @@ public final class PreferredItemsNeighbo
    * that has preferred at least one item that the current user has preferred too
    */
   @Override
-  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException {
+  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel, boolean includeKnownItems)
+    throws TasteException {
     FastIDSet possibleItemsIDs = new FastIDSet();
     for (long itemID : preferredItemIDs) {
       PreferenceArray itemPreferences = dataModel.getPreferencesForItem(itemID);
@@ -38,7 +39,9 @@ public final class PreferredItemsNeighbo
         possibleItemsIDs.addAll(dataModel.getItemIDsFromUser(itemPreferences.getUserID(index)));
       }
     }
-    possibleItemsIDs.removeAll(preferredItemIDs);
+    if (!includeKnownItems) {
+      possibleItemsIDs.removeAll(preferredItemIDs);
+    }
     return possibleItemsIDs;
   }
 

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/RandomRecommender.java Tue May  6 05:01:51 2014
@@ -62,9 +62,10 @@ public final class RandomRecommender ext
     this.minPref = minPref;
     this.maxPref = maxPref;
   }
-  
+
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     DataModel dataModel = getDataModel();
     int numItems = dataModel.getNumItems();
     List<RecommendedItem> result = Lists.newArrayListWithCapacity(howMany);
@@ -72,7 +73,7 @@ public final class RandomRecommender ext
       LongPrimitiveIterator it = dataModel.getItemIDs();
       it.skip(random.nextInt(numItems));
       long itemID = it.next();
-      if (dataModel.getPreferenceValue(userID, itemID) == null) {
+      if (includeKnownItems || dataModel.getPreferenceValue(userID, itemID) == null) {
         result.add(new GenericRecommendedItem(itemID, randomPref()));
       }
     }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -118,7 +118,8 @@ public class SamplingCandidateItemsStrat
   }
 
   @Override
-  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel) throws TasteException {
+  protected FastIDSet doGetCandidateItems(long[] preferredItemIDs, DataModel dataModel, boolean includeKnownItems)
+    throws TasteException {
     LongPrimitiveIterator preferredItemIDsIterator = new LongPrimitiveArrayIterator(preferredItemIDs);
     if (preferredItemIDs.length > maxItems) {
       double samplingRate = (double) maxItems / preferredItemIDs.length;
@@ -143,7 +144,9 @@ public class SamplingCandidateItemsStrat
         }
       }
     }
-    possibleItemsIDs.removeAll(preferredItemIDs);
+    if (!includeKnownItems) {
+      possibleItemsIDs.removeAll(preferredItemIDs);
+    }
     return possibleItemsIDs;
   }
 

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommender.java Tue May  6 05:01:51 2014
@@ -131,12 +131,13 @@ public final class SVDRecommender extend
   }
   
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+    throws TasteException {
     Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1");
     log.debug("Recommending items for user ID '{}'", userID);
 
     PreferenceArray preferencesFromUser = getDataModel().getPreferencesFromUser(userID);
-    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser);
+    FastIDSet possibleItemIDs = getAllOtherItems(userID, preferencesFromUser, includeKnownItems);
 
     List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer,
         new Estimator(userID));

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/CandidateItemsStrategy.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/CandidateItemsStrategy.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/CandidateItemsStrategy.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/CandidateItemsStrategy.java Tue May  6 05:01:51 2014
@@ -31,7 +31,7 @@ public interface CandidateItemsStrategy 
   /**
    * @return IDs of all items that could be recommended to the user
    */
-  FastIDSet getCandidateItems(long userID, PreferenceArray preferencesFromUser, DataModel dataModel)
-    throws TasteException;
+  FastIDSet getCandidateItems(long userID, PreferenceArray preferencesFromUser, DataModel dataModel,
+     boolean includeKnownItems) throws TasteException;
   
 }

Modified: mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java (original)
+++ mahout/trunk/mrlegacy/src/main/java/org/apache/mahout/cf/taste/recommender/Recommender.java Tue May  6 05:01:51 2014
@@ -42,7 +42,21 @@ public interface Recommender extends Ref
    *           if an error occurs while accessing the {@link DataModel}
    */
   List<RecommendedItem> recommend(long userID, int howMany) throws TasteException;
-  
+
+  /**
+   * @param userID
+   *          user for which recommendations are to be computed
+   * @param howMany
+   *          desired number of recommendations
+   * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to
+   *         least
+   * @param includeKnownItems
+   *          whether to include items already known by the user in recommendations
+   * @throws TasteException
+   *           if an error occurs while accessing the {@link DataModel}
+   */
+  List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException;
+
   /**
    * @param userID
    *          user for which recommendations are to be computed
@@ -59,6 +73,24 @@ public interface Recommender extends Ref
   
   /**
    * @param userID
+   *          user for which recommendations are to be computed
+   * @param howMany
+   *          desired number of recommendations
+   * @param rescorer
+   *          rescoring function to apply before final list of recommendations is determined
+   * @param includeKnownItems
+   *          whether to include items already known by the user in recommendations
+   * @return {@link List} of recommended {@link RecommendedItem}s, ordered from most strongly recommend to
+   *         least
+   * @throws TasteException
+   *           if an error occurs while accessing the {@link DataModel}
+   */
+  
+  List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems)
+      throws TasteException;
+  
+  /**
+   * @param userID
    *          user ID whose preference is to be estimated
    * @param itemID
    *          item ID to estimate preference for

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategyTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategyTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategyTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/AllUnknownItemsCandidateItemsStrategyTest.java Tue May  6 05:01:51 2014
@@ -54,7 +54,7 @@ public final class AllUnknownItemsCandid
 
     EasyMock.replay(dataModel);
 
-    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
+    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel, false);
     assertEquals(2, candidateItems.size());
     assertTrue(candidateItems.contains(1L));
     assertTrue(candidateItems.contains(3L));

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommenderTest.java Tue May  6 05:01:51 2014
@@ -122,6 +122,36 @@ public final class GenericItemBasedRecom
   }
 
   @Test
+  public void testIncludeKnownItems() throws Exception {
+
+    DataModel dataModel = getDataModel(
+            new long[] {1, 2, 3},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.4, 0.5, 0.9},
+            });
+
+    Collection<GenericItemSimilarity.ItemItemSimilarity> similarities = Lists.newArrayList();
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 1, 0.8));
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 2, 0.5));
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(0, 3, 0.2));
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 2, 0.7));
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(1, 3, 0.5));
+    similarities.add(new GenericItemSimilarity.ItemItemSimilarity(2, 3, 0.9));
+    ItemSimilarity similarity = new GenericItemSimilarity(similarities);
+    Recommender recommender = new GenericItemBasedRecommender(dataModel, similarity);
+    List<RecommendedItem> originalRecommended = recommender.recommend(1, 4, null, true);
+    List<RecommendedItem> rescoredRecommended = recommender.recommend(1, 4, new ReversingRescorer<Long>(), true);
+    assertNotNull(originalRecommended);
+    assertNotNull(rescoredRecommended);
+    assertEquals(4, originalRecommended.size());
+    assertEquals(4, rescoredRecommended.size());
+    assertEquals(originalRecommended.get(0).getItemID(), rescoredRecommended.get(3).getItemID());
+    assertEquals(originalRecommended.get(3).getItemID(), rescoredRecommended.get(0).getItemID());
+  }
+  
+  @Test
   public void testEstimatePref() throws Exception {
     Recommender recommender = buildRecommender();
     assertEquals(0.1f, recommender.estimatePreference(1, 2), EPSILON);
@@ -274,7 +304,7 @@ public final class GenericItemBasedRecom
     EasyMock.expect(dataModel.getMaxPreference()).andReturn(Float.NaN);
 
     EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
-    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel))
+    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel, false))
         .andReturn(new FastIDSet(new long[] { 3L, 4L }));
 
     EasyMock.expect(itemSimilarity.itemSimilarities(3L, preferencesFromUser.getIDs()))

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommenderTest.java Tue May  6 05:01:51 2014
@@ -97,6 +97,28 @@ public final class GenericUserBasedRecom
   }
 
   @Test
+  public void testIncludeKnownItems() throws Exception {
+    DataModel dataModel = getDataModel(
+            new long[] {1, 2, 3},
+            new Double[][] {
+                    {0.1, 0.2},
+                    {0.2, 0.3, 0.3, 0.6},
+                    {0.4, 0.5, 0.5, 0.9},
+            });
+    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
+    UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, dataModel);
+    Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
+    List<RecommendedItem> originalRecommended = recommender.recommend(1, 4, null, true);
+    List<RecommendedItem> rescoredRecommended = recommender.recommend(1, 4, new ReversingRescorer<Long>(), true);
+    assertNotNull(originalRecommended);
+    assertNotNull(rescoredRecommended);
+    assertEquals(4, originalRecommended.size());
+    assertEquals(4, rescoredRecommended.size());
+    assertEquals(originalRecommended.get(0).getItemID(), rescoredRecommended.get(3).getItemID());
+    assertEquals(originalRecommended.get(3).getItemID(), rescoredRecommended.get(0).getItemID());
+  }
+
+  @Test
   public void testEstimatePref() throws Exception {
     Recommender recommender = buildRecommender();
     assertEquals(0.1f, recommender.estimatePreference(1, 2), EPSILON);

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/MockRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/MockRecommender.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/MockRecommender.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/MockRecommender.java Tue May  6 05:01:51 2014
@@ -46,9 +46,19 @@ final class MockRecommender implements R
   }
 
   @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) {
+    return recommend(userID, howMany);
+  }
+
+  @Override
   public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) {
     return recommend(userID, howMany);
   }
+  
+  @Override
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) {
+    return recommend(userID, howMany);
+  }
 
   @Override
   public float estimatePreference(long userID, long itemID) {
@@ -74,8 +84,6 @@ final class MockRecommender implements R
   }
 
   @Override
-  public void refresh(Collection<Refreshable> alreadyRefreshed) {
-    // do nothing
-  }
+  public void refresh(Collection<Refreshable> alreadyRefreshed) {}
 
 }

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategyTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategyTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategyTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/PreferredItemsNeighborhoodCandidateItemsStrategyTest.java Tue May  6 05:01:51 2014
@@ -65,7 +65,7 @@ public final class PreferredItemsNeighbo
 
     EasyMock.replay(dataModel);
 
-    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
+    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel, false);
     assertEquals(1, candidateItems.size());
     assertTrue(candidateItems.contains(2L));
 

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategyTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategyTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategyTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/SamplingCandidateItemsStrategyTest.java Tue May  6 05:01:51 2014
@@ -63,7 +63,7 @@ public final class SamplingCandidateItem
     CandidateItemsStrategy strategy =
         new SamplingCandidateItemsStrategy(1, 1, 1, dataModel.getNumUsers(), dataModel.getNumItems());
 
-    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel);
+    FastIDSet candidateItems = strategy.getCandidateItems(123L, prefArrayOfUser123, dataModel, false);
     /* result can be either item2 or item3 or empty */
     assertTrue(candidateItems.size() <= 1);
     assertFalse(candidateItems.contains(1L));

Modified: mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommenderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommenderTest.java?rev=1592656&r1=1592655&r2=1592656&view=diff
==============================================================================
--- mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommenderTest.java (original)
+++ mahout/trunk/mrlegacy/src/test/java/org/apache/mahout/cf/taste/impl/recommender/svd/SVDRecommenderTest.java Tue May  6 05:01:51 2014
@@ -63,7 +63,7 @@ public class SVDRecommenderTest extends 
 
     EasyMock.expect(factorizer.factorize()).andReturn(factorization);
     EasyMock.expect(dataModel.getPreferencesFromUser(1L)).andReturn(preferencesFromUser);
-    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel))
+    EasyMock.expect(candidateItemsStrategy.getCandidateItems(1L, preferencesFromUser, dataModel, false))
         .andReturn(candidateItems);
     EasyMock.expect(factorization.getUserFeatures(1L)).andReturn(new double[] { 0.4, 2 });
     EasyMock.expect(factorization.getItemFeatures(5L)).andReturn(new double[] { 1, 0.3 });



Mime
View raw message