CWIS Developer Documentation
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
Recommender Class Reference

Recommendation engine. More...

Inheritance diagram for Recommender:
Inheritance graph
[legend]

Public Member Functions

 __construct (&$DB, $ItemTableName, $RatingTableName, $ItemIdFieldName, $UserIdFieldName, $RatingFieldName, $ContentFields)
 Object constructor. More...
 
 DebugLevel ($Setting)
 Set level for debugging output. More...
 
 Recommend ($UserId, $StartingResult=0, $NumberOfResults=10)
 Recommend items for specified user. More...
 
 AddResultFilterFunction ($FunctionName)
 Add function to be called to filter returned recommendation list. More...
 
 NumberOfResults ()
 Get number of recommendations generated. More...
 
 SearchTime ()
 Get time it took to generate the most recent recommendation. More...
 
 GetSourceList ($UserId, $RecommendedItemId)
 Return list of items used to generate recommendation of specified item. More...
 
 FindSimilarItems ($ItemId, $FieldList=NULL)
 Dynamically generate and return list of items similar to specified item. More...
 
 RecommendFieldValues ($ItemId, $FieldList=NULL)
 Dynamically generate and return list of recommended field values for item. More...
 
 UpdateForItems ($StartingItemId, $NumberOfItems)
 Update recommender data for range of items. More...
 
 UpdateForItem ($ItemId, $FullPass=FALSE)
 Update recommender data for specified item. More...
 
 DropItem ($ItemId)
 Drop item from stored recommender data. More...
 
 PruneCorrelations ()
 Prune any stored correlation values that are below-average. More...
 
 GetItemIds ()
 Retrieve all item IDs. More...
 

Static Public Member Functions

static ClearCaches ()
 Clear internal caches of item and correlation data. More...
 

Public Attributes

const CONTENTFIELDTYPE_TEXT = 1
 
const CONTENTFIELDTYPE_NUMERIC = 2
 
const CONTENTFIELDTYPE_CONTROLLEDNAME = 3
 
const CONTENTFIELDTYPE_DATE = 4
 
const CONTENTFIELDTYPE_DATERAMGE = 5
 

Protected Member Functions

 LoadItemIds ()
 Load internal item ID cache (if not already loaded). More...
 
 GetFieldData ($ItemId, $FieldName)
 Get data for field. More...
 
 CalculateContentCorrelation ($ItemIdA, $ItemIdB, $FieldList=NULL)
 Calculate content correlation between two items and return value to caller. More...
 
 UpdateContentCorrelation ($ItemIdA, $ItemIdB)
 Calculate content correlation between two items and update in DB. More...
 
 NormalizeAndParseText ($Text)
 Normalize text string and parse into words. More...
 
 CalcTextCorrelation ($WordsA, $WordsB)
 Get value for correlation between two sets of words. More...
 
 ContentCorrelation ($ItemIdA, $ItemIdB, $NewCorrelation=-1)
 Get/set stored value for correlation between two items. More...
 
 FilterOnSuppliedFunctions ($Results)
 Run results through supplied filter functions. More...
 

Detailed Description

Recommendation engine.

Definition at line 13 of file Recommender.php.

Constructor & Destructor Documentation

Recommender::__construct ( $DB,
  $ItemTableName,
  $RatingTableName,
  $ItemIdFieldName,
  $UserIdFieldName,
  $RatingFieldName,
  $ContentFields 
)

Object constructor.

Parameters
object$DBDatabase to use.
string$ItemTableNameName of database table containing items.
string$RatingTableNameName of database table used to store item ratings.
string$ItemIdFieldNameName of column in ratings table that contains item IDs.
string$UserIdFieldNameName of column in ratings table that contains user IDs.
string$RatingFieldNameName of column in ratings table that contains rating value.
array$ContentFieldsArray of arrays with information about content fields, indexed by field identifiers, with the second-level arrays having "DBFieldName", "Weight", and "FieldType" elements.

Definition at line 41 of file Recommender.php.

References DebugLevel().

Member Function Documentation

Recommender::AddResultFilterFunction (   $FunctionName)

Add function to be called to filter returned recommendation list.

Parameters
callable$FunctionNameFilter function, that accepts an item ID and returns TRUE if item should be filtered out of results.

Definition at line 195 of file Recommender.php.

Recommender::CalcTextCorrelation (   $WordsA,
  $WordsB 
)
protected

Get value for correlation between two sets of words.

Parameters
array$WordsAFirst set of words.
array$WordsBSecond set of words.
Returns
int Value of correlation.

Definition at line 883 of file Recommender.php.

Referenced by CalculateContentCorrelation().

Here is the caller graph for this function:

Recommender::CalculateContentCorrelation (   $ItemIdA,
  $ItemIdB,
  $FieldList = NULL 
)
protected

Calculate content correlation between two items and return value to caller.

Parameters
int$ItemIdAID for first item.
int$ItemIdBID for second item.
array$FieldListList of fields to correlate. (OPTIONAL, defaults to all fields)
Returns
int Correlation value.

Definition at line 676 of file Recommender.php.

References CalcTextCorrelation(), DebugLevel(), and GetFieldData().

Referenced by FindSimilarItems(), and UpdateContentCorrelation().

Here is the caller graph for this function:

static Recommender::ClearCaches ( )
static

Clear internal caches of item and correlation data.

This is primarily intended for situations where memory may have run low.

Definition at line 595 of file Recommender.php.

Recommender::ContentCorrelation (   $ItemIdA,
  $ItemIdB,
  $NewCorrelation = -1 
)
protected

Get/set stored value for correlation between two items.

Parameters
int$ItemIdAID of first item.
int$ItemIdBID of second item.
int$NewCorrelationNew value for correlation. (OPTIONAL)
Returns
int Current correlation value.

Definition at line 899 of file Recommender.php.

Referenced by UpdateContentCorrelation().

Here is the caller graph for this function:

Recommender::DebugLevel (   $Setting)

Set level for debugging output.

Parameters
int$SettingNew debugging output level.

Definition at line 67 of file Recommender.php.

Referenced by __construct(), CalculateContentCorrelation(), FindSimilarItems(), Recommend(), RecommendFieldValues(), UpdateContentCorrelation(), UpdateForItem(), and UpdateForItems().

Here is the caller graph for this function:

Recommender::DropItem (   $ItemId)

Drop item from stored recommender data.

Parameters
int$ItemIdID of item to drop.

Definition at line 551 of file Recommender.php.

Recommender::FilterOnSuppliedFunctions (   $Results)
protected

Run results through supplied filter functions.

Parameters
array$ResultsResults to filter.
Returns
array Filtered results.

Definition at line 956 of file Recommender.php.

Referenced by FindSimilarItems().

Here is the caller graph for this function:

Recommender::FindSimilarItems (   $ItemId,
  $FieldList = NULL 
)

Dynamically generate and return list of items similar to specified item.

Parameters
int$ItemIdID of item.
array$FieldListList of fields to consider. (OPTIONAL, defaults to all fields)
Returns
array IDs for similar items.

Definition at line 271 of file Recommender.php.

References CalculateContentCorrelation(), DebugLevel(), FilterOnSuppliedFunctions(), and LoadItemIds().

Referenced by RecommendFieldValues().

Here is the caller graph for this function:

Recommender::GetFieldData (   $ItemId,
  $FieldName 
)
protected

Get data for field.

Parameters
int$ItemIdID of item to retrieve data for.
string$FieldNameName of field.
Returns
string Retrieved data.

Definition at line 644 of file Recommender.php.

References NormalizeAndParseText().

Referenced by CalculateContentCorrelation().

Here is the caller graph for this function:

Recommender::GetItemIds ( )

Retrieve all item IDs.

Returns
Array of item IDs.

Definition at line 580 of file Recommender.php.

Recommender::GetSourceList (   $UserId,
  $RecommendedItemId 
)

Return list of items used to generate recommendation of specified item.

Parameters
int$UserIdID of user that recommendation was generated for.
int$RecommendedItemIdID of item that was recommended.
Returns
array Array with IDs of items that were used to generate recommendation for the index, and correlation values (indicate how strongly the item determine the recommendation) for the values.

Definition at line 228 of file Recommender.php.

Recommender::LoadItemIds ( )
protected

Load internal item ID cache (if not already loaded).

Definition at line 626 of file Recommender.php.

Referenced by FindSimilarItems(), UpdateForItem(), and UpdateForItems().

Here is the caller graph for this function:

Recommender::NormalizeAndParseText (   $Text)
protected

Normalize text string and parse into words.

Parameters
string$TextText string.
Returns
array Resulting words.

Definition at line 785 of file Recommender.php.

Referenced by GetFieldData().

Here is the caller graph for this function:

Recommender::NumberOfResults ( )

Get number of recommendations generated.

Returns
int Number of recommended items.

Definition at line 205 of file Recommender.php.

Recommender::PruneCorrelations ( )

Prune any stored correlation values that are below-average.

Definition at line 562 of file Recommender.php.

Recommender::Recommend (   $UserId,
  $StartingResult = 0,
  $NumberOfResults = 10 
)

Recommend items for specified user.

Parameters
int$UserIdID of user.
int$StartingResultIndex into list of recommended items (first item is 0). (OPTIONAL, defaults to 0)
int$NumberOfResultsNumber of items to return. (OPTIONAL, defaults to 10)

Definition at line 83 of file Recommender.php.

References DebugLevel().

Recommender::RecommendFieldValues (   $ItemId,
  $FieldList = NULL 
)

Dynamically generate and return list of recommended field values for item.

Parameters
int$ItemIdID of item.
array$FieldListList of fields to recommend values for. (OPTIONAL, defaults to all fields)
Returns
array Array of arrays of recommended values, with fields for the top-level index.

Definition at line 339 of file Recommender.php.

References DebugLevel(), and FindSimilarItems().

Recommender::SearchTime ( )

Get time it took to generate the most recent recommendation.

Returns
float Time in seconds, with microseconds.

Definition at line 214 of file Recommender.php.

Recommender::UpdateContentCorrelation (   $ItemIdA,
  $ItemIdB 
)
protected

Calculate content correlation between two items and update in DB.

Parameters
int$ItemIdAID for first item.
int$ItemIdBID for second item.

Definition at line 765 of file Recommender.php.

References CalculateContentCorrelation(), ContentCorrelation(), and DebugLevel().

Referenced by UpdateForItem().

Here is the caller graph for this function:

Recommender::UpdateForItem (   $ItemId,
  $FullPass = FALSE 
)

Update recommender data for specified item.

Parameters
int$ItemIdID of item to update.
bool$FullPassIf TRUE, update is assumed to be part of an update of all items. (OPTIONAL, default to FALSE)

Definition at line 521 of file Recommender.php.

References DebugLevel(), LoadItemIds(), and UpdateContentCorrelation().

Referenced by UpdateForItems().

Here is the caller graph for this function:

Recommender::UpdateForItems (   $StartingItemId,
  $NumberOfItems 
)

Update recommender data for range of items.

Parameters
int$StartingItemIdID of first item to update.
int$NumberOfItemsNumber of items to update.
Returns
int ID of last item updated.

Definition at line 474 of file Recommender.php.

References DebugLevel(), LoadItemIds(), and UpdateForItem().

Member Data Documentation

const Recommender::CONTENTFIELDTYPE_CONTROLLEDNAME = 3

Definition at line 20 of file Recommender.php.

const Recommender::CONTENTFIELDTYPE_DATE = 4

Definition at line 21 of file Recommender.php.

Referenced by SPTRecommender\__construct().

const Recommender::CONTENTFIELDTYPE_DATERAMGE = 5

Definition at line 22 of file Recommender.php.

const Recommender::CONTENTFIELDTYPE_NUMERIC = 2

Definition at line 19 of file Recommender.php.

Referenced by SPTRecommender\__construct().

const Recommender::CONTENTFIELDTYPE_TEXT = 1

Definition at line 18 of file Recommender.php.

Referenced by SPTRecommender\__construct().


The documentation for this class was generated from the following file: