mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r722986 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl: model/jdbc/AbstractJDBCDataModel.java model/jdbc/MySQLJDBCDataModel.java recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java
Date Wed, 03 Dec 2008 18:00:51 GMT
Author: srowen
Date: Wed Dec  3 10:00:50 2008
New Revision: 722986

URL: http://svn.apache.org/viewvc?rev=722986&view=rev
Log:
Address MAHOUT-100: record and save table and column names, not just SQL statement, in JDBCDataModel
implementations, and reuse them when configuring JDBCDiffStorage implementations.

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java?rev=722986&r1=722985&r2=722986&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/AbstractJDBCDataModel.java
Wed Dec  3 10:00:50 2008
@@ -78,6 +78,10 @@
   public static final String DEFAULT_PREFERENCE_COLUMN = "preference";
 
   private final DataSource dataSource;
+  private final String preferenceTable;
+  private final String userIDColumn;
+  private final String itemIDColumn;
+  private final String preferenceColumn;
   private final String getUserSQL;
   private final String getNumItemsSQL;
   private final String getNumUsersSQL;
@@ -102,8 +106,48 @@
                                   String getPrefsForItemSQL,
                                   String getNumPreferenceForItemSQL,
                                   String getNumPreferenceForItemsSQL) {
+    this(dataSource,
+         DEFAULT_PREFERENCE_TABLE,
+         DEFAULT_USER_ID_COLUMN,
+         DEFAULT_ITEM_ID_COLUMN,
+         DEFAULT_PREFERENCE_COLUMN,
+         getUserSQL,
+         getNumItemsSQL,
+         getNumUsersSQL,
+         setPreferenceSQL,
+         removePreferenceSQL,
+         getUsersSQL,
+         getItemsSQL,
+         getItemSQL,
+         getPrefsForItemSQL,
+         getNumPreferenceForItemSQL,
+         getNumPreferenceForItemsSQL);
+  }
+
+  protected AbstractJDBCDataModel(DataSource dataSource,
+                                  String preferenceTable,
+                                  String userIDColumn,
+                                  String itemIDColumn,
+                                  String preferenceColumn,
+                                  String getUserSQL,
+                                  String getNumItemsSQL,
+                                  String getNumUsersSQL,
+                                  String setPreferenceSQL,
+                                  String removePreferenceSQL,
+                                  String getUsersSQL,
+                                  String getItemsSQL,
+                                  String getItemSQL,
+                                  String getPrefsForItemSQL,
+                                  String getNumPreferenceForItemSQL,
+                                  String getNumPreferenceForItemsSQL) {
 
     log.debug("Creating AbstractJDBCModel...");
+
+    checkNotNullAndLog("preferenceTable", preferenceTable);
+    checkNotNullAndLog("userIDColumn", userIDColumn);
+    checkNotNullAndLog("itemIDColumn", itemIDColumn);
+    checkNotNullAndLog("preferenceColumn", preferenceColumn);
+
     checkNotNullAndLog("dataSource", dataSource);
     checkNotNullAndLog("getUserSQL", getUserSQL);
     checkNotNullAndLog("getNumItemsSQL", getNumItemsSQL);
@@ -122,6 +166,11 @@
                "to the database itself, or database performance will be severely reduced.");
     }
 
+    this.preferenceTable = preferenceTable;
+    this.userIDColumn = userIDColumn;
+    this.itemIDColumn = itemIDColumn;
+    this.preferenceColumn = preferenceColumn;
+
     this.dataSource = dataSource;
     this.getUserSQL = getUserSQL;
     this.getNumItemsSQL = getNumItemsSQL;
@@ -176,6 +225,22 @@
     return dataSource;
   }
 
+  public String getPreferenceTable() {
+    return preferenceTable;
+  }
+
+  public String getUserIDColumn() {
+    return userIDColumn;
+  }
+
+  public String getItemIDColumn() {
+    return itemIDColumn;
+  }
+
+  public String getPreferenceColumn() {
+    return preferenceColumn;
+  }
+
   public final Iterable<? extends User> getUsers() throws TasteException {
     log.debug("Retrieving all users...");
     return new IteratorIterable<User>(new ResultSetUserIterator(dataSource, getUsersSQL));

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=722986&r1=722985&r2=722986&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
Wed Dec  3 10:00:50 2008
@@ -133,6 +133,10 @@
                             String itemIDColumn,
                             String preferenceColumn) {
     super(dataSource,
+          preferenceTable,
+          userIDColumn,
+          itemIDColumn,
+          preferenceColumn,
           // getUserSQL
           "SELECT " + itemIDColumn + ", " + preferenceColumn + " FROM " + preferenceTable
+
           " WHERE " + userIDColumn + "=? ORDER BY " + itemIDColumn,

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java?rev=722986&r1=722985&r2=722986&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/slopeone/jdbc/MySQLJDBCDiffStorage.java
Wed Dec  3 10:00:50 2008
@@ -18,7 +18,6 @@
 package org.apache.mahout.cf.taste.impl.recommender.slopeone.jdbc;
 
 import org.apache.mahout.cf.taste.common.TasteException;
-import org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel;
 import org.apache.mahout.cf.taste.impl.model.jdbc.MySQLJDBCDataModel;
 
 /**
@@ -58,10 +57,6 @@
 
   public MySQLJDBCDiffStorage(MySQLJDBCDataModel dataModel) throws TasteException {
     this(dataModel,
-         AbstractJDBCDataModel.DEFAULT_PREFERENCE_TABLE,
-         AbstractJDBCDataModel.DEFAULT_USER_ID_COLUMN,
-         AbstractJDBCDataModel.DEFAULT_ITEM_ID_COLUMN,
-         AbstractJDBCDataModel.DEFAULT_PREFERENCE_COLUMN,
          DEFAULT_DIFF_TABLE,
          DEFAULT_ITEM_A_COLUMN,
          DEFAULT_ITEM_B_COLUMN,
@@ -71,10 +66,6 @@
   }
 
   public MySQLJDBCDiffStorage(MySQLJDBCDataModel dataModel,
-                              String preferenceTable,
-                              String userIDColumn,
-                              String itemIDColumn,
-                              String preferenceColumn,
                               String diffsTable,
                               String itemIDAColumn,
                               String itemIDBColumn,
@@ -89,11 +80,11 @@
           " WHERE " + itemIDAColumn + "=? AND " + itemIDBColumn + "=?",
           // getDiffsSQL
           "SELECT " + countColumn + ", " + avgColumn + ", " + itemIDAColumn + " FROM " +
diffsTable + ", " +
-          preferenceTable + " WHERE " + itemIDBColumn + "=? AND " + itemIDAColumn + " = "
+ itemIDColumn +
-          " AND " + userIDColumn + "=? ORDER BY " + itemIDAColumn,
+          dataModel.getPreferenceTable() + " WHERE " + itemIDBColumn + "=? AND " + itemIDAColumn
+ " = " + dataModel.getItemIDColumn() +
+          " AND " + dataModel.getUserIDColumn() + "=? ORDER BY " + itemIDAColumn,
           // getAverageItemPrefSQL
-          "SELECT COUNT(1), AVG(" + preferenceColumn + ") FROM " + preferenceTable +
-          " WHERE " + itemIDColumn + "=?",
+          "SELECT COUNT(1), AVG(" + dataModel.getPreferenceColumn() + ") FROM " + dataModel.getPreferenceTable()
+
+          " WHERE " + dataModel.getItemIDColumn() + "=?",
           // updateDiffSQLs
           new String[]{
                   "UPDATE " + diffsTable + " SET " + avgColumn + " = " + avgColumn + " -
(? / " + countColumn +
@@ -112,22 +103,22 @@
           },
           // getRecommendableItemsSQL
           "SELECT id FROM " +
-          "(SELECT " + itemIDAColumn + " AS id FROM " + diffsTable + ", " + preferenceTable
+
-          " WHERE " + itemIDBColumn + " = item_id AND " + userIDColumn + "=? UNION DISTINCT"
+
-          " SELECT " + itemIDBColumn + " AS id FROM " + diffsTable + ", " + preferenceTable
+
-          " WHERE " + itemIDAColumn + " = item_id AND " + userIDColumn +
-          "=?) possible_item_ids WHERE id NOT IN (SELECT " + itemIDColumn + " FROM " + preferenceTable
+
-          " WHERE " + userIDColumn + "=?)",
+          "(SELECT " + itemIDAColumn + " AS id FROM " + diffsTable + ", " + dataModel.getPreferenceTable()
+
+          " WHERE " + itemIDBColumn + " = item_id AND " + dataModel.getUserIDColumn() + "=?
UNION DISTINCT" +
+          " SELECT " + itemIDBColumn + " AS id FROM " + diffsTable + ", " + dataModel.getPreferenceTable()
+
+          " WHERE " + itemIDAColumn + " = item_id AND " + dataModel.getUserIDColumn() +
+          "=?) possible_item_ids WHERE id NOT IN (SELECT " + dataModel.getItemIDColumn()
+ " FROM " + dataModel.getPreferenceTable() +
+          " WHERE " + dataModel.getUserIDColumn() + "=?)",
           // deleteDiffsSQL
           "DELETE FROM " + diffsTable,
           // createDiffsSQL
           "INSERT INTO " + diffsTable + " (" + itemIDAColumn + ", " + itemIDBColumn + ",
" + avgColumn +
-          ", " + countColumn + ") SELECT prefsA." + itemIDColumn + ", prefsB." + itemIDColumn
+ ',' +
-          " AVG(prefsB." + preferenceColumn + " - prefsA." + preferenceColumn + ")," +
-          " COUNT(1) AS count FROM " + preferenceTable + " prefsA, " + preferenceTable +
" prefsB WHERE prefsA." +
-          userIDColumn + " = prefsB." + userIDColumn + " AND prefsA." + itemIDColumn + "
< prefsB." +
-          itemIDColumn + ' ' + " GROUP BY prefsA." + itemIDColumn +
-          ", prefsB." + itemIDColumn + " HAVING count >=?",
+          ", " + countColumn + ") SELECT prefsA." + dataModel.getItemIDColumn() + ", prefsB."
+ dataModel.getItemIDColumn() + ',' +
+          " AVG(prefsB." + dataModel.getPreferenceColumn() + " - prefsA." + dataModel.getPreferenceColumn()
+ ")," +
+          " COUNT(1) AS count FROM " + dataModel.getPreferenceTable() + " prefsA, " + dataModel.getPreferenceTable()
+ " prefsB WHERE prefsA." +
+          dataModel.getUserIDColumn() + " = prefsB." + dataModel.getUserIDColumn() + " AND
prefsA." + dataModel.getItemIDColumn() + " < prefsB." +
+          dataModel.getItemIDColumn() + ' ' + " GROUP BY prefsA." + dataModel.getItemIDColumn()
+
+          ", prefsB." + dataModel.getItemIDColumn() + " HAVING count >=?",
           // diffsExistSQL
           "SELECT COUNT(1) FROM " + diffsTable,
           minDiffCount);



Mime
View raw message