CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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:
[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 | $DB | Database to use.
  string | $ItemTableName | Name of database table containing items.
  string | $RatingTableName | Name of database table used to store item ratings.
  string | $ItemIdFieldName | Name of column in ratings table that contains item IDs.
  string | $UserIdFieldName | Name of column in ratings table that contains user IDs.
  string | $RatingFieldName | Name of column in ratings table that contains rating value.
  array | $ContentFields | Array 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 | $FunctionName | Filter 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 | $WordsA | First set of words.
  array | $WordsB | Second 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 | $ItemIdA | ID for first item.
  int | $ItemIdB | ID for second item.
  array | $FieldList | List 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 | $ItemIdA | ID of first item.
  int | $ItemIdB | ID of second item.
  int | $NewCorrelation | New 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 | $Setting | New 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 | $ItemId | ID of item to drop.

Definition at line 551 of file Recommender.php.

Recommender::FilterOnSuppliedFunctions | ( |  | $Results | ) |
| protected

Run results through supplied filter functions.

Parameters

  array | $Results | Results 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 | $ItemId | ID of item.
  array | $FieldList | List 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 | $ItemId | ID of item to retrieve data for.
  string | $FieldName | Name 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 | $UserId | ID of user that recommendation was generated for.
  int | $RecommendedItemId | ID 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 | $Text | Text 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 | $UserId | ID of user.
  int | $StartingResult | Index into list of recommended items (first item is 0). (OPTIONAL, defaults to 0)
  int | $NumberOfResults | Number 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 | $ItemId | ID of item.
  array | $FieldList | List 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 | $ItemIdA | ID for first item.
  int | $ItemIdB | ID 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 | $ItemId | ID of item to update.
  bool | $FullPass | If 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 | $StartingItemId | ID of first item to update.
  int | $NumberOfItems | Number 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:

- objects/Recommender.php