mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r888365 - in /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste: impl/model/AbstractIDMigrator.java impl/model/AbstractJDBCIDMigrator.java impl/model/MemoryIDMigrator.java model/IDMigrator.java
Date Tue, 08 Dec 2009 12:20:09 GMT
Author: srowen
Date: Tue Dec  8 12:20:09 2009
New Revision: 888365

URL: http://svn.apache.org/viewvc?rev=888365&view=rev
Log:
MAHOUT-213

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java?rev=888365&r1=888364&r2=888365&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractIDMigrator.java
Tue Dec  8 12:20:09 2009
@@ -39,6 +39,9 @@
     }
   }
 
+  /**
+   * @return most significant 8 bytes of the MD5 hash of the string, as a long
+   */
   protected final long hash(String value) {
     byte[] md5hash;
     synchronized (md5Digest) {
@@ -54,18 +57,14 @@
 
   @Override
   public long toLongID(String stringID) throws TasteException {
-    long longID = hash(stringID);
-    storeMapping(longID, stringID);
-    return longID;
+    return hash(stringID);
   }
 
   @Override
   public void initialize(Iterable<String> stringIDs) throws TasteException {
     for (String stringID : stringIDs) {
-      toLongID(stringID);
+      storeMapping(toLongID(stringID), stringID);
     }
   }
 
-  protected abstract void storeMapping(long longID, String stringID) throws TasteException;
-
 }
\ No newline at end of file

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java?rev=888365&r1=888364&r2=888365&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/AbstractJDBCIDMigrator.java
Tue Dec  8 12:20:09 2009
@@ -26,6 +26,12 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
+/**
+ * Implementation which stores the reverse long-to-String mapping
+ * in a database. Subclasses can override and configure the class to
+ * operate with particular databases by supplying appropriate SQL
+ * statements to the constructor.
+ */
 public abstract class AbstractJDBCIDMigrator extends AbstractIDMigrator {
 
   public static final String DEFAULT_MAPPING_TABLE = "taste_id_mapping";
@@ -36,6 +42,12 @@
   private final String getStringIDSQL;
   private final String storeMappingSQL;
 
+  /**
+   * @param getStringIDSQL SQL statement which selects one column, the String ID, from a
+   *  mapping table. The statement should take one long parameter.
+   * @param storeMappingSQL SQL statement which saves a mapping from long to String.
+   *  It should take two parameters, a long and a String.
+   */
   protected AbstractJDBCIDMigrator(DataSource dataSource,
                                    String getStringIDSQL,
                                    String storeMappingSQL) {
@@ -45,7 +57,7 @@
   }
 
   @Override
-  protected final void storeMapping(long longID, String stringID) throws TasteException {
+  public final void storeMapping(long longID, String stringID) throws TasteException {
     Connection conn = null;
     PreparedStatement stmt = null;
     try {

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java?rev=888365&r1=888364&r2=888365&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/model/MemoryIDMigrator.java
Tue Dec  8 12:20:09 2009
@@ -19,6 +19,10 @@
 
 import org.apache.mahout.cf.taste.impl.common.FastByIDMap;
 
+/**
+ * Implementation which stores the reverse long-to-String mapping
+ * in memory.
+ */
 public final class MemoryIDMigrator extends AbstractIDMigrator {
 
   private final FastByIDMap<String> longToString;
@@ -28,7 +32,7 @@
   }
 
   @Override
-  protected void storeMapping(long longID, String stringID) {
+  public void storeMapping(long longID, String stringID) {
     synchronized (longToString) {
       longToString.put(longID, stringID);
     }

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java?rev=888365&r1=888364&r2=888365&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/model/IDMigrator.java
Tue Dec  8 12:20:09 2009
@@ -56,6 +56,17 @@
   String toStringID(long longID) throws TasteException;
 
   /**
+   * Stores the reverse long-to-String mapping in some kind of backing store. Note that this
must
+   * be called directly (or indirectly through {@link #initialize(Iterable)}) for every String
that
+   * might be encountered in the application, or else the mapping will not be known.
+   *
+   * @param longID long ID
+   * @param stringID string ID that maps to/from that long ID
+   * @throws TasteException if an error occurs while saving the mapping
+   */
+  void storeMapping(long longID, String stringID) throws TasteException;
+
+  /**
    * Make the mapping aware of the given string IDs.
    *
    * @throws TasteException if an error occurs while storing the mappings



Mime
View raw message