You are here

recommender.install in Recommender API 6

Installation file for the Recommender API module.

File

recommender.install
View source
<?php

/**
 * @file
 * Installation file for the Recommender API module.
 */
function recommender_schema() {

  // This is the main table to save similarity data. See fields description for details
  $schema['recommender_similarity'] = array(
    'description' => t('This is the main table to save similarity data'),
    'fields' => array(
      'pair_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('Unique index for each similarity pair'),
      ),
      'app_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('This field distinguishes different applications.'),
      ),
      'mouse1_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('The first mouse_id'),
      ),
      'mouse2_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('The second mouse_id'),
      ),
      'similarity' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
        'description' => t('Similarity score. The bigger, the more similar'),
      ),
      'created' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '11',
        'description' => t('Created timestamp'),
      ),
    ),
    'primary key' => array(
      'pair_id',
    ),
    'indexes' => array(
      'index_key' => array(
        'app_id',
        'mouse1_id',
        'mouse2_id',
      ),
    ),
  );

  // This is the main table to save prediction data. See fields descriptions for details
  $schema['recommender_prediction'] = array(
    'description' => t('This is the main table to save similarity data'),
    'fields' => array(
      'link_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('Unique index for each prediction link'),
      ),
      'app_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('This field distinguishes different applications.'),
      ),
      'mouse_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('The mouse_id for which the prediction is generated'),
      ),
      'cheese_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
        'description' => t('The cheese_id for which the prediction is generated'),
      ),
      'prediction' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
        'description' => t('The prediction score'),
      ),
      'created' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '11',
        'description' => t('Created timestamp'),
      ),
    ),
    'primary key' => array(
      'link_id',
    ),
    'indexes' => array(
      'index_key' => array(
        'app_id',
        'mouse_id',
        'cheese_id',
      ),
    ),
  );

  // Application name-id mapping.
  $schema['recommender_app_map'] = array(
    'description' => t('Map between application name and id'),
    'fields' => array(
      'app_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'app_name' => array(
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'app_id',
    ),
    'unique keys' => array(
      'index_app_name' => array(
        'app_name',
      ),
    ),
  );

  // coupled with the recommender_updated_* functions.
  $schema['recommender_updated_queue'] = array(
    'description' => t('The updated node queue for incremental algorithms'),
    'fields' => array(
      'update_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'app_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'mouse_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'cheese_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'old' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'new' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'created' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '11',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'disp-width' => '3',
      ),
    ),
    'primary key' => array(
      'update_id',
    ),
    'indexes' => array(
      'index_key' => array(
        'app_id',
        'mouse_id',
        'cheese_id',
      ),
    ),
  );

  // Table used for the slope-one algorithm
  $schema['recommender_slopeone_dev'] = array(
    'description' => t('Table used for the slope-one algorithm'),
    'fields' => array(
      'app_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'cheese1_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'cheese2_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'count' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'dev' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
    ),
    'indexes' => array(
      'index_key' => array(
        'app_id',
        'cheese1_id',
        'cheese2_id',
      ),
    ),
  );

  // Helper table for internal use.
  $schema['recommender_helper_single_stat'] = array(
    'description' => t('Statistics for single entity'),
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'avg' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'stddev' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );

  // Helper table for internal use.
  $schema['recommender_helper_pair_stat'] = array(
    'description' => t('Statistics for pairs, like a pair of mice or a pair of cheese'),
    'fields' => array(
      'id1' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'id2' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'avg1' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'avg2' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'stddev1' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'stddev2' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'dev' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'count' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'disp-width' => '10',
      ),
    ),
    'primary key' => array(
      'id1',
      'id2',
    ),
  );

  // Helper table for internal use.
  $schema['recommender_helper_matrix'] = array(
    'description' => t('Temporary storage for mouse-cheese links.'),
    'fields' => array(
      'mouse_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'cheese_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'disp-width' => '10',
      ),
      'weight' => array(
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'mouse_id',
      'cheese_id',
    ),
  );
  return $schema;
}
function recommender_install() {
  drupal_install_schema('recommender');
}
function recommender_uninstall() {
  drupal_uninstall_schema('recommender');
}

Functions

Namesort descending Description
recommender_install
recommender_schema @file Installation file for the Recommender API module.
recommender_uninstall