Come to the 2010 CMS Expo

The Amplify Module: Developer's Guide

OpenAmplifyOpenAmplifyThe Amplify module is a Drupal module that provides a semantic analysis of your nodes. It is powered by OpenAmplify and QueryPath.

This guide provides basic configuration instructions for setting up the Amplify module. It also provides examples of how to retrieve the semantic information from an already amplified document. The Amplify module uses QueryPath for much of its work. If you are planning on doing significant integration with Amplify, you may want to familiarize yourself with the QueryPath API documentation.

Configuring the Amplify Module

To use this module, you will need to enable the QueryPath and QPCache modules (both in the QueryPath module).

After following the standard procedure for installing a Drupal module, you will need to configure Amplify.

The Amplify module uses the OpenAmplify web service, provided by Amplify. To use this service you will need to get an API key.

Once you have an API key and you have installed the Amplify module into Drupal, you will need to go to Administer > Site configuration > Amplify and configure your module. There are two things you need to do: Enter the API key, and tell the module which node type(s) to amplify:
Amplify SettingsAmplify Settings

Once the key is entered and the desired node types are selected, you will be all set. Each time you save a node of the selected type(s), a new OpenAmplify analysis will be done on that document.

Using Built-in Blocks

There are two blocks included with Amplify:

  • Mood Cloud: This provides various information about the the polarity (mood), ranking, and authoritativeness of the terms in an amplified document.
  • Basic Info: This will provide some basic analysis of the document.

These blocks will only be displayed on node pages for nodes that have been amplified.

A Basic Example: Get a List of Proper Nouns

The Amplify module provides several convenience functions for quickly retrieving Amplify information. Here's a simple example that will retrieve all of the proper nouns associated with a node:

<?php
 
// Load node # 6
$node = node_load(6);
 
// Get an array of nouns
$proper_nouns = amplify_get_proper_nouns($node);
 
// Loop through all nouns and set a message for each.
foreach ($proper_nouns as $noun => $score) {
  drupal_set_message($noun);
}
?>

The above simply loads a node, gets all of the associated proper nouns, and then displays them all to the screen using drupal_set_message().

Advanced Example: A Mood Cloud

In this example, we build a mood cloud. This will look like a tag cloud, but it is encoded to provide information about the tone of the document and the frequency that each term appeared.

Instead of using convenience functions, this uses QueryPath to work directly with the XML DOM.

<?php 
function qpservices_amplify_tags($node) {
  $qp = amplify_get_qp($node);
  drupal_add_css(drupal_get_path('module', 'qpservices') . '/qpservices.css');
  $out = qp('<?xml version="1.0"?><div class="tagcloud"/>', 'div');
  foreach ($qp->find('TopTopics>TopicResult')->slice(0, 10) as $topic) {
    $name = $topic->find('Topic>Name')->text();
    $polarity = $topic->end()->find('Polarity>Mean>Name')->text();
    $guidance = $topic->end()->find('OfferingGuidance>Name')->text();
 
    $pol_class = 'polarity-' . strtolower($polarity);
    $guid_class = 'guidance-' . strtr(strtolower($guidance), ' ', '-');
    $classes = $pol_class . ' ' . $guid_class . ' amplified-tags';
 
    $out->append('<span class="' . $classes . '">' . htmlentities($name) . '</span> ');
  }
  return $out;
}
?>

The chunk of markup created by the code above can then be inserted into a document. Here are the results of taking the output of that function and placing them in a block:
Mood CloudMood Cloud

Examine the XML

If you are interested in seeing what the XML looks like unadulterated, you may want to check out the amplify_get_xml() method.

Recent comments