mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r942328 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java
Date Sat, 08 May 2010 07:20:03 GMT
Author: srowen
Date: Sat May  8 07:20:03 2010
New Revision: 942328

URL: http://svn.apache.org/viewvc?rev=942328&view=rev
Log:
Add ability to transpose user and item in mapper

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java?rev=942328&r1=942327&r2=942328&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/ToEntityPrefsMapper.java
Sat May  8 07:20:03 2010
@@ -32,9 +32,12 @@ import java.util.regex.Pattern;
 abstract class ToEntityPrefsMapper extends MapReduceBase implements
     Mapper<LongWritable,Text,LongWritable,LongWritable> {
 
-  private static final Pattern COMMA = Pattern.compile(",");
+  static final String TRANSPOSE_USER_ITEM = "transposeUserItem";
+
+  private static final Pattern DELIMITER = Pattern.compile("[\t,]");
 
   private boolean booleanData;
+  private boolean transpose;
   private final boolean itemKey;
 
   ToEntityPrefsMapper(boolean itemKey) {
@@ -44,6 +47,7 @@ abstract class ToEntityPrefsMapper exten
   @Override
   public void configure(JobConf jobConf) {
     booleanData = jobConf.getBoolean(RecommenderJob.BOOLEAN_DATA, false);
+    transpose = jobConf.getBoolean(TRANSPOSE_USER_ITEM, false);
   }
 
   @Override
@@ -51,10 +55,13 @@ abstract class ToEntityPrefsMapper exten
                   Text value,
                   OutputCollector<LongWritable,LongWritable> output,
                   Reporter reporter) throws IOException {
-    String[] tokens = ToEntityPrefsMapper.COMMA.split(value.toString());
+    String[] tokens = ToEntityPrefsMapper.DELIMITER.split(value.toString());
     long userID = Long.parseLong(tokens[0]);
     long itemID = Long.parseLong(tokens[1]);
-    if (itemKey) {
+    if (itemKey ^ transpose) {
+      // If using items as keys, and not transposing items and users, then users are items!
+      // Or if not using items as keys (users are, as usual), but transposing items and users,
+      // then users are items! Confused?
       long temp = userID;
       userID = itemID;
       itemID = temp;



Mime
View raw message