Repository: mahout
Updated Branches:
  refs/heads/master 002943be7 -> 785668906


MAHOUT-1642 Iterator class within SimilarItems class always misses the first 
element, this closes apache/mahout#134


Project: http://git-wip-us.apache.org/repos/asf/mahout/repo
Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/78566890
Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/78566890
Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/78566890

Branch: refs/heads/master
Commit: 785668906b5e69db6c9352ffba961b49bda450d2
Parents: 002943b
Author: smarthi <[email protected]>
Authored: Sat Aug 8 14:35:41 2015 -0400
Committer: smarthi <[email protected]>
Committed: Sat Aug 8 14:35:41 2015 -0400

----------------------------------------------------------------------
 CHANGELOG                                       |  2 +
 .../similarity/precompute/SimilarItems.java     |  2 +-
 .../similarity/precompute/SimilarItemsTest.java | 50 ++++++++++++++++++++
 3 files changed, 53 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mahout/blob/78566890/CHANGELOG
----------------------------------------------------------------------
diff --git a/CHANGELOG b/CHANGELOG
index 624c94b..726426a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,8 @@ Mahout Change Log
 
 Release 0.11.1 - unreleased
 
+  MAHOUT-1642: Iterator class within SimilarItems class always misses the 
first element (Oleg Zotov via smarthi)
+
   MAHOUT-1675: Remove MLP from codebase (ZJaffe via smarthi)
 
 Release 0.11.0 - 2015-08-07

http://git-wip-us.apache.org/repos/asf/mahout/blob/78566890/mr/src/main/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItems.java
----------------------------------------------------------------------
diff --git 
a/mr/src/main/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItems.java
 
b/mr/src/main/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItems.java
index 18ee42c..057e996 100644
--- 
a/mr/src/main/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItems.java
+++ 
b/mr/src/main/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItems.java
@@ -65,7 +65,7 @@ public class SimilarItems {
 
   private class SimilarItemsIterator extends UnmodifiableIterator<SimilarItem> 
{
 
-    private int index = 0;
+    private int index = -1;
 
     @Override
     public boolean hasNext() {

http://git-wip-us.apache.org/repos/asf/mahout/blob/78566890/mr/src/test/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItemsTest.java
----------------------------------------------------------------------
diff --git 
a/mr/src/test/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItemsTest.java
 
b/mr/src/test/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItemsTest.java
new file mode 100644
index 0000000..afce3cf
--- /dev/null
+++ 
b/mr/src/test/java/org/apache/mahout/cf/taste/similarity/precompute/SimilarItemsTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.similarity.precompute;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.mahout.cf.taste.impl.TasteTestCase;
+import org.apache.mahout.cf.taste.impl.recommender.GenericRecommendedItem;
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+public class SimilarItemsTest extends TasteTestCase {
+
+  @Test
+  public void testIterator() {
+       List<RecommendedItem> recommendedItems = new ArrayList<>();
+       for (long itemId = 2; itemId < 10; itemId++) {
+         recommendedItems.add(new GenericRecommendedItem(itemId, itemId));
+       }
+
+       SimilarItems similarItems = new SimilarItems(1, recommendedItems);
+
+       assertThat(similarItems.getSimilarItems(), Matchers.<SimilarItem> 
iterableWithSize(recommendedItems.size()));
+
+       int byHandIndex = 0;
+       for (SimilarItem simItem : similarItems.getSimilarItems()) {
+         RecommendedItem recItem = recommendedItems.get(byHandIndex++);
+         assertEquals(simItem.getItemID(), recItem.getItemID());
+         assertEquals(simItem.getSimilarity(), recItem.getValue(), EPSILON);
+       }
+
+  }
+}

Reply via email to