yii-word-frequency A class for accumulating tokens from various text sources, filtering them, and counting their frequency.

  1. Potential Usage
  2. Requirements
  3. Installation
  4. Usage
  5. Motivation
  6. Resources

Potential Usage

  • Generating Tag Clouds
  • Determining the top keywords in a set of texts (e.g. Most often mentioned keywords in a set of posts or comments)
  • Determining the frequency of a specified set of tokens (e.g. A sports blog displays which players from a specific team appear in a post)


Yii 1.1.14 (developed with this version. I see no problems using earlier versions but it has not been tested with any version prior to 1.1.14)


Place the contents of the 'yii-word-frequency' extension (extracted from the zip file or obtained via Github) into the extensions folder extensions/yii-word-frequency

Add ext.yii-word-frequency to the import array in config/main.php ~~~ // preloading 'log' component 'preload'=>array('log'),

// autoloading model and component classes 'import'=>array(


), ~~~


A minimalistic example
$ywf = Yii::createComponent(array('class' => 'YiiWordFrequency'));
$ywf->sourceList = 'This is a test string. This is another test string. Test strings are fun.';
$frequencyList = $ywf->generateList();
An example using Active Records

(the frequency list can be obtained from the return value of generateList() as above or via the property ~~~ $ywf = Yii::createComponent(array('class' => 'YiiWordFrequency')); $model = new Testdata; $criteria=new CDbCriteria(); $criteria->addInCondition('id',array(1,2)); $criteria->select = "col1, col2, col3"; $ywf->sourceList = array(array($model, $criteria)); $ywf->accumulateSources(); $ywf->generateList(); $frequencyList = $ywf->tagFrequencyList; ~~~

An example usinge multiple sources
$ywf = Yii::createComponent(array('class' => 'YiiWordFrequency'));
$model = new Testdata; // Active Record Model
$criteria=new CDbCriteria(); // Criteria object for determining columns and record sources
$criteria->select = "col1";
$this->ywf->sourceList = array(
	array($model, $criteria),
$frequencyList = $ywf->tagFrequencyList;
An example using a blacklist and method chaining
$ywf = Yii::createComponent(array('class' => 'YiiWordFrequency'));
$ywf->sourceList = 'This is a test string. This is another test string. Test strings are fun.';
$ywf->blackList = array('this', 'is');
$frequencyList = $ywf->tagFrequencyList;
An example using a whitelist as well as configuration at object creation
$this->ywf = Yii::createComponent(array(
      'class' => 'YiiWordFrequency',
      'sourceList'=> array($this->inputFixture[0]),
      'whiteListFile' => array('../tests/fixtures/whiteList_test.txt'),
      'whiteListCaseSensitive' => true,


The initial motivation for this class was to generate data for a TagCloud which could be displayed with the yiitagcloud widget

See inline documentation for more information


1 0
Yii Version: Unknown
License: MIT
Category: Others
Developed by: apotter
Created on: Feb 19, 2014
Last updated: 4 years ago


show all

Related Extensions