You are here

class ItemBasedRecommender in Recommender API 7.6

Hierarchy

Expanded class hierarchy of ItemBasedRecommender

1 string reference to 'ItemBasedRecommender'
recommender_process_record in ./recommender.module
This function process the command, and saves result back to $record. Will not save record.

File

classes/Recommender.php, line 216

View source
class ItemBasedRecommender extends CFRecommender {
  public function initialize($params) {

    // do a simple trick of inverse item/user fields.
    parent::initialize($params);
    $user_field = $this->structure['preference']['user field'];
    $item_field = $this->structure['preference']['item field'];
    $this->structure['preference']['user field'] = $item_field;
    $this->structure['preference']['item field'] = $user_field;
  }
  public function finalize() {

    // save item similarities
    db_query("DELETE FROM {$this->structure['item similarity']['name']}");
    $this
      ->saveMatrix($this->userMap, $this->userMap, $this->similarityMatrix, $this->structure['item similarity']['name'], $this->structure['item similarity']['item1 field'], $this->structure['item similarity']['item2 field'], $this->structure['item similarity']['score field'], $this->structure['item similarity']['timestamp field'], TRUE);

    // save predictions
    db_query("DELETE FROM {$this->structure['prediction']['name']}");
    $this
      ->saveMatrix($this->userMap, $this->itemMap, $this->predictionMatrix, $this->structure['prediction']['name'], $this->structure['prediction']['item field'], $this->structure['prediction']['user field'], $this->structure['prediction']['score field'], $this->structure['prediction']['timestamp field']);

    // note: this should be reverse.
    return array(
      'num_user' => $this->itemNum,
      'num_item' => $this->userNum,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CFRecommender::$isBooleanRecommender protected property
CFRecommender::$itemMap protected property
CFRecommender::$itemNum protected property
CFRecommender::$predictionMatrix protected property
CFRecommender::$preferenceMatrix protected property
CFRecommender::$similarityMatrix protected property
CFRecommender::$structure protected property
CFRecommender::$timestamp protected property
CFRecommender::$userMap protected property
CFRecommender::$userNum protected property
CFRecommender::$userVectors protected property
CFRecommender::computePrediction protected function
CFRecommender::computeSimilarity protected function
CFRecommender::execute public function Do all computation here. Overrides RecommenderInterface::execute
CFRecommender::loadPreference protected function Load matrix from the database into a matrix class in memory
CFRecommender::saveMatrix protected function
ItemBasedRecommender::finalize public function Save data to database, etc. Overrides CFRecommender::finalize
ItemBasedRecommender::initialize public function Initialize the recommender settings from $params. No complexity should be introduced here. Overrides CFRecommender::initialize 1