You are here

class CooccurrenceRecommender in Recommender API 6.2

The simple co-occurrence algorithm

Hierarchy

Expanded class hierarchy of CooccurrenceRecommender

File

./Recommender.php, line 651

View source
class CooccurrenceRecommender extends Recommender {

  // allow $fieldWeight to be NULL
  function __construct($appName, $tableName, $fieldMouse, $fieldCheese, $fieldWeight = NULL, $options = array()) {
    parent::__construct($appName, $tableName, $fieldMouse, $fieldCheese, $fieldWeight, $options);
  }
  function computeSimilarity() {
    $this
      ->prepareData('database');
    $this
      ->computeSimilarityDatabase();
  }

  // Note: removed the $incremental==update mode [#480300]
  // To see the removed code, go to branch DRUPAL-6--1-1
  protected function computeSimilarityDatabase() {
    watchdog("recommender", "Computing similarity in database. Might take a long time. Please be patient.");
    if ($this->fieldWeight === NULL) {
      $count = "COUNT(*)";

      // if no $fieldWeight is specified, just count the occurrences.
    }
    else {

      // otherwise, use the weight.
      $count = "SUM((n1.{$this->fieldWeight}+n2.{$this->fieldWeight})/2)";
    }
    $sql = "INSERT INTO {recommender_similarity}(app_id, mouse1_id, mouse2_id, similarity, created)\n                SELECT {$this->appId}, n1.{$this->fieldMouse}, n2.{$this->fieldMouse}, {$count}, {$this->created}\n                FROM {{$this->tableName}} n1 INNER JOIN {{$this->tableName}} n2 ON n1.{$this->fieldCheese}=n2.{$this->fieldCheese}\n                GROUP BY n1.{$this->fieldMouse}, n2.{$this->fieldMouse}";
    update_sql($sql);
    $this
      ->purgeOutdatedRecords('similarity');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CooccurrenceRecommender::computeSimilarity function Overrides Recommender::computeSimilarity
CooccurrenceRecommender::computeSimilarityDatabase protected function Overrides Recommender::computeSimilarityDatabase
CooccurrenceRecommender::__construct function Overrides Recommender::__construct
Recommender::$appId protected property
Recommender::$appName protected property
Recommender::$cheeseMap protected property
Recommender::$cheeseNum protected property
Recommender::$created protected property
Recommender::$directMatrix protected property
Recommender::$duplicate protected property
Recommender::$fieldCheese protected property
Recommender::$fieldMouse protected property
Recommender::$fieldWeight protected property
Recommender::$missing protected property
Recommender::$mouseMap protected property
Recommender::$mouseNum protected property
Recommender::$options protected property
Recommender::$performance protected property
Recommender::$predictionMatrix protected property
Recommender::$similarityMatrix protected property
Recommender::$tableName protected property
Recommender::batchInsert protected function
Recommender::cleanupMemory protected function
Recommender::computePrediction public function 2
Recommender::computePredictionDatabase protected function 1
Recommender::computePredictionJava protected function
Recommender::computePredictionMemory protected function 1
Recommender::computeSimilarityJava protected function
Recommender::computeSimilarityMemory protected function 1
Recommender::convertAppId static function
Recommender::getAppId public function
Recommender::getCheeseNum protected function
Recommender::getEntityNum protected function
Recommender::getMouseNum protected function
Recommender::initialize protected function 2
Recommender::loadDirectMatrix protected function Load matrix from the database into a matrix class in memory
Recommender::loadSimilarityMatrix protected function
Recommender::prepareData protected function After calling this function, data would be ready to process. Could be: 1) if it's in database, then $->tableName, $this->$field* would store the correct info. 2) if it's in memory, then $this->directMatrix will be the matrix
Recommender::processTable protected function
Recommender::purgeApp static function
Recommender::purgeOutdatedRecords protected function
Recommender::retrievePrediction public function
Recommender::retrieveSimilarity public function Return the similarity between $mouse1 and $mouse2.
Recommender::saveSimilarityMatrix protected function
Recommender::topPrediction public function
Recommender::topSimilarity public function