oc-auto-tag Auto tags generation using Open Calais

  1. Documentation
  2. Change Log

OCAutoTag Component is a useful extension to auto generate tags from Calais service. This extension is based on Open Calais Tags PHP class written by Dan Grossman, see http://www.dangrossman.info/open-calais-tags/.

Currently only English and French are supported by Calais.

Resources

Documentation

Requirements
  • Yii 1.03 or above (only tested on Yii 1.03)
Installation
  • Extract the release file under protected/extensions
Usage

See an eample used in Blog Demo:

In config file main.php, add to component:

'components'=>array(
          ......
          'OCAutoTag'=>array(
	          'class'=>'application.extensions.OCAutoTag.EOCAutoTagComponent',
	          'oc_api_key'=>'calais_api_key', // required, add your Calais API key here
	          'tag_delimiter'=>',', // Optional, set tag delimiter here
          ),
          ......
        )

Modify actionCreate() action in PostController.php file:

public function actionCreate()
      	{
      		$post=new Post;
      		if(isset($_POST['Post']))
      		{
      		  $oc = Yii::app()->OCAutoTag; // Get an OCAutoTag instance
      		  $auto_tag = $oc->getTags($_POST['Post']['content']); // Get tag in string by sending in post content
      		  if(!empty($auto_tag))
      		    $_POST['Post']['tags'] = !empty($_POST['Post']['tags'])?$_POST['Post']['tags'].$oc->getTagDelimiter().$auto_tag:$auto_tag; // Append auto generated tags to user input tags if $auto_tag is not empty

      			$post->attributes=$_POST['Post'];
      			if(isset($_POST['previewPost'])){
      				$post->validate();
      			}
      			else if(isset($_POST['submitPost']) && $post->save())
      				$this->redirect(array('show','id'=>$post->id));
      		}
      		$this->render('create',array('post'=>$post));
      	}

Change Log

April 2, 2009
  • V0.1 Initial release.
1 0
1 follower
335 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Others
Tags:
Developed by: will
Created on: Apr 2, 2009
Last updated: 9 years ago

Downloads

show all