mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robina...@apache.org
Subject svn commit: r909912 [6/10] - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: common/ eval/ hadoop/ hadoop/cooccurence/ hadoop/item/ hadoop/pseudo/ hadoop/slopeone/ impl/common/ impl/common/jdbc/ impl/eval/ impl/model/ impl/model/...
Date Sat, 13 Feb 2010 20:54:31 GMT
Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLBooleanPrefJDBCDataModel.java Sat Feb 13 20:54:05 2010
@@ -17,16 +17,22 @@
 
 package org.apache.mahout.cf.taste.impl.model.jdbc;
 
-import org.apache.mahout.cf.taste.common.TasteException;
-
-import javax.sql.DataSource;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent;
+
 /**
- * <p>See also {@link MySQLJDBCDataModel} -- same except deals with a table without preference info:</p>
- *
- * <p><pre>
+ * <p>
+ * See also {@link MySQLJDBCDataModel} -- same except deals with a table without preference info:
+ * </p>
+ * 
+ * <p>
+ * 
+ * <pre>
  * CREATE TABLE taste_preferences (
  *   user_id BIGINT NOT NULL,
  *   item_id BIGINT NOT NULL,
@@ -34,75 +40,87 @@
  *   INDEX (user_id),
  *   INDEX (item_id)
  * )
- * </pre></p>
+ * </pre>
+ * 
+ * </p>
  */
 public class MySQLBooleanPrefJDBCDataModel extends AbstractBooleanPrefJDBCDataModel {
-
+  
   private static final String NO_SUCH_COLUMN = "NO_SUCH_COLUMN";
-
+  
   /**
-   * <p>Creates a {@link MySQLBooleanPrefJDBCDataModel} using the default {@link javax.sql.DataSource} (named {@link
-   * #DEFAULT_DATASOURCE_NAME} and default table/column names.</p>
-   *
+   * <p>
+   * Creates a {@link MySQLBooleanPrefJDBCDataModel} using the default {@link javax.sql.DataSource} (named
+   * {@link #DEFAULT_DATASOURCE_NAME} and default table/column names.
+   * </p>
+   * 
    * @throws org.apache.mahout.cf.taste.common.TasteException
-   *          if {@link javax.sql.DataSource} can't be found
+   *           if {@link javax.sql.DataSource} can't be found
    */
   public MySQLBooleanPrefJDBCDataModel() throws TasteException {
-    this(DEFAULT_DATASOURCE_NAME);
+    this(AbstractJDBCComponent.DEFAULT_DATASOURCE_NAME);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLBooleanPrefJDBCDataModel} using the default {@link javax.sql.DataSource} found under the
-   * given name, and using default table/column names.</p>
-   *
-   * @param dataSourceName name of {@link javax.sql.DataSource} to look up
+   * <p>
+   * Creates a {@link MySQLBooleanPrefJDBCDataModel} using the default {@link javax.sql.DataSource} found
+   * under the given name, and using default table/column names.
+   * </p>
+   * 
+   * @param dataSourceName
+   *          name of {@link javax.sql.DataSource} to look up
    * @throws org.apache.mahout.cf.taste.common.TasteException
-   *          if {@link javax.sql.DataSource} can't be found
+   *           if {@link javax.sql.DataSource} can't be found
    */
   public MySQLBooleanPrefJDBCDataModel(String dataSourceName) throws TasteException {
-    this(lookupDataSource(dataSourceName),
-        DEFAULT_PREFERENCE_TABLE,
-        DEFAULT_USER_ID_COLUMN,
-        DEFAULT_ITEM_ID_COLUMN);
+    this(AbstractJDBCComponent.lookupDataSource(dataSourceName),
+        AbstractJDBCDataModel.DEFAULT_PREFERENCE_TABLE, AbstractJDBCDataModel.DEFAULT_USER_ID_COLUMN,
+        AbstractJDBCDataModel.DEFAULT_ITEM_ID_COLUMN);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLBooleanPrefJDBCDataModel} using the given {@link javax.sql.DataSource} and default
-   * table/column names.</p>
-   *
-   * @param dataSource {@link javax.sql.DataSource} to use
+   * <p>
+   * Creates a {@link MySQLBooleanPrefJDBCDataModel} using the given {@link javax.sql.DataSource} and default
+   * table/column names.
+   * </p>
+   * 
+   * @param dataSource
+   *          {@link javax.sql.DataSource} to use
    */
   public MySQLBooleanPrefJDBCDataModel(DataSource dataSource) {
-    this(dataSource,
-        DEFAULT_PREFERENCE_TABLE,
-        DEFAULT_USER_ID_COLUMN,
-        DEFAULT_ITEM_ID_COLUMN);
+    this(dataSource, AbstractJDBCDataModel.DEFAULT_PREFERENCE_TABLE,
+        AbstractJDBCDataModel.DEFAULT_USER_ID_COLUMN, AbstractJDBCDataModel.DEFAULT_ITEM_ID_COLUMN);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLBooleanPrefJDBCDataModel} using the given {@link javax.sql.DataSource} and default
-   * table/column names.</p>
-   *
-   * @param dataSource      {@link javax.sql.DataSource} to use
-   * @param preferenceTable name of table containing preference data
-   * @param userIDColumn    user ID column name
-   * @param itemIDColumn    item ID column name
+   * <p>
+   * Creates a {@link MySQLBooleanPrefJDBCDataModel} using the given {@link javax.sql.DataSource} and default
+   * table/column names.
+   * </p>
+   * 
+   * @param dataSource
+   *          {@link javax.sql.DataSource} to use
+   * @param preferenceTable
+   *          name of table containing preference data
+   * @param userIDColumn
+   *          user ID column name
+   * @param itemIDColumn
+   *          item ID column name
    */
   public MySQLBooleanPrefJDBCDataModel(DataSource dataSource,
                                        String preferenceTable,
                                        String userIDColumn,
                                        String itemIDColumn) {
-    super(dataSource,
-        preferenceTable,
-        userIDColumn,
-        itemIDColumn,
-        NO_SUCH_COLUMN,
+    super(dataSource, preferenceTable, userIDColumn, itemIDColumn,
+        MySQLBooleanPrefJDBCDataModel.NO_SUCH_COLUMN,
         // getPreferenceSQL
         "SELECT 1 FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND " + itemIDColumn + "=?",
         // getUserSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " WHERE " + userIDColumn + "=?",
+        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " WHERE "
+            + userIDColumn + "=?",
         // getAllUsersSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY " + userIDColumn,
+        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY "
+            + userIDColumn,
         // getNumItemsSQL
         "SELECT COUNT(DISTINCT " + itemIDColumn + ") FROM " + preferenceTable,
         // getNumUsersSQL
@@ -116,28 +134,28 @@
         // getItemsSQL
         "SELECT DISTINCT " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY " + itemIDColumn,
         // getPrefsForItemSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " +
-            preferenceTable + " WHERE " + itemIDColumn + "=? ORDER BY " + userIDColumn,
+        "SELECT " + userIDColumn + ", " + itemIDColumn + " FROM " + preferenceTable + " WHERE "
+            + itemIDColumn + "=? ORDER BY " + userIDColumn,
         // getNumPreferenceForItemSQL
         "SELECT COUNT(1) FROM " + preferenceTable + " WHERE " + itemIDColumn + "=?",
         // getNumPreferenceForItemsSQL
-        "SELECT COUNT(1) FROM " + preferenceTable + " tp1 JOIN " + preferenceTable + " tp2 " +
-            "USING (" + userIDColumn + ") WHERE tp1." + itemIDColumn + "=? and tp2." + itemIDColumn + "=?");
+        "SELECT COUNT(1) FROM " + preferenceTable + " tp1 JOIN " + preferenceTable + " tp2 " + "USING ("
+            + userIDColumn + ") WHERE tp1." + itemIDColumn + "=? and tp2." + itemIDColumn + "=?");
   }
-
+  
   @Override
   protected int getFetchSize() {
     // Need to return this for MySQL Connector/J to make it use streaming mode
     return Integer.MIN_VALUE;
   }
-
+  
   @Override
   protected void advanceResultSet(ResultSet resultSet, int n) throws SQLException {
     // Can't use relative on MySQL Connector/J
     int i = 0;
-    while (i < n && resultSet.next()) {
+    while ((i < n) && resultSet.next()) {
       i++;
     }
   }
-
+  
 }
\ No newline at end of file

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java Sat Feb 13 20:54:05 2010
@@ -17,32 +17,59 @@
 
 package org.apache.mahout.cf.taste.impl.model.jdbc;
 
-import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.model.DataModel;
-
-import javax.sql.DataSource;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+import javax.sql.DataSource;
+
+import org.apache.mahout.cf.taste.common.TasteException;
+import org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent;
+import org.apache.mahout.cf.taste.model.DataModel;
+
 /**
- * <p>A {@link DataModel} backed by a MySQL database and accessed via JDBC. It may work with other JDBC databases. By
- * default, this class assumes that there is a {@link DataSource} available under the JNDI name "jdbc/taste", which
- * gives access to a database with a "taste_preferences" table with the following schema:</p>
- *
+ * <p>
+ * A {@link DataModel} backed by a MySQL database and accessed via JDBC. It may work with other JDBC
+ * databases. By default, this class assumes that there is a {@link DataSource} available under the JNDI name
+ * "jdbc/taste", which gives access to a database with a "taste_preferences" table with the following schema:
+ * </p>
+ * 
  * <table>
- * <tr><th>user_id</th><th>item_id</th><th>preference</th></tr>
- * <tr><td>987</td><td>123</td><td>0.9</td></tr>
- * <tr><td>987</td><td>456</td><td>0.1</td></tr>
- * <tr><td>654</td><td>123</td><td>0.2</td></tr>
- * <tr><td>654</td><td>789</td><td>0.3</td></tr>
+ * <tr>
+ * <th>user_id</th>
+ * <th>item_id</th>
+ * <th>preference</th>
+ * </tr>
+ * <tr>
+ * <td>987</td>
+ * <td>123</td>
+ * <td>0.9</td>
+ * </tr>
+ * <tr>
+ * <td>987</td>
+ * <td>456</td>
+ * <td>0.1</td>
+ * </tr>
+ * <tr>
+ * <td>654</td>
+ * <td>123</td>
+ * <td>0.2</td>
+ * </tr>
+ * <tr>
+ * <td>654</td>
+ * <td>789</td>
+ * <td>0.3</td>
+ * </tr>
  * </table>
- *
- * <p><code>preference</code> must have a type compatible
- * with the Java <code>float</code> type. <code>user_id</code> and <code>item_id</code> should be compatible
- * with long type (BIGINT). For example, the following command sets up a suitable table in MySQL,
- * complete with primary key and indexes:</p>
- *
- * <p><pre>
+ * 
+ * <p>
+ * <code>preference</code> must have a type compatible with the Java <code>float</code> type.
+ * <code>user_id</code> and <code>item_id</code> should be compatible with long type (BIGINT). For example,
+ * the following command sets up a suitable table in MySQL, complete with primary key and indexes:
+ * </p>
+ * 
+ * <p>
+ * 
+ * <pre>
  * CREATE TABLE taste_preferences (
  *   user_id BIGINT NOT NULL,
  *   item_id BIGINT NOT NULL,
@@ -51,20 +78,28 @@
  *   INDEX (user_id),
  *   INDEX (item_id)
  * )
- * </pre></p>
- *
+ * </pre>
+ * 
+ * </p>
+ * 
  * <h3>Performance Notes</h3>
- *
- * <p>See the notes in {@link AbstractJDBCDataModel} regarding using connection pooling. It's pretty vital to
- * performance.</p>
- *
- * <p>Some experimentation suggests that MySQL's InnoDB engine is faster than MyISAM for these kinds of applications.
- * While MyISAM is the default and, I believe, generally considered the lighter-weight and faster of the two engines, my
- * guess is the row-level locking of InnoDB helps here. Your mileage may vary.</p>
- *
- * <p>Here are some key settings that can be tuned for MySQL, and suggested size for a data set of around 1 million
- * elements:</p>
- *
+ * 
+ * <p>
+ * See the notes in {@link AbstractJDBCDataModel} regarding using connection pooling. It's pretty vital to
+ * performance.
+ * </p>
+ * 
+ * <p>
+ * Some experimentation suggests that MySQL's InnoDB engine is faster than MyISAM for these kinds of
+ * applications. While MyISAM is the default and, I believe, generally considered the lighter-weight and
+ * faster of the two engines, my guess is the row-level locking of InnoDB helps here. Your mileage may vary.
+ * </p>
+ * 
+ * <p>
+ * Here are some key settings that can be tuned for MySQL, and suggested size for a data set of around 1
+ * million elements:
+ * </p>
+ * 
  * <ul>
  * <li>innodb_buffer_pool_size=64M</li>
  * <li>myisam_sort_buffer_size=64M</li>
@@ -73,9 +108,11 @@
  * <li>query_cache_type=1</li>
  * <li>query_cache_size=64M</li>
  * </ul>
- *
- * <p>Also consider setting some parameters on the MySQL Connector/J driver:</p>
- *
+ * 
+ * <p>
+ * Also consider setting some parameters on the MySQL Connector/J driver:
+ * </p>
+ * 
  * <pre>
  * cachePreparedStatements = true
  * cachePrepStmts = true
@@ -83,84 +120,95 @@
  * alwaysSendSetIsolation = false
  * elideSetAutoCommits = true
  * </pre>
- *
- * <p>Thanks to Amila Jayasooriya for contributing MySQL notes above as part of Google Summer of Code 2007.</p>
+ * 
+ * <p>
+ * Thanks to Amila Jayasooriya for contributing MySQL notes above as part of Google Summer of Code 2007.
+ * </p>
  */
 public class MySQLJDBCDataModel extends AbstractJDBCDataModel {
-
+  
   /**
-   * <p>Creates a {@link MySQLJDBCDataModel} using the default {@link DataSource} (named {@link
-   * #DEFAULT_DATASOURCE_NAME} and default table/column names.</p>
-   *
-   * @throws TasteException if {@link DataSource} can't be found
+   * <p>
+   * Creates a {@link MySQLJDBCDataModel} using the default {@link DataSource} (named
+   * {@link #DEFAULT_DATASOURCE_NAME} and default table/column names.
+   * </p>
+   * 
+   * @throws TasteException
+   *           if {@link DataSource} can't be found
    */
   public MySQLJDBCDataModel() throws TasteException {
-    this(DEFAULT_DATASOURCE_NAME);
+    this(AbstractJDBCComponent.DEFAULT_DATASOURCE_NAME);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLJDBCDataModel} using the default {@link DataSource} found under the given name, and using
-   * default table/column names.</p>
-   *
-   * @param dataSourceName name of {@link DataSource} to look up
-   * @throws TasteException if {@link DataSource} can't be found
+   * <p>
+   * Creates a {@link MySQLJDBCDataModel} using the default {@link DataSource} found under the given name, and
+   * using default table/column names.
+   * </p>
+   * 
+   * @param dataSourceName
+   *          name of {@link DataSource} to look up
+   * @throws TasteException
+   *           if {@link DataSource} can't be found
    */
   public MySQLJDBCDataModel(String dataSourceName) throws TasteException {
-    this(lookupDataSource(dataSourceName),
-        DEFAULT_PREFERENCE_TABLE,
-        DEFAULT_USER_ID_COLUMN,
-        DEFAULT_ITEM_ID_COLUMN,
-        DEFAULT_PREFERENCE_COLUMN);
+    this(AbstractJDBCComponent.lookupDataSource(dataSourceName),
+        AbstractJDBCDataModel.DEFAULT_PREFERENCE_TABLE, AbstractJDBCDataModel.DEFAULT_USER_ID_COLUMN,
+        AbstractJDBCDataModel.DEFAULT_ITEM_ID_COLUMN, AbstractJDBCDataModel.DEFAULT_PREFERENCE_COLUMN);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLJDBCDataModel} using the given {@link DataSource} and default table/column names.</p>
-   *
-   * @param dataSource {@link DataSource} to use
+   * <p>
+   * Creates a {@link MySQLJDBCDataModel} using the given {@link DataSource} and default table/column names.
+   * </p>
+   * 
+   * @param dataSource
+   *          {@link DataSource} to use
    */
   public MySQLJDBCDataModel(DataSource dataSource) {
-    this(dataSource,
-        DEFAULT_PREFERENCE_TABLE,
-        DEFAULT_USER_ID_COLUMN,
-        DEFAULT_ITEM_ID_COLUMN,
-        DEFAULT_PREFERENCE_COLUMN);
+    this(dataSource, AbstractJDBCDataModel.DEFAULT_PREFERENCE_TABLE,
+        AbstractJDBCDataModel.DEFAULT_USER_ID_COLUMN, AbstractJDBCDataModel.DEFAULT_ITEM_ID_COLUMN,
+        AbstractJDBCDataModel.DEFAULT_PREFERENCE_COLUMN);
   }
-
+  
   /**
-   * <p>Creates a {@link MySQLJDBCDataModel} using the given {@link DataSource} and default table/column names.</p>
-   *
-   * @param dataSource       {@link DataSource} to use
-   * @param preferenceTable  name of table containing preference data
-   * @param userIDColumn     user ID column name
-   * @param itemIDColumn     item ID column name
-   * @param preferenceColumn preference column name
+   * <p>
+   * Creates a {@link MySQLJDBCDataModel} using the given {@link DataSource} and default table/column names.
+   * </p>
+   * 
+   * @param dataSource
+   *          {@link DataSource} to use
+   * @param preferenceTable
+   *          name of table containing preference data
+   * @param userIDColumn
+   *          user ID column name
+   * @param itemIDColumn
+   *          item ID column name
+   * @param preferenceColumn
+   *          preference column name
    */
   public MySQLJDBCDataModel(DataSource dataSource,
                             String preferenceTable,
                             String userIDColumn,
                             String itemIDColumn,
                             String preferenceColumn) {
-    super(dataSource,
-        preferenceTable,
-        userIDColumn,
-        itemIDColumn,
-        preferenceColumn,
-        // getPreferenceSQL
-        "SELECT " + preferenceColumn + " FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND " +
-            itemIDColumn + "=?",
+    super(dataSource, preferenceTable, userIDColumn, itemIDColumn, preferenceColumn,
+    // getPreferenceSQL
+        "SELECT " + preferenceColumn + " FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND "
+            + itemIDColumn + "=?",
         // getUserSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable +
-            " WHERE " + userIDColumn + "=? ORDER BY " + itemIDColumn,
+        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable
+            + " WHERE " + userIDColumn + "=? ORDER BY " + itemIDColumn,
         // getAllUsersSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable +
-            " ORDER BY " + userIDColumn + ", " + itemIDColumn,
+        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable
+            + " ORDER BY " + userIDColumn + ", " + itemIDColumn,
         // getNumItemsSQL
         "SELECT COUNT(DISTINCT " + itemIDColumn + ") FROM " + preferenceTable,
         // getNumUsersSQL
         "SELECT COUNT(DISTINCT " + userIDColumn + ") FROM " + preferenceTable,
         // setPreferenceSQL
-        "INSERT INTO " + preferenceTable + '(' + userIDColumn + ',' + itemIDColumn + ',' + preferenceColumn +
-            ") VALUES (?,?,?) ON DUPLICATE KEY UPDATE " + preferenceColumn + "=?",
+        "INSERT INTO " + preferenceTable + '(' + userIDColumn + ',' + itemIDColumn + ',' + preferenceColumn
+            + ") VALUES (?,?,?) ON DUPLICATE KEY UPDATE " + preferenceColumn + "=?",
         // removePreference SQL
         "DELETE FROM " + preferenceTable + " WHERE " + userIDColumn + "=? AND " + itemIDColumn + "=?",
         // getUsersSQL
@@ -168,28 +216,28 @@
         // getItemsSQL
         "SELECT DISTINCT " + itemIDColumn + " FROM " + preferenceTable + " ORDER BY " + itemIDColumn,
         // getPrefsForItemSQL
-        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " +
-            preferenceTable + " WHERE " + itemIDColumn + "=? ORDER BY " + userIDColumn,
+        "SELECT " + userIDColumn + ", " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable
+            + " WHERE " + itemIDColumn + "=? ORDER BY " + userIDColumn,
         // getNumPreferenceForItemSQL
         "SELECT COUNT(1) FROM " + preferenceTable + " WHERE " + itemIDColumn + "=?",
         // getNumPreferenceForItemsSQL
-        "SELECT COUNT(1) FROM " + preferenceTable + " tp1 JOIN " + preferenceTable + " tp2 " +
-            "USING (" + userIDColumn + ") WHERE tp1." + itemIDColumn + "=? and tp2." + itemIDColumn + "=?");
+        "SELECT COUNT(1) FROM " + preferenceTable + " tp1 JOIN " + preferenceTable + " tp2 " + "USING ("
+            + userIDColumn + ") WHERE tp1." + itemIDColumn + "=? and tp2." + itemIDColumn + "=?");
   }
-
+  
   @Override
   protected int getFetchSize() {
     // Need to return this for MySQL Connector/J to make it use streaming mode
     return Integer.MIN_VALUE;
   }
-
+  
   @Override
   protected void advanceResultSet(ResultSet resultSet, int n) throws SQLException {
     // Can't use relative on MySQL Connector/J
     int i = 0;
-    while (i < n && resultSet.next()) {
+    while ((i < n) && resultSet.next()) {
       i++;
     }
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/AbstractUserNeighborhood.java Sat Feb 13 20:54:05 2010
@@ -17,29 +17,31 @@
 
 package org.apache.mahout.cf.taste.impl.neighborhood;
 
+import java.util.Collection;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
-import java.util.Collection;
-
-/** <p>Contains methods and resources useful to all classes in this package.</p> */
+/**
+ * <p>
+ * Contains methods and resources useful to all classes in this package.
+ * </p>
+ */
 abstract class AbstractUserNeighborhood implements UserNeighborhood {
-
+  
   private final UserSimilarity userSimilarity;
   private final DataModel dataModel;
   private final double samplingRate;
   private final RefreshHelper refreshHelper;
-
-  AbstractUserNeighborhood(UserSimilarity userSimilarity,
-                           DataModel dataModel,
-                           double samplingRate) {
-    if (userSimilarity == null || dataModel == null) {
+  
+  AbstractUserNeighborhood(UserSimilarity userSimilarity, DataModel dataModel, double samplingRate) {
+    if ((userSimilarity == null) || (dataModel == null)) {
       throw new IllegalArgumentException("userSimilarity or dataModel is null");
     }
-    if (Double.isNaN(samplingRate) || samplingRate <= 0.0 || samplingRate > 1.0) {
+    if (Double.isNaN(samplingRate) || (samplingRate <= 0.0) || (samplingRate > 1.0)) {
       throw new IllegalArgumentException("samplingRate must be in (0,1]");
     }
     this.userSimilarity = userSimilarity;
@@ -49,22 +51,22 @@
     this.refreshHelper.addDependency(this.dataModel);
     this.refreshHelper.addDependency(this.userSimilarity);
   }
-
+  
   final UserSimilarity getUserSimilarity() {
     return userSimilarity;
   }
-
+  
   final DataModel getDataModel() {
     return dataModel;
   }
-
+  
   final double getSamplingRate() {
     return samplingRate;
   }
-
+  
   @Override
   public final void refresh(Collection<Refreshable> alreadyRefreshed) {
     refreshHelper.refresh(alreadyRefreshed);
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/CachingUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/CachingUserNeighborhood.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/CachingUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/CachingUserNeighborhood.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,8 @@
 
 package org.apache.mahout.cf.taste.impl.neighborhood;
 
+import java.util.Collection;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.Cache;
@@ -25,47 +27,44 @@
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
 
-import java.util.Collection;
-
 /** A caching wrapper around an underlying {@link UserNeighborhood} implementation. */
 public final class CachingUserNeighborhood implements UserNeighborhood {
-
+  
   private final UserNeighborhood neighborhood;
-  private final Cache<Long, long[]> neighborhoodCache;
-
+  private final Cache<Long,long[]> neighborhoodCache;
+  
   public CachingUserNeighborhood(UserNeighborhood neighborhood, DataModel dataModel) throws TasteException {
     if (neighborhood == null) {
       throw new IllegalArgumentException("neighborhood is null");
     }
     this.neighborhood = neighborhood;
     int maxCacheSize = dataModel.getNumUsers(); // just a dumb heuristic for sizing
-    this.neighborhoodCache = new Cache<Long, long[]>(
-            new NeighborhoodRetriever(neighborhood), maxCacheSize);
+    this.neighborhoodCache = new Cache<Long,long[]>(new NeighborhoodRetriever(neighborhood), maxCacheSize);
   }
-
+  
   @Override
   public long[] getUserNeighborhood(long userID) throws TasteException {
     return neighborhoodCache.get(userID);
   }
-
+  
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     neighborhoodCache.clear();
     alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
     RefreshHelper.maybeRefresh(alreadyRefreshed, neighborhood);
   }
-
-  private static final class NeighborhoodRetriever implements Retriever<Long, long[]> {
+  
+  private static final class NeighborhoodRetriever implements Retriever<Long,long[]> {
     private final UserNeighborhood neighborhood;
-
+    
     private NeighborhoodRetriever(UserNeighborhood neighborhood) {
       this.neighborhood = neighborhood;
     }
-
+    
     @Override
     public long[] get(Long key) throws TasteException {
       return neighborhood.getUserNeighborhood(key);
     }
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/NearestNUserNeighborhood.java Sat Feb 13 20:54:05 2010
@@ -25,32 +25,41 @@
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
 /**
- * <p>Computes a neighborhood consisting of the nearest n users to a given user. "Nearest" is defined by
- * the given {@link UserSimilarity}.</p>
+ * <p>
+ * Computes a neighborhood consisting of the nearest n users to a given user. "Nearest" is defined by the
+ * given {@link UserSimilarity}.
+ * </p>
  */
 public final class NearestNUserNeighborhood extends AbstractUserNeighborhood {
-
+  
   private final int n;
   private final double minSimilarity;
-
+  
   /**
-   * @param n              neighborhood size
-   * @param userSimilarity nearness metric
-   * @param dataModel      data model
-   * @throws IllegalArgumentException if n &lt; 1, or userSimilarity or dataModel are <code>null</code>
+   * @param n
+   *          neighborhood size
+   * @param userSimilarity
+   *          nearness metric
+   * @param dataModel
+   *          data model
+   * @throws IllegalArgumentException
+   *           if n &lt; 1, or userSimilarity or dataModel are <code>null</code>
    */
-  public NearestNUserNeighborhood(int n,
-                                  UserSimilarity userSimilarity,
-                                  DataModel dataModel) {
+  public NearestNUserNeighborhood(int n, UserSimilarity userSimilarity, DataModel dataModel) {
     this(n, Double.NEGATIVE_INFINITY, userSimilarity, dataModel, 1.0);
   }
-
+  
   /**
-   * @param n              neighborhood size
-   * @param minSimilarity  minimal similarity required for neighbors
-   * @param userSimilarity nearness metric
-   * @param dataModel      data model
-   * @throws IllegalArgumentException if n &lt; 1, or userSimilarity or dataModel are <code>null</code>
+   * @param n
+   *          neighborhood size
+   * @param minSimilarity
+   *          minimal similarity required for neighbors
+   * @param userSimilarity
+   *          nearness metric
+   * @param dataModel
+   *          data model
+   * @throws IllegalArgumentException
+   *           if n &lt; 1, or userSimilarity or dataModel are <code>null</code>
    */
   public NearestNUserNeighborhood(int n,
                                   double minSimilarity,
@@ -58,16 +67,22 @@
                                   DataModel dataModel) {
     this(n, minSimilarity, userSimilarity, dataModel, 1.0);
   }
-
+  
   /**
-   * @param n              neighborhood size
-   * @param minSimilarity  minimal similarity required for neighbors
-   * @param userSimilarity nearness metric
-   * @param dataModel      data model
-   * @param samplingRate   percentage of users to consider when building neighborhood -- decrease to trade quality for
-   *                       performance
-   * @throws IllegalArgumentException if n &lt; 1 or samplingRate is NaN or not in (0,1], or userSimilarity or dataModel
-   *                                  are <code>null</code>
+   * @param n
+   *          neighborhood size
+   * @param minSimilarity
+   *          minimal similarity required for neighbors
+   * @param userSimilarity
+   *          nearness metric
+   * @param dataModel
+   *          data model
+   * @param samplingRate
+   *          percentage of users to consider when building neighborhood -- decrease to trade quality for
+   *          performance
+   * @throws IllegalArgumentException
+   *           if n &lt; 1 or samplingRate is NaN or not in (0,1], or userSimilarity or dataModel are
+   *           <code>null</code>
    */
   public NearestNUserNeighborhood(int n,
                                   double minSimilarity,
@@ -81,44 +96,44 @@
     this.n = n;
     this.minSimilarity = minSimilarity;
   }
-
+  
   @Override
   public long[] getUserNeighborhood(long userID) throws TasteException {
-
+    
     DataModel dataModel = getDataModel();
     UserSimilarity userSimilarityImpl = getUserSimilarity();
-
+    
     TopItems.Estimator<Long> estimator = new Estimator(userSimilarityImpl, userID, minSimilarity);
-
-    LongPrimitiveIterator userIDs =
-            SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel.getUserIDs(), getSamplingRate());
-
+    
+    LongPrimitiveIterator userIDs = SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel.getUserIDs(),
+      getSamplingRate());
+    
     return TopItems.getTopUsers(n, userIDs, null, estimator);
   }
-
+  
   @Override
   public String toString() {
     return "NearestNUserNeighborhood";
   }
-
+  
   private static class Estimator implements TopItems.Estimator<Long> {
     private final UserSimilarity userSimilarityImpl;
     private final long theUserID;
     private final double minSim;
-
+    
     private Estimator(UserSimilarity userSimilarityImpl, long theUserID, double minSim) {
       this.userSimilarityImpl = userSimilarityImpl;
       this.theUserID = theUserID;
       this.minSim = minSim;
     }
-
+    
     @Override
     public double estimate(Long userID) throws TasteException {
       if (userID == theUserID) {
         return Double.NaN;
       }
       double sim = userSimilarityImpl.userSimilarity(theUserID, userID);
-      return (sim >= minSim) ? sim : Double.NaN;
+      return sim >= minSim ? sim : Double.NaN;
     }
   }
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/neighborhood/ThresholdUserNeighborhood.java Sat Feb 13 20:54:05 2010
@@ -25,35 +25,43 @@
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
 /**
- * <p>Computes a neigbhorhood consisting of all users whose similarity to the given user meets or
- * exceeds a certain threshold. Similarity is defined by the given {@link UserSimilarity}.</p>
+ * <p>
+ * Computes a neigbhorhood consisting of all users whose similarity to the given user meets or exceeds a
+ * certain threshold. Similarity is defined by the given {@link UserSimilarity}.
+ * </p>
  */
 public final class ThresholdUserNeighborhood extends AbstractUserNeighborhood {
-
+  
   private final double threshold;
-
+  
   /**
-   * @param threshold      similarity threshold
-   * @param userSimilarity similarity metric
-   * @param dataModel      data model
-   * @throws IllegalArgumentException if threshold is {@link Double#NaN}, or if samplingRate is not positive and less
-   *                                  than or equal to 1.0, or if userSimilarity or dataModel are <code>null</code>
+   * @param threshold
+   *          similarity threshold
+   * @param userSimilarity
+   *          similarity metric
+   * @param dataModel
+   *          data model
+   * @throws IllegalArgumentException
+   *           if threshold is {@link Double#NaN}, or if samplingRate is not positive and less than or equal
+   *           to 1.0, or if userSimilarity or dataModel are <code>null</code>
    */
-  public ThresholdUserNeighborhood(double threshold,
-                                   UserSimilarity userSimilarity,
-                                   DataModel dataModel) {
+  public ThresholdUserNeighborhood(double threshold, UserSimilarity userSimilarity, DataModel dataModel) {
     this(threshold, userSimilarity, dataModel, 1.0);
   }
-
+  
   /**
-   * @param threshold      similarity threshold
-   * @param userSimilarity similarity metric
-   * @param dataModel      data model
-   * @param samplingRate   percentage of users to consider when building neighborhood -- decrease to trade quality for
-   *                       performance
-   * @throws IllegalArgumentException if threshold or samplingRate is {@link Double#NaN}, or if samplingRate is not
-   *                                  positive and less than or equal to 1.0, or if userSimilarity or dataModel are
-   *                                  <code>null</code>
+   * @param threshold
+   *          similarity threshold
+   * @param userSimilarity
+   *          similarity metric
+   * @param dataModel
+   *          data model
+   * @param samplingRate
+   *          percentage of users to consider when building neighborhood -- decrease to trade quality for
+   *          performance
+   * @throws IllegalArgumentException
+   *           if threshold or samplingRate is {@link Double#NaN}, or if samplingRate is not positive and less
+   *           than or equal to 1.0, or if userSimilarity or dataModel are <code>null</code>
    */
   public ThresholdUserNeighborhood(double threshold,
                                    UserSimilarity userSimilarity,
@@ -65,32 +73,32 @@
     }
     this.threshold = threshold;
   }
-
+  
   @Override
   public long[] getUserNeighborhood(long userID) throws TasteException {
-
+    
     DataModel dataModel = getDataModel();
     FastIDSet neighborhood = new FastIDSet();
-    LongPrimitiveIterator usersIterable =
-        SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel.getUserIDs(), getSamplingRate());
+    LongPrimitiveIterator usersIterable = SamplingLongPrimitiveIterator.maybeWrapIterator(dataModel
+        .getUserIDs(), getSamplingRate());
     UserSimilarity userSimilarityImpl = getUserSimilarity();
-
+    
     while (usersIterable.hasNext()) {
       long otherUserID = usersIterable.next();
       if (userID != otherUserID) {
         double theSimilarity = userSimilarityImpl.userSimilarity(userID, otherUserID);
-        if (!Double.isNaN(theSimilarity) && theSimilarity >= threshold) {
+        if (!Double.isNaN(theSimilarity) && (theSimilarity >= threshold)) {
           neighborhood.add(otherUserID);
         }
       }
     }
-
+    
     return neighborhood.toArray();
   }
-
+  
   @Override
   public String toString() {
     return "ThresholdUserNeighborhood";
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/AbstractRecommender.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,8 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+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.impl.common.LongPrimitiveIterator;
@@ -27,68 +29,74 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.List;
-
 public abstract class AbstractRecommender implements Recommender {
-
+  
   private static final Logger log = LoggerFactory.getLogger(AbstractRecommender.class);
-
+  
   private final DataModel dataModel;
-
+  
   protected AbstractRecommender(DataModel dataModel) {
     if (dataModel == null) {
       throw new IllegalArgumentException("dataModel is null");
     }
     this.dataModel = dataModel;
   }
-
+  
   /**
-   * <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>
+   * <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) throws TasteException {
     return recommend(userID, howMany, null);
   }
-
+  
   /**
-   * <p>Default implementation which just calls {@link DataModel#setPreference(long, long, float)}.</p>
-   *
-   * @throws IllegalArgumentException if userID or itemID is <code>null</code>, or if value is {@link Double#NaN}
+   * <p>
+   * Default implementation which just calls {@link DataModel#setPreference(long, long, float)}.
+   * </p>
+   * 
+   * @throws IllegalArgumentException
+   *           if userID or itemID is <code>null</code>, or if value is {@link Double#NaN}
    */
   @Override
   public void setPreference(long userID, long itemID, float value) throws TasteException {
     if (Double.isNaN(value)) {
       throw new IllegalArgumentException("Invalid value: " + value);
     }
-    log.debug("Setting preference for user {}, item {}", userID, itemID);    
+    AbstractRecommender.log.debug("Setting preference for user {}, item {}", userID, itemID);
     dataModel.setPreference(userID, itemID, value);
   }
-
+  
   /**
-   * <p>Default implementation which just calls {@link DataModel#removePreference(long, long)} (Object,
-   * Object)}.</p>
-   *
-   * @throws IllegalArgumentException if userID or itemID is <code>null</code>
+   * <p>
+   * Default implementation which just calls {@link DataModel#removePreference(long, long)} (Object, Object)}.
+   * </p>
+   * 
+   * @throws IllegalArgumentException
+   *           if userID or itemID is <code>null</code>
    */
   @Override
   public void removePreference(long userID, long itemID) throws TasteException {
-    log.debug("Remove preference for user '{}', item '{}'", userID, itemID);
+    AbstractRecommender.log.debug("Remove preference for user '{}', item '{}'", userID, itemID);
     dataModel.removePreference(userID, itemID);
   }
-
+  
   @Override
   public DataModel getDataModel() {
     return dataModel;
   }
-
+  
   /**
-   * @param theUserID ID of user being evaluated
-   * @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
+   * @param theUserID
+   *          ID of user being evaluated
+   * @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 theUserID) throws TasteException {
     FastIDSet possibleItemsIDs = new FastIDSet();
@@ -105,5 +113,5 @@
     possibleItemsIDs.removeAll(itemIDs);
     return possibleItemsIDs;
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ByRescoreComparator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ByRescoreComparator.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ByRescoreComparator.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ByRescoreComparator.java Sat Feb 13 20:54:05 2010
@@ -17,24 +17,26 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
-import org.apache.mahout.cf.taste.recommender.IDRescorer;
-import org.apache.mahout.cf.taste.recommender.RecommendedItem;
-
 import java.io.Serializable;
 import java.util.Comparator;
 
+import org.apache.mahout.cf.taste.recommender.IDRescorer;
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+
 /**
- * <p>Defines ordering on {@link RecommendedItem} by the rescored value of the recommendations' estimated preference
- * value, from high to low.</p>
+ * <p>
+ * Defines ordering on {@link RecommendedItem} by the rescored value of the recommendations' estimated
+ * preference value, from high to low.
+ * </p>
  */
 final class ByRescoreComparator implements Comparator<RecommendedItem>, Serializable {
-
+  
   private final IDRescorer rescorer;
-
+  
   ByRescoreComparator(IDRescorer rescorer) {
     this.rescorer = rescorer;
   }
-
+  
   @Override
   public int compare(RecommendedItem o1, RecommendedItem o2) {
     double rescored1;
@@ -54,10 +56,10 @@
       return 0;
     }
   }
-
+  
   @Override
   public String toString() {
     return "ByRescoreComparator[rescorer:" + rescorer + ']';
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/CachingRecommender.java Sat Feb 13 20:54:05 2010
@@ -17,40 +17,43 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+import java.lang.ref.SoftReference;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.Cache;
-import org.apache.mahout.cf.taste.recommender.IDRescorer;
-import org.apache.mahout.common.LongPair;
 import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
 import org.apache.mahout.cf.taste.impl.common.Retriever;
 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.apache.mahout.common.LongPair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.lang.ref.SoftReference;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Callable;
-
 /**
- * <p>A {@link Recommender} which caches the results from another {@link Recommender} in memory. Results are held by
- * {@link SoftReference}s so that the JVM may reclaim memory from the recommendationCache in low-memory situations.</p>
+ * <p>
+ * A {@link Recommender} which caches the results from another {@link Recommender} in memory. Results are held
+ * by {@link SoftReference}s so that the JVM may reclaim memory from the recommendationCache in low-memory
+ * situations.
+ * </p>
  */
 public final class CachingRecommender implements Recommender {
-
+  
   private static final Logger log = LoggerFactory.getLogger(CachingRecommender.class);
-
+  
   private final Recommender recommender;
   private final int[] maxHowMany;
-  private final Cache<Long, Recommendations> recommendationCache;
-  private final Cache<LongPair, Float> estimatedPrefCache;
+  private final Cache<Long,Recommendations> recommendationCache;
+  private final Cache<LongPair,Float> estimatedPrefCache;
   private final RefreshHelper refreshHelper;
   private IDRescorer currentRescorer;
-
+  
   public CachingRecommender(Recommender recommender) throws TasteException {
     if (recommender == null) {
       throw new IllegalArgumentException("recommender is null");
@@ -59,10 +62,10 @@
     this.maxHowMany = new int[] {1};
     // Use "num users" as an upper limit on cache size. Rough guess.
     int numUsers = recommender.getDataModel().getNumUsers();
-    this.recommendationCache =
-        new Cache<Long, Recommendations>(new RecommendationRetriever(this.recommender), numUsers);
-    this.estimatedPrefCache =
-        new Cache<LongPair, Float>(new EstimatedPrefRetriever(this.recommender), numUsers);
+    this.recommendationCache = new Cache<Long,Recommendations>(new RecommendationRetriever(this.recommender),
+        numUsers);
+    this.estimatedPrefCache = new Cache<LongPair,Float>(new EstimatedPrefRetriever(this.recommender),
+        numUsers);
     this.refreshHelper = new RefreshHelper(new Callable<Object>() {
       @Override
       public Object call() {
@@ -72,11 +75,11 @@
     });
     this.refreshHelper.addDependency(recommender);
   }
-
+  
   private synchronized IDRescorer getCurrentRescorer() {
     return currentRescorer;
   }
-
+  
   private synchronized void setCurrentRescorer(IDRescorer rescorer) {
     if (rescorer == null) {
       if (currentRescorer != null) {
@@ -90,147 +93,151 @@
       }
     }
   }
-
+  
   @Override
   public List<RecommendedItem> recommend(long userID, int howMany) throws TasteException {
     return recommend(userID, howMany, null);
   }
-
+  
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer)
-      throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
     if (howMany < 1) {
       throw new IllegalArgumentException("howMany must be at least 1");
     }
-
+    
     synchronized (maxHowMany) {
       if (howMany > maxHowMany[0]) {
         maxHowMany[0] = howMany;
       }
     }
-
+    
     setCurrentRescorer(rescorer);
-
+    
     Recommendations recommendations = recommendationCache.get(userID);
-    if (recommendations.getItems().size() < howMany && !recommendations.isNoMoreRecommendableItems()) {
+    if ((recommendations.getItems().size() < howMany) && !recommendations.isNoMoreRecommendableItems()) {
       clear(userID);
       recommendations = recommendationCache.get(userID);
       if (recommendations.getItems().size() < howMany) {
         recommendations.setNoMoreRecommendableItems(true);
       }
     }
-
+    
     List<RecommendedItem> recommendedItems = recommendations.getItems();
-    return recommendedItems.size() > howMany ?
-        recommendedItems.subList(0, howMany) :
-        recommendedItems;
+    return recommendedItems.size() > howMany ? recommendedItems.subList(0, howMany) : recommendedItems;
   }
-
+  
   @Override
   public float estimatePreference(long userID, long itemID) throws TasteException {
     return estimatedPrefCache.get(new LongPair(userID, itemID));
   }
-
+  
   @Override
   public void setPreference(long userID, long itemID, float value) throws TasteException {
     recommender.setPreference(userID, itemID, value);
     clear(userID);
   }
-
+  
   @Override
   public void removePreference(long userID, long itemID) throws TasteException {
     recommender.removePreference(userID, itemID);
     clear(userID);
   }
-
+  
   @Override
   public DataModel getDataModel() {
     return recommender.getDataModel();
   }
-
+  
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     refreshHelper.refresh(alreadyRefreshed);
   }
-
+  
   /**
-   * <p>Clears cached recommendations for the given user.</p>
-   *
-   * @param userID clear cached data associated with this user ID
+   * <p>
+   * Clears cached recommendations for the given user.
+   * </p>
+   * 
+   * @param userID
+   *          clear cached data associated with this user ID
    */
   public void clear(long userID) {
-    log.debug("Clearing recommendations for user ID '{}'", userID);
+    CachingRecommender.log.debug("Clearing recommendations for user ID '{}'", userID);
     recommendationCache.remove(userID);
   }
-
-  /** <p>Clears all cached recommendations.</p> */
+  
+  /**
+   * <p>
+   * Clears all cached recommendations.
+   * </p>
+   */
   public void clear() {
-    log.debug("Clearing all recommendations...");
+    CachingRecommender.log.debug("Clearing all recommendations...");
     recommendationCache.clear();
   }
-
+  
   @Override
   public String toString() {
     return "CachingRecommender[recommender:" + recommender + ']';
   }
-
-  private final class RecommendationRetriever implements Retriever<Long, Recommendations> {
-
+  
+  private final class RecommendationRetriever implements Retriever<Long,Recommendations> {
+    
     private final Recommender recommender;
-
+    
     private RecommendationRetriever(Recommender recommender) {
       this.recommender = recommender;
     }
-
+    
     @Override
     public Recommendations get(Long key) throws TasteException {
-      log.debug("Retrieving new recommendations for user ID '{}'", key);
+      CachingRecommender.log.debug("Retrieving new recommendations for user ID '{}'", key);
       int howMany = maxHowMany[0];
       IDRescorer rescorer = getCurrentRescorer();
-      List<RecommendedItem> recommendations = rescorer == null ?
-          recommender.recommend(key, howMany) :
-          recommender.recommend(key, howMany, rescorer);
+      List<RecommendedItem> recommendations = rescorer == null ? recommender.recommend(key, howMany)
+          : recommender.recommend(key, howMany, rescorer);
       return new Recommendations(Collections.unmodifiableList(recommendations));
     }
   }
-
-  private static final class EstimatedPrefRetriever implements Retriever<LongPair, Float> {
-
+  
+  private static final class EstimatedPrefRetriever implements Retriever<LongPair,Float> {
+    
     private final Recommender recommender;
-
+    
     private EstimatedPrefRetriever(Recommender recommender) {
       this.recommender = recommender;
     }
-
+    
     @Override
     public Float get(LongPair key) throws TasteException {
       long userID = key.getFirst();
       long itemID = key.getSecond();
-      log.debug("Retrieving estimated preference for user ID '{}' and item ID '{}'", userID, itemID);
+      CachingRecommender.log.debug("Retrieving estimated preference for user ID '{}' and item ID '{}'",
+        userID, itemID);
       return recommender.estimatePreference(userID, itemID);
     }
   }
-
+  
   private static final class Recommendations {
-
+    
     private final List<RecommendedItem> items;
     private boolean noMoreRecommendableItems;
-
+    
     private Recommendations(List<RecommendedItem> items) {
       this.items = items;
     }
-
+    
     List<RecommendedItem> getItems() {
       return items;
     }
-
+    
     boolean isNoMoreRecommendableItems() {
       return noMoreRecommendableItems;
     }
-
+    
     void setNoMoreRecommendableItems(boolean noMoreRecommendableItems) {
       this.noMoreRecommendableItems = noMoreRecommendableItems;
     }
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ClusterSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ClusterSimilarity.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ClusterSimilarity.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ClusterSimilarity.java Sat Feb 13 20:54:05 2010
@@ -22,21 +22,27 @@
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
 
 /**
- * <p>Returns the "similarity" between two clusters of users, according to some definition of similarity. Subclassses
- * define different notions of similarity.</p>
- *
+ * <p>
+ * Returns the "similarity" between two clusters of users, according to some definition of similarity.
+ * Subclassses define different notions of similarity.
+ * </p>
+ * 
  * @see TreeClusteringRecommender
  */
 public interface ClusterSimilarity extends Refreshable {
-
+  
   /**
-   * @param cluster1 first cluster of user IDs
-   * @param cluster2 second cluster of user IDs
+   * @param cluster1
+   *          first cluster of user IDs
+   * @param cluster2
+   *          second cluster of user IDs
    * @return "distance" between clusters; a bigger value means less similarity
-   * @throws TasteException           if an error occurs while computing similarity, such as errors accessing an
-   *                                  underlying {@link org.apache.mahout.cf.taste.model.DataModel}
-   * @throws IllegalArgumentException if either argument is null or empty
+   * @throws TasteException
+   *           if an error occurs while computing similarity, such as errors accessing an underlying
+   *           {@link org.apache.mahout.cf.taste.model.DataModel}
+   * @throws IllegalArgumentException
+   *           if either argument is null or empty
    */
   double getSimilarity(FastIDSet cluster1, FastIDSet cluster2) throws TasteException;
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/FarthestNeighborClusterSimilarity.java Sat Feb 13 20:54:05 2010
@@ -17,6 +17,8 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+import java.util.Collection;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
@@ -25,50 +27,55 @@
 import org.apache.mahout.cf.taste.impl.common.SamplingLongPrimitiveIterator;
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
-import java.util.Collection;
-
 /**
- * <p>Defines cluster similarity as the <em>smallest</em> similarity between any two users in the clusters --
+ * <p>
+ * Defines cluster similarity as the <em>smallest</em> similarity between any two users in the clusters --
  * that is, it says that clusters are close when <em>all pairs</em> of their members have relatively high
- * similarity.</p>
+ * similarity.
+ * </p>
  */
 public final class FarthestNeighborClusterSimilarity implements ClusterSimilarity {
-
+  
   private final UserSimilarity similarity;
   private final double samplingRate;
-
+  
   /**
-   * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserSimilarity}. All user-user
-   * similarities are examined.</p>
+   * <p>
+   * Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserSimilarity}. All
+   * user-user similarities are examined.
+   * </p>
    */
   public FarthestNeighborClusterSimilarity(UserSimilarity similarity) {
     this(similarity, 1.0);
   }
-
+  
   /**
-   * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserSimilarity}. By setting
-   * <code>samplingRate</code> to a value less than 1.0, this implementation will only examine that fraction of all
-   * user-user similarities between two clusters, increasing performance at the expense of accuracy.</p>
+   * <p>
+   * Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserSimilarity}. By
+   * setting <code>samplingRate</code> to a value less than 1.0, this implementation will only examine that
+   * fraction of all user-user similarities between two clusters, increasing performance at the expense of
+   * accuracy.
+   * </p>
    */
   public FarthestNeighborClusterSimilarity(UserSimilarity similarity, double samplingRate) {
     if (similarity == null) {
       throw new IllegalArgumentException("similarity is null");
     }
-    if (Double.isNaN(samplingRate) || samplingRate <= 0.0 || samplingRate > 1.0) {
+    if (Double.isNaN(samplingRate) || (samplingRate <= 0.0) || (samplingRate > 1.0)) {
       throw new IllegalArgumentException("samplingRate is invalid: " + samplingRate);
     }
     this.similarity = similarity;
     this.samplingRate = samplingRate;
   }
-
+  
   @Override
   public double getSimilarity(FastIDSet cluster1, FastIDSet cluster2) throws TasteException {
     if (cluster1.isEmpty() || cluster2.isEmpty()) {
       return Double.NaN;
     }
     double leastSimilarity = Double.POSITIVE_INFINITY;
-    LongPrimitiveIterator someUsers =
-            SamplingLongPrimitiveIterator.maybeWrapIterator(cluster1.iterator(), samplingRate);
+    LongPrimitiveIterator someUsers = SamplingLongPrimitiveIterator.maybeWrapIterator(cluster1.iterator(),
+      samplingRate);
     while (someUsers.hasNext()) {
       long userID1 = someUsers.next();
       LongPrimitiveIterator it2 = cluster2.iterator();
@@ -85,16 +92,16 @@
     }
     return leastSimilarity;
   }
-
+  
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     alreadyRefreshed = RefreshHelper.buildRefreshed(alreadyRefreshed);
     RefreshHelper.maybeRefresh(alreadyRefreshed, similarity);
   }
-
+  
   @Override
   public String toString() {
     return "FarthestNeighborClusterSimilarity[similarity:" + similarity + ']';
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericBooleanPrefUserBasedRecommender.java Sat Feb 13 20:54:05 2010
@@ -24,26 +24,25 @@
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
 
 /**
- * A variant on {@link GenericUserBasedRecommender} which is appropriate for use when no notion of
- * preference value exists in the data.
+ * A variant on {@link GenericUserBasedRecommender} which is appropriate for use when no notion of preference
+ * value exists in the data.
  */
 public final class GenericBooleanPrefUserBasedRecommender extends GenericUserBasedRecommender {
-
+  
   public GenericBooleanPrefUserBasedRecommender(DataModel dataModel,
                                                 UserNeighborhood neighborhood,
                                                 UserSimilarity similarity) {
     super(dataModel, neighborhood, similarity);
   }
-
+  
   /**
-   * This computation is in a technical sense, wrong, since in the domain of "boolean preference users" where all
-   * preference values are 1, this method should only ever return 1.0 or NaN. This isn't terribly useful however since
-   * it means results can't be ranked by preference value (all are 1). So instead this returns a sum of similarities to
-   * any other user in the neighborhood who has also rated the item.
+   * This computation is in a technical sense, wrong, since in the domain of "boolean preference users" where
+   * all preference values are 1, this method should only ever return 1.0 or NaN. This isn't terribly useful
+   * however since it means results can't be ranked by preference value (all are 1). So instead this returns a
+   * sum of similarities to any other user in the neighborhood who has also rated the item.
    */
   @Override
-  protected float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID)
-      throws TasteException {
+  protected float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID) throws TasteException {
     if (theNeighborhood.length == 0) {
       return Float.NaN;
     }
@@ -53,17 +52,16 @@
     boolean foundAPref = false;
     for (long userID : theNeighborhood) {
       // See GenericItemBasedRecommender.doEstimatePreference() too
-      if (userID != theUserID && dataModel.getPreferenceValue(userID, itemID) != null) {
+      if ((userID != theUserID) && (dataModel.getPreferenceValue(userID, itemID) != null)) {
         foundAPref = true;
         totalSimilarity += similarity.userSimilarity(theUserID, userID);
       }
     }
     return foundAPref ? totalSimilarity : Float.NaN;
   }
-
+  
   @Override
-  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID)
-      throws TasteException {
+  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
     DataModel dataModel = getDataModel();
     FastIDSet possibleItemIDs = new FastIDSet();
     for (long userID : theNeighborhood) {
@@ -72,11 +70,10 @@
     possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
     return possibleItemIDs;
   }
-
-
+  
   @Override
   public String toString() {
     return "GenericBooleanPrefUserBasedRecommender";
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericItemBasedRecommender.java Sat Feb 13 20:54:05 2010
@@ -17,49 +17,57 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
 import org.apache.mahout.cf.taste.impl.common.FullRunningAverage;
-import org.apache.mahout.cf.taste.recommender.IDRescorer;
-import org.apache.mahout.common.LongPair;
 import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
 import org.apache.mahout.cf.taste.impl.common.RunningAverage;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.model.PreferenceArray;
+import org.apache.mahout.cf.taste.recommender.IDRescorer;
 import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.cf.taste.recommender.Rescorer;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.common.LongPair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
 /**
- * <p>A simple {@link org.apache.mahout.cf.taste.recommender.Recommender} which uses a given {@link
- * org.apache.mahout.cf.taste.model.DataModel} and {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} to
- * produce recommendations. This class represents Taste's support for item-based recommenders.</p>
- *
- * <p>The {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} is the most important point to discuss here.
- * Item-based recommenders are useful because they can take advantage of something to be very fast: they base their
- * computations on item similarity, not user similarity, and item similarity is relatively static. It can be
- * precomputed, instead of re-computed in real time.</p>
- *
- * <p>Thus it's strongly recommended that you use {@link org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity}
- * with pre-computed similarities if you're going to use this class. You can use {@link
- * org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity} too, which computes similarities in
- * real-time, but will probably find this painfully slow for large amounts of data.</p>
+ * <p>
+ * A simple {@link org.apache.mahout.cf.taste.recommender.Recommender} which uses a given
+ * {@link org.apache.mahout.cf.taste.model.DataModel} and
+ * {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} to produce recommendations. This class
+ * represents Taste's support for item-based recommenders.
+ * </p>
+ * 
+ * <p>
+ * The {@link org.apache.mahout.cf.taste.similarity.ItemSimilarity} is the most important point to discuss
+ * here. Item-based recommenders are useful because they can take advantage of something to be very fast: they
+ * base their computations on item similarity, not user similarity, and item similarity is relatively static.
+ * It can be precomputed, instead of re-computed in real time.
+ * </p>
+ * 
+ * <p>
+ * Thus it's strongly recommended that you use
+ * {@link org.apache.mahout.cf.taste.impl.similarity.GenericItemSimilarity} with pre-computed similarities if
+ * you're going to use this class. You can use
+ * {@link org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity} too, which computes
+ * similarities in real-time, but will probably find this painfully slow for large amounts of data.
+ * </p>
  */
 public class GenericItemBasedRecommender extends AbstractRecommender implements ItemBasedRecommender {
-
+  
   private static final Logger log = LoggerFactory.getLogger(GenericItemBasedRecommender.class);
-
+  
   private final ItemSimilarity similarity;
   private final RefreshHelper refreshHelper;
-
+  
   public GenericItemBasedRecommender(DataModel dataModel, ItemSimilarity similarity) {
     super(dataModel);
     if (similarity == null) {
@@ -70,34 +78,34 @@
     refreshHelper.addDependency(dataModel);
     refreshHelper.addDependency(similarity);
   }
-
+  
   public ItemSimilarity getSimilarity() {
     return similarity;
   }
-
+  
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer)
-      throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
     if (howMany < 1) {
       throw new IllegalArgumentException("howMany must be at least 1");
     }
-
-    log.debug("Recommending items for user ID '{}'", userID);
-
+    
+    GenericItemBasedRecommender.log.debug("Recommending items for user ID '{}'", userID);
+    
     if (getNumPreferences(userID) == 0) {
       return Collections.emptyList();
     }
-
+    
     FastIDSet possibleItemIDs = getAllOtherItems(userID);
-
+    
     TopItems.Estimator<Long> estimator = new Estimator(userID);
-
-    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer, estimator);
-
-    log.debug("Recommendations are: {}", topItems);
+    
+    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, possibleItemIDs.iterator(), rescorer,
+      estimator);
+    
+    GenericItemBasedRecommender.log.debug("Recommendations are: {}", topItems);
     return topItems;
   }
-
+  
   @Override
   public float estimatePreference(long userID, long itemID) throws TasteException {
     DataModel model = getDataModel();
@@ -107,55 +115,49 @@
     }
     return doEstimatePreference(userID, itemID);
   }
-
+  
   @Override
   public List<RecommendedItem> mostSimilarItems(long itemID, int howMany) throws TasteException {
     return mostSimilarItems(itemID, howMany, null);
   }
-
+  
   @Override
-  public List<RecommendedItem> mostSimilarItems(long itemID,
-                                                int howMany,
-                                                Rescorer<LongPair> rescorer) throws TasteException {
+  public List<RecommendedItem> mostSimilarItems(long itemID, int howMany, Rescorer<LongPair> rescorer) throws TasteException {
     TopItems.Estimator<Long> estimator = new MostSimilarEstimator(itemID, similarity, rescorer);
     return doMostSimilarItems(new long[] {itemID}, howMany, estimator);
   }
-
+  
   @Override
   public List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany) throws TasteException {
     return mostSimilarItems(itemIDs, howMany, null);
   }
-
+  
   @Override
-  public List<RecommendedItem> mostSimilarItems(long[] itemIDs,
-                                                int howMany,
-                                                Rescorer<LongPair> rescorer) throws TasteException {
+  public List<RecommendedItem> mostSimilarItems(long[] itemIDs, int howMany, Rescorer<LongPair> rescorer) throws TasteException {
     TopItems.Estimator<Long> estimator = new MultiMostSimilarEstimator(itemIDs, similarity, rescorer);
     return doMostSimilarItems(itemIDs, howMany, estimator);
   }
-
+  
   @Override
-  public List<RecommendedItem> recommendedBecause(long userID,
-                                                  long itemID,
-                                                  int howMany) throws TasteException {
+  public List<RecommendedItem> recommendedBecause(long userID, long itemID, int howMany) throws TasteException {
     if (howMany < 1) {
       throw new IllegalArgumentException("howMany must be at least 1");
     }
-
+    
     DataModel model = getDataModel();
     TopItems.Estimator<Long> estimator = new RecommendedBecauseEstimator(userID, itemID, similarity);
-
+    
     PreferenceArray prefs = model.getPreferencesFromUser(userID);
     int size = prefs.length();
-    FastIDSet allUserItems = new FastIDSet(size);    
+    FastIDSet allUserItems = new FastIDSet(size);
     for (int i = 0; i < size; i++) {
       allUserItems.add(prefs.getItemID(i));
     }
     allUserItems.remove(itemID);
-
+    
     return TopItems.getTopItems(howMany, allUserItems.iterator(), null, estimator);
   }
-
+  
   private List<RecommendedItem> doMostSimilarItems(long[] itemIDs,
                                                    int howMany,
                                                    TopItems.Estimator<Long> estimator) throws TasteException {
@@ -172,7 +174,7 @@
     possibleItemsIDs.removeAll(itemIDs);
     return TopItems.getTopItems(howMany, possibleItemsIDs.iterator(), null, estimator);
   }
-
+  
   protected float doEstimatePreference(long userID, long itemID) throws TasteException {
     double preference = 0.0;
     double totalSimilarity = 0.0;
@@ -198,80 +200,76 @@
     // seems like a bad situation.
     return count <= 1 ? Float.NaN : (float) (preference / totalSimilarity);
   }
-
+  
   private int getNumPreferences(long userID) throws TasteException {
     return getDataModel().getPreferencesFromUser(userID).length();
   }
-
+  
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     refreshHelper.refresh(alreadyRefreshed);
   }
-
+  
   @Override
   public String toString() {
     return "GenericItemBasedRecommender[similarity:" + similarity + ']';
   }
-
+  
   public static class MostSimilarEstimator implements TopItems.Estimator<Long> {
-
+    
     private final long toItemID;
     private final ItemSimilarity similarity;
     private final Rescorer<LongPair> rescorer;
-
-    public MostSimilarEstimator(long toItemID,
-                                ItemSimilarity similarity,
-                                Rescorer<LongPair> rescorer) {
+    
+    public MostSimilarEstimator(long toItemID, ItemSimilarity similarity, Rescorer<LongPair> rescorer) {
       this.toItemID = toItemID;
       this.similarity = similarity;
       this.rescorer = rescorer;
     }
-
+    
     @Override
     public double estimate(Long itemID) throws TasteException {
       LongPair pair = new LongPair(toItemID, itemID);
-      if (rescorer != null && rescorer.isFiltered(pair)) {
+      if ((rescorer != null) && rescorer.isFiltered(pair)) {
         return Double.NaN;
       }
       double originalEstimate = similarity.itemSimilarity(toItemID, itemID);
       return rescorer == null ? originalEstimate : rescorer.rescore(pair, originalEstimate);
     }
   }
-
+  
   private final class Estimator implements TopItems.Estimator<Long> {
-
+    
     private final long userID;
-
+    
     private Estimator(long userID) {
       this.userID = userID;
     }
-
+    
     @Override
     public double estimate(Long itemID) throws TasteException {
       return doEstimatePreference(userID, itemID);
     }
   }
-
+  
   private static class MultiMostSimilarEstimator implements TopItems.Estimator<Long> {
-
+    
     private final long[] toItemIDs;
     private final ItemSimilarity similarity;
     private final Rescorer<LongPair> rescorer;
-
-    private MultiMostSimilarEstimator(long[] toItemIDs,
-                                      ItemSimilarity similarity,
-                                      Rescorer<LongPair> rescorer) {
+    
+    private MultiMostSimilarEstimator(long[] toItemIDs, ItemSimilarity similarity, Rescorer<LongPair> rescorer) {
       this.toItemIDs = toItemIDs;
       this.similarity = similarity;
       this.rescorer = rescorer;
     }
-
+    
     @Override
     public double estimate(Long itemID) throws TasteException {
       RunningAverage average = new FullRunningAverage();
       for (long toItemID : toItemIDs) {
         LongPair pair = new LongPair(toItemID, itemID);
-        if (rescorer != null && rescorer.isFiltered(pair)) {
+        if ((rescorer != null) && rescorer.isFiltered(pair)) {
           continue;
         }
         double estimate = similarity.itemSimilarity(toItemID, itemID);
@@ -283,21 +281,19 @@
       return average.getAverage();
     }
   }
-
+  
   private class RecommendedBecauseEstimator implements TopItems.Estimator<Long> {
-
+    
     private final long userID;
     private final long recommendedItemID;
     private final ItemSimilarity similarity;
-
-    private RecommendedBecauseEstimator(long userID,
-                                        long recommendedItemID,
-                                        ItemSimilarity similarity) {
+    
+    private RecommendedBecauseEstimator(long userID, long recommendedItemID, ItemSimilarity similarity) {
       this.userID = userID;
       this.recommendedItemID = recommendedItemID;
       this.similarity = similarity;
     }
-
+    
     @Override
     public double estimate(Long itemID) throws TasteException {
       Float pref = getDataModel().getPreferenceValue(userID, itemID);
@@ -308,5 +304,5 @@
       return (1.0 + similarityValue) * pref;
     }
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericRecommendedItem.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericRecommendedItem.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericRecommendedItem.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericRecommendedItem.java Sat Feb 13 20:54:05 2010
@@ -17,18 +17,25 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
-import org.apache.mahout.common.RandomUtils;
-import org.apache.mahout.cf.taste.recommender.RecommendedItem;
-
 import java.io.Serializable;
 
-/** <p>A simple implementation of {@link RecommendedItem}.</p> */
-public final class GenericRecommendedItem implements RecommendedItem, Serializable {
+import org.apache.mahout.cf.taste.recommender.RecommendedItem;
+import org.apache.mahout.common.RandomUtils;
 
+/**
+ * <p>
+ * A simple implementation of {@link RecommendedItem}.
+ * </p>
+ */
+public final class GenericRecommendedItem implements RecommendedItem, Serializable {
+  
   private final long itemID;
   private final float value;
-
-  /** @throws IllegalArgumentException if item is null or value is NaN */
+  
+  /**
+   * @throws IllegalArgumentException
+   *           if item is null or value is NaN
+   */
   public GenericRecommendedItem(long itemID, float value) {
     if (Float.isNaN(value)) {
       throw new IllegalArgumentException("value is NaN");
@@ -36,39 +43,39 @@
     this.itemID = itemID;
     this.value = value;
   }
-
+  
   @Override
   public long getItemID() {
     return itemID;
   }
-
+  
   @Override
   public float getValue() {
     return value;
   }
-
+  
   @Override
   public String toString() {
     return "RecommendedItem[item:" + itemID + ", value:" + value + ']';
   }
-
+  
   @Override
   public int hashCode() {
     return (int) itemID ^ RandomUtils.hashFloat(value);
   }
-
+  
   @Override
   public boolean equals(Object o) {
     if (!(o instanceof GenericRecommendedItem)) {
       return false;
     }
     GenericRecommendedItem other = (GenericRecommendedItem) o;
-    return itemID == other.getItemID() && value == other.getValue();
+    return (itemID == other.getItemID()) && (value == other.getValue());
   }
-
+  
   /**
    * Defines a natural ordering from most-preferred item (highest value) to least-preferred.
-   *
+   * 
    * @return 1, -1, 0 as this value is less than, greater than or equal to the other's value
    */
   @Override
@@ -76,5 +83,5 @@
     float otherValue = other.getValue();
     return value > otherValue ? -1 : value < otherValue ? 1 : 0;
   }
-
+  
 }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java?rev=909912&r1=909911&r2=909912&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java (original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/GenericUserBasedRecommender.java Sat Feb 13 20:54:05 2010
@@ -17,38 +17,40 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.mahout.cf.taste.common.Refreshable;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FastIDSet;
-import org.apache.mahout.cf.taste.recommender.IDRescorer;
-import org.apache.mahout.common.LongPair;
 import org.apache.mahout.cf.taste.impl.common.RefreshHelper;
 import org.apache.mahout.cf.taste.model.DataModel;
 import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
+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.apache.mahout.cf.taste.recommender.Rescorer;
 import org.apache.mahout.cf.taste.recommender.UserBasedRecommender;
 import org.apache.mahout.cf.taste.similarity.UserSimilarity;
+import org.apache.mahout.common.LongPair;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
 /**
- * <p>A simple {@link Recommender} which uses a given {@link DataModel} and {@link UserNeighborhood} to produce
- * recommendations.</p>
+ * <p>
+ * A simple {@link Recommender} which uses a given {@link DataModel} and {@link UserNeighborhood} to produce
+ * recommendations.
+ * </p>
  */
 public class GenericUserBasedRecommender extends AbstractRecommender implements UserBasedRecommender {
-
+  
   private static final Logger log = LoggerFactory.getLogger(GenericUserBasedRecommender.class);
-
+  
   private final UserNeighborhood neighborhood;
   private final UserSimilarity similarity;
   private final RefreshHelper refreshHelper;
-
+  
   public GenericUserBasedRecommender(DataModel dataModel,
                                      UserNeighborhood neighborhood,
                                      UserSimilarity similarity) {
@@ -63,36 +65,36 @@
     refreshHelper.addDependency(similarity);
     refreshHelper.addDependency(neighborhood);
   }
-
+  
   public UserSimilarity getSimilarity() {
     return similarity;
   }
-
+  
   @Override
-  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer)
-      throws TasteException {
+  public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException {
     if (howMany < 1) {
       throw new IllegalArgumentException("howMany must be at least 1");
     }
-
-    log.debug("Recommending items for user ID '{}'", userID);
-
+    
+    GenericUserBasedRecommender.log.debug("Recommending items for user ID '{}'", userID);
+    
     long[] theNeighborhood = neighborhood.getUserNeighborhood(userID);
-
+    
     if (theNeighborhood.length == 0) {
       return Collections.emptyList();
     }
-
+    
     FastIDSet allItemIDs = getAllOtherItems(theNeighborhood, userID);
-
+    
     TopItems.Estimator<Long> estimator = new Estimator(userID, theNeighborhood);
-
-    List<RecommendedItem> topItems = TopItems.getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator);
-
-    log.debug("Recommendations are: {}", topItems);
+    
+    List<RecommendedItem> topItems = TopItems
+        .getTopItems(howMany, allItemIDs.iterator(), rescorer, estimator);
+    
+    GenericUserBasedRecommender.log.debug("Recommendations are: {}", topItems);
     return topItems;
   }
-
+  
   @Override
   public float estimatePreference(long userID, long itemID) throws TasteException {
     DataModel model = getDataModel();
@@ -103,26 +105,24 @@
     long[] theNeighborhood = neighborhood.getUserNeighborhood(userID);
     return doEstimatePreference(userID, theNeighborhood, itemID);
   }
-
+  
   @Override
   public long[] mostSimilarUserIDs(long userID, int howMany) throws TasteException {
     return mostSimilarUserIDs(userID, howMany, null);
   }
-
+  
   @Override
-  public long[] mostSimilarUserIDs(long userID, int howMany, Rescorer<LongPair> rescorer)
-          throws TasteException {
+  public long[] mostSimilarUserIDs(long userID, int howMany, Rescorer<LongPair> rescorer) throws TasteException {
     TopItems.Estimator<Long> estimator = new MostSimilarEstimator(userID, similarity, rescorer);
     return doMostSimilarUsers(howMany, estimator);
   }
-
+  
   private long[] doMostSimilarUsers(int howMany, TopItems.Estimator<Long> estimator) throws TasteException {
     DataModel model = getDataModel();
     return TopItems.getTopUsers(howMany, model.getUserIDs(), null, estimator);
   }
-
-  protected float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID)
-      throws TasteException {
+  
+  protected float doEstimatePreference(long theUserID, long[] theNeighborhood, long itemID) throws TasteException {
     if (theNeighborhood.length == 0) {
       return Float.NaN;
     }
@@ -145,9 +145,8 @@
     }
     return totalSimilarity == 0.0 ? Float.NaN : (float) (preference / totalSimilarity);
   }
-
-  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID)
-          throws TasteException {
+  
+  protected FastIDSet getAllOtherItems(long[] theNeighborhood, long theUserID) throws TasteException {
     DataModel dataModel = getDataModel();
     FastIDSet possibleItemIDs = new FastIDSet();
     for (long userID : theNeighborhood) {
@@ -156,31 +155,29 @@
     possibleItemIDs.removeAll(dataModel.getItemIDsFromUser(theUserID));
     return possibleItemIDs;
   }
-
+  
   @Override
   public void refresh(Collection<Refreshable> alreadyRefreshed) {
     refreshHelper.refresh(alreadyRefreshed);
   }
-
+  
   @Override
   public String toString() {
     return "GenericUserBasedRecommender[neighborhood:" + neighborhood + ']';
   }
-
+  
   private static class MostSimilarEstimator implements TopItems.Estimator<Long> {
-
+    
     private final long toUserID;
     private final UserSimilarity similarity;
     private final Rescorer<LongPair> rescorer;
-
-    private MostSimilarEstimator(long toUserID,
-                                 UserSimilarity similarity,
-                                 Rescorer<LongPair> rescorer) {
+    
+    private MostSimilarEstimator(long toUserID, UserSimilarity similarity, Rescorer<LongPair> rescorer) {
       this.toUserID = toUserID;
       this.similarity = similarity;
       this.rescorer = rescorer;
     }
-
+    
     @Override
     public double estimate(Long userID) throws TasteException {
       // Don't consider the user itself as a possible most similar user
@@ -199,17 +196,17 @@
       }
     }
   }
-
+  
   private final class Estimator implements TopItems.Estimator<Long> {
-
+    
     private final long theUserID;
     private final long[] theNeighborhood;
-
+    
     Estimator(long theUserID, long[] theNeighborhood) {
       this.theUserID = theUserID;
       this.theNeighborhood = theNeighborhood;
     }
-
+    
     @Override
     public double estimate(Long itemID) throws TasteException {
       return doEstimatePreference(theUserID, theNeighborhood, itemID);



Mime
View raw message