org.apache.mahout.cf.taste.impl.similarity.jdbc
Class AbstractJDBCItemSimilarity

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
      extended by org.apache.mahout.cf.taste.impl.similarity.jdbc.AbstractJDBCItemSimilarity
All Implemented Interfaces:
Refreshable, ItemSimilarity
Direct Known Subclasses:
MySQLJDBCItemSimilarity

public abstract class AbstractJDBCItemSimilarity
extends AbstractJDBCComponent
implements ItemSimilarity

An ItemSimilarity which draws pre-computed item-item similarities from a database table via JDBC.


Field Summary
 
Fields inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
DEFAULT_DATASOURCE_NAME
 
Constructor Summary
protected AbstractJDBCItemSimilarity(DataSource dataSource, String getItemItemSimilaritySQL, String getAllSimilarItemIDsSQL)
           
protected AbstractJDBCItemSimilarity(DataSource dataSource, String similarityTable, String itemAIDColumn, String itemBIDColumn, String similarityColumn, String getItemItemSimilaritySQL, String getAllSimilarItemIDsSQL)
           
 
Method Summary
 long[] allSimilarItemIDs(long itemID)
           
protected  String getItemAIDColumn()
           
protected  String getItemBIDColumn()
           
protected  String getSimilarityColumn()
           
protected  String getSimilarityTable()
           
 double[] itemSimilarities(long itemID1, long[] itemID2s)
          A bulk-get version of ItemSimilarity.itemSimilarity(long, long).
 double itemSimilarity(long itemID1, long itemID2)
           Returns the degree of similarity, of two items, based on the preferences that users have expressed for the items.
 void refresh(Collection<Refreshable> alreadyRefreshed)
           Triggers "refresh" -- whatever that means -- of the implementation.
 
Methods inherited from class org.apache.mahout.cf.taste.impl.common.jdbc.AbstractJDBCComponent
checkNotNullAndLog, checkNotNullAndLog, getFetchSize, lookupDataSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractJDBCItemSimilarity

protected AbstractJDBCItemSimilarity(DataSource dataSource,
                                     String getItemItemSimilaritySQL,
                                     String getAllSimilarItemIDsSQL)

AbstractJDBCItemSimilarity

protected AbstractJDBCItemSimilarity(DataSource dataSource,
                                     String similarityTable,
                                     String itemAIDColumn,
                                     String itemBIDColumn,
                                     String similarityColumn,
                                     String getItemItemSimilaritySQL,
                                     String getAllSimilarItemIDsSQL)
Method Detail

getSimilarityTable

protected String getSimilarityTable()

getItemAIDColumn

protected String getItemAIDColumn()

getItemBIDColumn

protected String getItemBIDColumn()

getSimilarityColumn

protected String getSimilarityColumn()

itemSimilarity

public double itemSimilarity(long itemID1,
                             long itemID2)
                      throws TasteException
Description copied from interface: ItemSimilarity

Returns the degree of similarity, of two items, based on the preferences that users have expressed for the items.

Specified by:
itemSimilarity in interface ItemSimilarity
Parameters:
itemID1 - first item ID
itemID2 - second item ID
Returns:
similarity between the items, in [-1,1] or Double.NaN similarity is unknown
Throws:
NoSuchItemException - if either item is known to be non-existent in the data
TasteException - if an error occurs while accessing the data

itemSimilarities

public double[] itemSimilarities(long itemID1,
                                 long[] itemID2s)
                          throws TasteException
Description copied from interface: ItemSimilarity

A bulk-get version of ItemSimilarity.itemSimilarity(long, long).

Specified by:
itemSimilarities in interface ItemSimilarity
Parameters:
itemID1 - first item ID
itemID2s - second item IDs to compute similarity with
Returns:
similarity between itemID1 and other items
Throws:
NoSuchItemException - if any item is known to be non-existent in the data
TasteException - if an error occurs while accessing the data

allSimilarItemIDs

public long[] allSimilarItemIDs(long itemID)
                         throws TasteException
Specified by:
allSimilarItemIDs in interface ItemSimilarity
Returns:
all IDs of similar items, in no particular order
Throws:
TasteException

refresh

public void refresh(Collection<Refreshable> alreadyRefreshed)
Description copied from interface: Refreshable

Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

Specified by:
refresh in interface Refreshable
Parameters:
alreadyRefreshed - s that are known to have already been refreshed as a result of an initial call to a method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.


Copyright © 2008-2011 The Apache Software Foundation. All Rights Reserved.