You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by sr...@apache.org on 2010/04/05 08:26:01 UTC
svn commit: r930805 - in /lucene/mahout/trunk/core/src:
main/java/org/apache/mahout/cf/taste/hadoop/
main/java/org/apache/mahout/cf/taste/hadoop/item/
main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/
main/java/org/apache/mahout/cf/taste/had...
Author: srowen
Date: Mon Apr 5 06:26:00 2010
New Revision: 930805
URL: http://svn.apache.org/viewvc?rev=930805&view=rev
Log:
MAHOUT-362 Fix test location and merge ItemWritable/UserWritable into EntityWritable
Added:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java
- copied, changed from r930802, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityWritable.java
- copied, changed from r930802, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemWritable.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java
- copied, changed from r930802, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/ItemSimilarityTest.java
Removed:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserWritable.java
lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/ItemSimilarityTest.java
Modified:
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/CopreferredItemsMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ToItemVectorReducer.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/UserPrefsPerItemMapper.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefArrayWritable.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java
lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java (from r930802, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java&r1=930802&r2=930805&rev=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemPrefWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java Mon Apr 5 06:26:00 2010
@@ -22,25 +22,24 @@ import java.io.DataOutput;
import java.io.IOException;
import org.apache.hadoop.io.Writable;
-import org.apache.hadoop.io.WritableComparable;
import org.apache.mahout.common.RandomUtils;
/** A {@link Writable} encapsulating an item ID and a preference value. */
-public final class ItemPrefWritable extends ItemWritable implements WritableComparable<ItemPrefWritable> {
+public final class EntityPrefWritable extends EntityWritable {
private float prefValue;
- public ItemPrefWritable() {
+ public EntityPrefWritable() {
// do nothing
}
- public ItemPrefWritable(long itemID, float prefValue) {
+ public EntityPrefWritable(long itemID, float prefValue) {
super(itemID);
this.prefValue = prefValue;
}
- public ItemPrefWritable(ItemPrefWritable other) {
- this(other.getItemID(), other.getPrefValue());
+ public EntityPrefWritable(EntityPrefWritable other) {
+ this(other.getID(), other.getPrefValue());
}
public float getPrefValue() {
@@ -59,8 +58,8 @@ public final class ItemPrefWritable exte
prefValue = in.readFloat();
}
- public static ItemPrefWritable read(DataInput in) throws IOException {
- ItemPrefWritable writable = new ItemPrefWritable();
+ public static EntityPrefWritable read(DataInput in) throws IOException {
+ EntityPrefWritable writable = new EntityPrefWritable();
writable.readFields(in);
return writable;
}
@@ -72,12 +71,16 @@ public final class ItemPrefWritable exte
@Override
public boolean equals(Object o) {
- if (!(o instanceof ItemPrefWritable)) {
+ if (!(o instanceof EntityPrefWritable)) {
return false;
}
- ItemPrefWritable other = (ItemPrefWritable) o;
- return getItemID() == other.getItemID() && prefValue == other.getPrefValue();
-
+ EntityPrefWritable other = (EntityPrefWritable) o;
+ return getID() == other.getID() && prefValue == other.getPrefValue();
+ }
+
+ @Override
+ public EntityPrefWritable clone() {
+ return new EntityPrefWritable(getID(), prefValue);
}
}
\ No newline at end of file
Copied: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityWritable.java (from r930802, lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemWritable.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityWritable.java?p2=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityWritable.java&p1=lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemWritable.java&r1=930802&r2=930805&rev=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ItemWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityWritable.java Mon Apr 5 06:26:00 2010
@@ -26,56 +26,61 @@ import org.apache.hadoop.io.WritableComp
import org.apache.mahout.common.RandomUtils;
/** A {@link Writable} encapsulating an item ID. */
-public class ItemWritable implements WritableComparable<ItemWritable> {
+public class EntityWritable implements WritableComparable<EntityWritable>, Cloneable {
- private long itemID;
+ private long ID;
- public ItemWritable() {
+ public EntityWritable() {
// do nothing
}
- public ItemWritable(long itemID) {
- this.itemID = itemID;
+ public EntityWritable(long ID) {
+ this.ID = ID;
}
- public ItemWritable(ItemWritable other) {
- this(other.getItemID());
+ public EntityWritable(EntityWritable other) {
+ this(other.getID());
}
- public long getItemID() {
- return itemID;
+ public long getID() {
+ return ID;
}
@Override
public void write(DataOutput out) throws IOException {
- out.writeLong(itemID);
+ out.writeLong(ID);
}
@Override
public void readFields(DataInput in) throws IOException {
- itemID = in.readLong();
+ ID = in.readLong();
}
- public static ItemWritable read(DataInput in) throws IOException {
- ItemWritable writable = new ItemWritable();
+ public static EntityWritable read(DataInput in) throws IOException {
+ EntityWritable writable = new EntityWritable();
writable.readFields(in);
return writable;
}
@Override
- public int compareTo(ItemWritable other) {
- long otherItemID = other.getItemID();
- return itemID < otherItemID ? -1 : itemID > otherItemID ? 1 : 0;
+ public int compareTo(EntityWritable other) {
+ long otherItemID = other.getID();
+ return ID < otherItemID ? -1 : ID > otherItemID ? 1 : 0;
}
@Override
public int hashCode() {
- return RandomUtils.hashLong(itemID);
+ return RandomUtils.hashLong(ID);
}
@Override
public boolean equals(Object o) {
- return o instanceof ItemWritable && (itemID == ((ItemWritable) o).getItemID());
+ return o instanceof EntityWritable && (ID == ((EntityWritable) o).getID());
+ }
+
+ @Override
+ public EntityWritable clone() {
+ return new EntityWritable(ID);
}
}
\ No newline at end of file
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToItemPrefsMapper.java Mon Apr 5 06:26:00 2010
@@ -46,11 +46,11 @@ import org.apache.mahout.cf.taste.hadoop
*
* <p>
* Outputs the user ID as a {@link LongWritable} mapped to the item ID and preference as a
- * {@link ItemPrefWritable}.
+ * {@link EntityPrefWritable}.
* </p>
*/
public final class ToItemPrefsMapper extends MapReduceBase implements
- Mapper<LongWritable,Text,LongWritable,ItemWritable> {
+ Mapper<LongWritable,Text,LongWritable, EntityWritable> {
private static final Pattern COMMA = Pattern.compile(",");
@@ -64,16 +64,16 @@ public final class ToItemPrefsMapper ext
@Override
public void map(LongWritable key,
Text value,
- OutputCollector<LongWritable,ItemWritable> output,
+ OutputCollector<LongWritable, EntityWritable> output,
Reporter reporter) throws IOException {
String[] tokens = ToItemPrefsMapper.COMMA.split(value.toString());
long userID = Long.parseLong(tokens[0]);
long itemID = Long.parseLong(tokens[1]);
if (booleanData) {
- output.collect(new LongWritable(userID), new ItemWritable(itemID));
+ output.collect(new LongWritable(userID), new EntityWritable(itemID));
} else {
float prefValue = tokens.length > 2 ? Float.parseFloat(tokens[2]) : 1.0f;
- output.collect(new LongWritable(userID), new ItemPrefWritable(itemID, prefValue));
+ output.collect(new LongWritable(userID), new EntityPrefWritable(itemID, prefValue));
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/RecommenderJob.java Mon Apr 5 06:26:00 2010
@@ -35,9 +35,9 @@ import org.apache.hadoop.mapred.TextInpu
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapred.lib.IdentityReducer;
import org.apache.hadoop.util.ToolRunner;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.common.AbstractJob;
-import org.apache.mahout.cf.taste.hadoop.ItemPrefWritable;
import org.apache.mahout.cf.taste.hadoop.RecommendedItemsWritable;
import org.apache.mahout.cf.taste.hadoop.ToItemPrefsMapper;
import org.apache.mahout.math.VectorWritable;
@@ -100,7 +100,7 @@ public final class RecommenderJob extend
JobConf toUserVectorConf = prepareJobConf(inputPath, userVectorPath,
TextInputFormat.class, ToItemPrefsMapper.class, LongWritable.class,
- booleanData ? ItemWritable.class : ItemPrefWritable.class,
+ booleanData ? EntityWritable.class : EntityPrefWritable.class,
ToUserVectorReducer.class, LongWritable.class, VectorWritable.class, SequenceFileOutputFormat.class);
toUserVectorConf.setBoolean(BOOLEAN_DATA, booleanData);
JobClient.runJob(toUserVectorConf);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ToUserVectorReducer.java Mon Apr 5 06:26:00 2010
@@ -28,8 +28,8 @@ import org.apache.hadoop.mapred.MapReduc
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
-import org.apache.mahout.cf.taste.hadoop.ItemPrefWritable;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.math.RandomAccessSparseVector;
import org.apache.mahout.math.Vector;
import org.apache.mahout.math.VectorWritable;
@@ -39,7 +39,7 @@ import org.apache.mahout.math.VectorWrit
*
* <p>
* Takes user IDs as {@link LongWritable} mapped to all associated item IDs and preference values, as
- * {@link ItemPrefWritable}s.
+ * {@link EntityPrefWritable}s.
* </p>
*
* <h1>Output</h1>
@@ -58,7 +58,7 @@ import org.apache.mahout.math.VectorWrit
*
*/
public final class ToUserVectorReducer extends MapReduceBase implements
- Reducer<LongWritable,ItemWritable,LongWritable,VectorWritable> {
+ Reducer<LongWritable, EntityWritable,LongWritable,VectorWritable> {
public static final int MAX_PREFS_CONSIDERED = 20;
@@ -72,17 +72,17 @@ public final class ToUserVectorReducer e
@Override
public void reduce(LongWritable userID,
- Iterator<ItemWritable> itemPrefs,
+ Iterator<EntityWritable> itemPrefs,
OutputCollector<LongWritable,VectorWritable> output,
Reporter reporter) throws IOException {
if (itemPrefs.hasNext()) {
RandomAccessSparseVector userVector = new RandomAccessSparseVector(Integer.MAX_VALUE, 100);
while (itemPrefs.hasNext()) {
- ItemWritable itemPref = itemPrefs.next();
- int index = ItemIDIndexMapper.idToIndex(itemPref.getItemID());
+ EntityWritable itemPref = itemPrefs.next();
+ int index = ItemIDIndexMapper.idToIndex(itemPref.getID());
float value;
- if (itemPref instanceof ItemPrefWritable) {
- value = ((ItemPrefWritable) itemPref).getPrefValue();
+ if (itemPref instanceof EntityPrefWritable) {
+ value = ((EntityPrefWritable) itemPref).getPrefValue();
} else {
value = 1.0f;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/CopreferredItemsMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/CopreferredItemsMapper.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/CopreferredItemsMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/CopreferredItemsMapper.java Mon Apr 5 06:26:00 2010
@@ -21,20 +21,20 @@ import java.io.IOException;
import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.mapreduce.Mapper;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPairWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthArrayWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserWritable;
/**
* map out each pair of items that appears in the same user-vector together with the multiplied vector lengths
* of the associated item vectors
*/
public final class CopreferredItemsMapper
- extends Mapper<UserWritable,ItemPrefWithLengthArrayWritable,ItemPairWritable,FloatWritable> {
+ extends Mapper<EntityWritable,ItemPrefWithLengthArrayWritable,ItemPairWritable,FloatWritable> {
@Override
- protected void map(UserWritable user, ItemPrefWithLengthArrayWritable itemPrefsArray, Context context)
+ protected void map(EntityWritable user, ItemPrefWithLengthArrayWritable itemPrefsArray, Context context)
throws IOException, InterruptedException {
ItemPrefWithLengthWritable[] itemPrefs = itemPrefsArray.getItemPrefs();
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityJob.java Mon Apr 5 06:26:00 2010
@@ -36,14 +36,13 @@ import org.apache.hadoop.mapreduce.lib.o
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
import org.apache.hadoop.util.ToolRunner;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.ItemItemWritable;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPairWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthArrayWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefArrayWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserWritable;
import org.apache.mahout.common.AbstractJob;
/**
@@ -123,14 +122,14 @@ public final class ItemSimilarityJob ext
String userVectorsPath = tempDirPath + "/userVectors";
Job itemVectors = createJob(originalConf, "itemVectors", inputPath, itemVectorsPath, UserPrefsPerItemMapper.class,
- ItemWritable.class, UserPrefWritable.class, ToItemVectorReducer.class, ItemWritable.class,
+ EntityWritable.class, EntityPrefWritable.class, ToItemVectorReducer.class, EntityWritable.class,
UserPrefArrayWritable.class, TextInputFormat.class, SequenceFileOutputFormat.class, true);
itemVectors.waitForCompletion(true);
Job userVectors = createJob(originalConf, "userVectors", itemVectorsPath, userVectorsPath,
- PreferredItemsPerUserMapper.class, UserWritable.class, ItemPrefWithLengthWritable.class,
- PreferredItemsPerUserReducer.class, UserWritable.class, ItemPrefWithLengthArrayWritable.class);
+ PreferredItemsPerUserMapper.class, EntityWritable.class, ItemPrefWithLengthWritable.class,
+ PreferredItemsPerUserReducer.class, EntityWritable.class, ItemPrefWithLengthArrayWritable.class);
userVectors.waitForCompletion(true);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserMapper.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserMapper.java Mon Apr 5 06:26:00 2010
@@ -20,36 +20,35 @@ package org.apache.mahout.cf.taste.hadoo
import java.io.IOException;
import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefArrayWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserWritable;
/**
* for each item-vector, we compute its length here and map out all entries with the user as key,
* so we can create the user-vectors in the reducer
*/
public final class PreferredItemsPerUserMapper
- extends Mapper<ItemWritable,UserPrefArrayWritable,UserWritable,ItemPrefWithLengthWritable> {
+ extends Mapper<EntityWritable,UserPrefArrayWritable,EntityWritable,ItemPrefWithLengthWritable> {
@Override
- protected void map(ItemWritable item, UserPrefArrayWritable userPrefsArray, Context context)
+ protected void map(EntityWritable item, UserPrefArrayWritable userPrefsArray, Context context)
throws IOException, InterruptedException {
- UserPrefWritable[] userPrefs = userPrefsArray.getUserPrefs();
+ EntityPrefWritable[] userPrefs = userPrefsArray.getUserPrefs();
double length = 0.0;
- for (UserPrefWritable userPref : userPrefs) {
+ for (EntityPrefWritable userPref : userPrefs) {
double value = userPref.getPrefValue();
length += value * value;
}
length = Math.sqrt(length);
- for (UserPrefWritable userPref : userPrefs) {
- context.write(new UserWritable(userPref.getUserID()),
- new ItemPrefWithLengthWritable(item.getItemID(), length, userPref.getPrefValue()));
+ for (EntityPrefWritable userPref : userPrefs) {
+ context.write(new EntityWritable(userPref.getID()),
+ new ItemPrefWithLengthWritable(item.getID(), length, userPref.getPrefValue()));
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserReducer.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/PreferredItemsPerUserReducer.java Mon Apr 5 06:26:00 2010
@@ -22,15 +22,15 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthArrayWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserWritable;
public final class PreferredItemsPerUserReducer
- extends Reducer<UserWritable,ItemPrefWithLengthWritable,UserWritable,ItemPrefWithLengthArrayWritable> {
+ extends Reducer<EntityWritable,ItemPrefWithLengthWritable, EntityWritable,ItemPrefWithLengthArrayWritable> {
@Override
- protected void reduce(UserWritable user, Iterable<ItemPrefWithLengthWritable> itemPrefs, Context context)
+ protected void reduce(EntityWritable user, Iterable<ItemPrefWithLengthWritable> itemPrefs, Context context)
throws IOException, InterruptedException {
Set<ItemPrefWithLengthWritable> itemPrefsWithLength = new HashSet<ItemPrefWithLengthWritable>();
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ToItemVectorReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ToItemVectorReducer.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ToItemVectorReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ToItemVectorReducer.java Mon Apr 5 06:26:00 2010
@@ -22,29 +22,29 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.hadoop.mapreduce.Reducer;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefArrayWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefWritable;
/**
* For each single item, collect all users with their preferences
* (thereby building the item vectors of the user-item-matrix)
*/
public final class ToItemVectorReducer
- extends Reducer<ItemWritable,UserPrefWritable,ItemWritable,UserPrefArrayWritable> {
+ extends Reducer<EntityWritable, EntityPrefWritable, EntityWritable,UserPrefArrayWritable> {
@Override
- protected void reduce(ItemWritable item, Iterable<UserPrefWritable> userPrefs, Context context)
+ protected void reduce(EntityWritable item, Iterable<EntityPrefWritable> userPrefs, Context context)
throws IOException, InterruptedException {
- Set<UserPrefWritable> collectedUserPrefs = new HashSet<UserPrefWritable>();
+ Set<EntityPrefWritable> collectedUserPrefs = new HashSet<EntityPrefWritable>();
- for (UserPrefWritable userPref : userPrefs) {
- collectedUserPrefs.add(userPref.deepCopy());
+ for (EntityPrefWritable userPref : userPrefs) {
+ collectedUserPrefs.add(userPref.clone());
}
context.write(item, new UserPrefArrayWritable(
- collectedUserPrefs.toArray(new UserPrefWritable[collectedUserPrefs.size()])));
+ collectedUserPrefs.toArray(new EntityPrefWritable[collectedUserPrefs.size()])));
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/UserPrefsPerItemMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/UserPrefsPerItemMapper.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/UserPrefsPerItemMapper.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/UserPrefsPerItemMapper.java Mon Apr 5 06:26:00 2010
@@ -23,14 +23,14 @@ import java.util.regex.Pattern;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
/**
* Read an entry from the preferences file and map it out with the item as key and the user with her preference
* as value
*/
-public final class UserPrefsPerItemMapper extends Mapper<LongWritable,Text,ItemWritable,UserPrefWritable> {
+public final class UserPrefsPerItemMapper extends Mapper<LongWritable,Text, EntityWritable, EntityPrefWritable> {
private static final Pattern COMMA = Pattern.compile(",");
@@ -44,7 +44,7 @@ public final class UserPrefsPerItemMappe
long itemID = Long.parseLong(tokens[1]);
float pref = Float.parseFloat(tokens[2]);
- context.write(new ItemWritable(itemID), new UserPrefWritable(userID,pref));
+ context.write(new EntityWritable(itemID), new EntityPrefWritable(userID,pref));
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefArrayWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefArrayWritable.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefArrayWritable.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/similarity/item/writables/UserPrefArrayWritable.java Mon Apr 5 06:26:00 2010
@@ -18,23 +18,24 @@
package org.apache.mahout.cf.taste.hadoop.similarity.item.writables;
import org.apache.hadoop.io.ArrayWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
/**
- * An {@link ArrayWritable} holding {@link UserPrefWritable}s
+ * An {@link ArrayWritable} holding {@link EntityPrefWritable}s
*
* Used to represent an item-vector
*/
public final class UserPrefArrayWritable extends ArrayWritable {
public UserPrefArrayWritable() {
- super(UserPrefWritable.class);
+ super(EntityPrefWritable.class);
}
- public UserPrefArrayWritable(UserPrefWritable[] userPrefs) {
- super(UserPrefWritable.class, userPrefs);
+ public UserPrefArrayWritable(EntityPrefWritable[] userPrefs) {
+ super(EntityPrefWritable.class, userPrefs);
}
- public UserPrefWritable[] getUserPrefs() {
- return (UserPrefWritable[]) toArray();
+ public EntityPrefWritable[] getUserPrefs() {
+ return (EntityPrefWritable[]) toArray();
}
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/ByItemIDComparator.java Mon Apr 5 06:26:00 2010
@@ -20,20 +20,20 @@ package org.apache.mahout.cf.taste.hadoo
import java.io.Serializable;
import java.util.Comparator;
-import org.apache.mahout.cf.taste.hadoop.ItemPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
-final class ByItemIDComparator implements Comparator<ItemPrefWritable>, Serializable {
+final class ByItemIDComparator implements Comparator<EntityPrefWritable>, Serializable {
- private static final Comparator<ItemPrefWritable> instance = new ByItemIDComparator();
+ private static final Comparator<EntityPrefWritable> instance = new ByItemIDComparator();
- public static Comparator<ItemPrefWritable> getInstance() {
+ public static Comparator<EntityPrefWritable> getInstance() {
return instance;
}
@Override
- public int compare(ItemPrefWritable a, ItemPrefWritable b) {
- long idA = a.getItemID();
- long idB = b.getItemID();
+ public int compare(EntityPrefWritable a, EntityPrefWritable b) {
+ long idA = a.getID();
+ long idB = b.getID();
return idA < idB ? -1 : idA > idB ? 1 : 0;
}
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOneAverageDiffsJob.java Mon Apr 5 06:26:00 2010
@@ -35,7 +35,7 @@ import org.apache.hadoop.mapred.lib.Iden
import org.apache.hadoop.util.ToolRunner;
import org.apache.mahout.common.AbstractJob;
import org.apache.mahout.cf.taste.hadoop.ItemItemWritable;
-import org.apache.mahout.cf.taste.hadoop.ItemPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
import org.apache.mahout.cf.taste.hadoop.ToItemPrefsMapper;
public final class SlopeOneAverageDiffsJob extends AbstractJob {
@@ -54,7 +54,7 @@ public final class SlopeOneAverageDiffsJ
String averagesOutputPath = parsedArgs.get("--tempDir");
JobConf prefsToDiffsJobConf = prepareJobConf(prefsFile, averagesOutputPath,
- TextInputFormat.class, ToItemPrefsMapper.class, LongWritable.class, ItemPrefWritable.class,
+ TextInputFormat.class, ToItemPrefsMapper.class, LongWritable.class, EntityPrefWritable.class,
SlopeOnePrefsToDiffsReducer.class, ItemItemWritable.class, FloatWritable.class,
SequenceFileOutputFormat.class);
JobClient.runJob(prefsToDiffsJobConf);
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java?rev=930805&r1=930804&r2=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/slopeone/SlopeOnePrefsToDiffsReducer.java Mon Apr 5 06:26:00 2010
@@ -29,30 +29,30 @@ import org.apache.hadoop.mapred.MapReduc
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
import org.apache.mahout.cf.taste.hadoop.ItemItemWritable;
-import org.apache.mahout.cf.taste.hadoop.ItemPrefWritable;
public final class SlopeOnePrefsToDiffsReducer extends MapReduceBase implements
- Reducer<LongWritable,ItemPrefWritable,ItemItemWritable,FloatWritable> {
+ Reducer<LongWritable, EntityPrefWritable,ItemItemWritable,FloatWritable> {
@Override
public void reduce(LongWritable key,
- Iterator<ItemPrefWritable> values,
+ Iterator<EntityPrefWritable> values,
OutputCollector<ItemItemWritable,FloatWritable> output,
Reporter reporter) throws IOException {
- List<ItemPrefWritable> prefs = new ArrayList<ItemPrefWritable>();
+ List<EntityPrefWritable> prefs = new ArrayList<EntityPrefWritable>();
while (values.hasNext()) {
- prefs.add(new ItemPrefWritable(values.next()));
+ prefs.add(new EntityPrefWritable(values.next()));
}
Collections.sort(prefs, ByItemIDComparator.getInstance());
int size = prefs.size();
for (int i = 0; i < size; i++) {
- ItemPrefWritable first = prefs.get(i);
- long itemAID = first.getItemID();
+ EntityPrefWritable first = prefs.get(i);
+ long itemAID = first.getID();
float itemAValue = first.getPrefValue();
for (int j = i + 1; j < size; j++) {
- ItemPrefWritable second = prefs.get(j);
- long itemBID = second.getItemID();
+ EntityPrefWritable second = prefs.get(j);
+ long itemBID = second.getID();
float itemBValue = second.getPrefValue();
output.collect(new ItemItemWritable(itemAID, itemBID), new FloatWritable(itemBValue - itemAValue));
}
Copied: lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java (from r930802, lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/ItemSimilarityTest.java)
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java?p2=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java&p1=lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/ItemSimilarityTest.java&r1=930802&r2=930805&rev=930805&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/ItemSimilarityTest.java (original)
+++ lucene/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/similarity/item/ItemSimilarityTest.java Mon Apr 5 06:26:00 2010
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.mahout.cf.taste.hadoop.similarity;
+package org.apache.mahout.cf.taste.hadoop.similarity.item;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
@@ -41,21 +41,13 @@ import org.apache.hadoop.io.LongWritable
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
+import org.apache.mahout.cf.taste.hadoop.EntityPrefWritable;
+import org.apache.mahout.cf.taste.hadoop.EntityWritable;
import org.apache.mahout.cf.taste.hadoop.ItemItemWritable;
-import org.apache.mahout.cf.taste.hadoop.ItemWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.CopreferredItemsMapper;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.CosineSimilarityReducer;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.ItemSimilarityJob;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.PreferredItemsPerUserMapper;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.PreferredItemsPerUserReducer;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.ToItemVectorReducer;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.UserPrefsPerItemMapper;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPairWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthArrayWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.ItemPrefWithLengthWritable;
import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefArrayWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserPrefWritable;
-import org.apache.mahout.cf.taste.hadoop.similarity.item.writables.UserWritable;
import org.apache.mahout.common.MahoutTestCase;
import org.easymock.IArgumentMatcher;
import org.easymock.classextension.EasyMock;
@@ -65,13 +57,12 @@ import org.easymock.classextension.EasyM
* Integration test with a mini-file at the end
*
*/
-@SuppressWarnings("unchecked")
public class ItemSimilarityTest extends MahoutTestCase {
public void testUserPrefsPerItemMapper() throws Exception {
Mapper.Context ctx = createMock(Mapper.Context.class);
- ctx.write(new ItemWritable(34l), new UserPrefWritable(12l, 2.3f));
+ ctx.write(new EntityWritable(34L), new EntityPrefWritable(12L, 2.3f));
replay(ctx);
new UserPrefsPerItemMapper().map(new LongWritable(), new Text("12,34,2.3"), ctx);
@@ -81,35 +72,33 @@ public class ItemSimilarityTest extends
public void testToItemVectorReducer() throws Exception {
- List<UserPrefWritable> userPrefs = Arrays.asList(new UserPrefWritable(34l, 1f), new UserPrefWritable(56l, 2f));
+ List<EntityPrefWritable> userPrefs = Arrays.asList(new EntityPrefWritable(34L, 1.0f), new EntityPrefWritable(56L, 2.0f));
Reducer.Context ctx = createMock(Reducer.Context.class);
- ctx.write(eq(new ItemWritable(12l)), equalToUserPrefs(userPrefs));
+ ctx.write(eq(new EntityWritable(12L)), equalToUserPrefs(userPrefs));
replay(ctx);
- new ToItemVectorReducer().reduce(new ItemWritable(12l), userPrefs, ctx);
+ new ToItemVectorReducer().reduce(new EntityWritable(12L), userPrefs, ctx);
verify(ctx);
}
- static UserPrefArrayWritable equalToUserPrefs(final Collection<UserPrefWritable> prefsToCheck) {
+ static UserPrefArrayWritable equalToUserPrefs(final Collection<EntityPrefWritable> prefsToCheck) {
EasyMock.reportMatcher(new IArgumentMatcher() {
@Override
public boolean matches(Object argument) {
if (argument instanceof UserPrefArrayWritable) {
UserPrefArrayWritable userPrefArray = (UserPrefArrayWritable) argument;
- Set<UserPrefWritable> set = new HashSet<UserPrefWritable>();
- for (UserPrefWritable userPref : userPrefArray.getUserPrefs()) {
- set.add(userPref);
- }
+ Set<EntityPrefWritable> set = new HashSet<EntityPrefWritable>();
+ set.addAll(Arrays.asList(userPrefArray.getUserPrefs()));
if (set.size() != prefsToCheck.size()) {
return false;
}
- for (UserPrefWritable prefToCheck : prefsToCheck) {
+ for (EntityPrefWritable prefToCheck : prefsToCheck) {
if (!set.contains(prefToCheck)) {
return false;
}
@@ -131,16 +120,16 @@ public class ItemSimilarityTest extends
UserPrefArrayWritable userPrefs = createMock(UserPrefArrayWritable.class);
expect(userPrefs.getUserPrefs())
- .andReturn(new UserPrefWritable[] { new UserPrefWritable(12l, 2f), new UserPrefWritable(56l, 3f) });
+ .andReturn(new EntityPrefWritable[] { new EntityPrefWritable(12L, 2.0f), new EntityPrefWritable(56L, 3.0f) });
- double length = Math.sqrt(Math.pow(2f, 2) + Math.pow(3f, 2));
+ double length = Math.sqrt(Math.pow(2.0f, 2) + Math.pow(3.0f, 2));
- ctx.write(new UserWritable(12l), new ItemPrefWithLengthWritable(34l, length, 2f));
- ctx.write(new UserWritable(56l), new ItemPrefWithLengthWritable(34l, length, 3f));
+ ctx.write(new EntityWritable(12L), new ItemPrefWithLengthWritable(34L, length, 2.0f));
+ ctx.write(new EntityWritable(56L), new ItemPrefWithLengthWritable(34L, length, 3.0f));
replay(ctx, userPrefs);
- new PreferredItemsPerUserMapper().map(new ItemWritable(34l), userPrefs, ctx);
+ new PreferredItemsPerUserMapper().map(new EntityWritable(34L), userPrefs, ctx);
verify(ctx, userPrefs);
}
@@ -148,15 +137,15 @@ public class ItemSimilarityTest extends
public void testPreferredItemsPerUserReducer() throws Exception {
List<ItemPrefWithLengthWritable> itemPrefs =
- Arrays.asList(new ItemPrefWithLengthWritable(34l, 5d, 1f), new ItemPrefWithLengthWritable(56l, 7d, 2f));
+ Arrays.asList(new ItemPrefWithLengthWritable(34L, 5.0, 1.0f), new ItemPrefWithLengthWritable(56L, 7.0, 2.0f));
Reducer.Context ctx = createMock(Reducer.Context.class);
- ctx.write(eq(new UserWritable(12l)), equalToItemPrefs(itemPrefs));
+ ctx.write(eq(new EntityWritable(12L)), equalToItemPrefs(itemPrefs));
replay(ctx);
- new PreferredItemsPerUserReducer().reduce(new UserWritable(12l), itemPrefs, ctx);
+ new PreferredItemsPerUserReducer().reduce(new EntityWritable(12L), itemPrefs, ctx);
verify(ctx);
}
@@ -198,16 +187,16 @@ public class ItemSimilarityTest extends
ItemPrefWithLengthArrayWritable itemPrefs = createMock(ItemPrefWithLengthArrayWritable.class);
expect(itemPrefs.getItemPrefs()).andReturn(new ItemPrefWithLengthWritable[] {
- new ItemPrefWithLengthWritable(34l, 2d, 1f), new ItemPrefWithLengthWritable(56l, 3d, 2f),
- new ItemPrefWithLengthWritable(78l, 4d, 3f) });
+ new ItemPrefWithLengthWritable(34L, 2.0, 1.0f), new ItemPrefWithLengthWritable(56L, 3.0, 2.0f),
+ new ItemPrefWithLengthWritable(78L, 4.0, 3.0f) });
- ctx.write(new ItemPairWritable(34l, 56l, 6d), new FloatWritable(2f));
- ctx.write(new ItemPairWritable(34l, 78l, 8d), new FloatWritable(3f));
- ctx.write(new ItemPairWritable(56l, 78l, 12d), new FloatWritable(6f));
+ ctx.write(new ItemPairWritable(34L, 56L, 6.0), new FloatWritable(2.0f));
+ ctx.write(new ItemPairWritable(34L, 78L, 8.0), new FloatWritable(3.0f));
+ ctx.write(new ItemPairWritable(56L, 78L, 12.0), new FloatWritable(6.0f));
replay(ctx, itemPrefs);
- new CopreferredItemsMapper().map(new UserWritable(), itemPrefs, ctx);
+ new CopreferredItemsMapper().map(new EntityWritable(), itemPrefs, ctx);
verify(ctx, itemPrefs);
}
@@ -215,19 +204,19 @@ public class ItemSimilarityTest extends
public void testCosineSimilarityReducer() throws Exception {
Reducer.Context ctx = createMock(Reducer.Context.class);
- ctx.write(new ItemItemWritable(12l, 34l), new DoubleWritable(0.5d));
+ ctx.write(new ItemItemWritable(12L, 34L), new DoubleWritable(0.5d));
replay(ctx);
- new CosineSimilarityReducer().reduce(new ItemPairWritable(12l, 34l, 20d),
- Arrays.asList(new FloatWritable(5f), new FloatWritable(5f)), ctx);
+ new CosineSimilarityReducer().reduce(new ItemPairWritable(12L, 34L, 20.0),
+ Arrays.asList(new FloatWritable(5.0f), new FloatWritable(5.0f)), ctx);
verify(ctx);
}
public void testCompleteJob() throws Exception {
- String tmpDirPath = System.getProperty("java.io.tmpdir")+"/"+ItemSimilarityTest.class.getCanonicalName();
+ String tmpDirPath = System.getProperty("java.io.tmpdir")+ '/' +ItemSimilarityTest.class.getCanonicalName();
File tmpDir = new File(tmpDirPath);
try {
@@ -279,14 +268,14 @@ public class ItemSimilarityTest extends
double similarity = Double.parseDouble(tokens[2]);
if (currentLine == 1) {
- assertEquals(1l, itemAID);
- assertEquals(3l, itemBID);
+ assertEquals(1L, itemAID);
+ assertEquals(3L, itemBID);
assertEquals(0.45, similarity, 0.01);
}
if (currentLine == 2) {
- assertEquals(2l, itemAID);
- assertEquals(3l, itemBID);
+ assertEquals(2L, itemAID);
+ assertEquals(3L, itemBID);
assertEquals(0.89, similarity, 0.01);
}