By Matt Butcher
openamplify
OpenAmplify Drupal Series: Part 2 - Building a Mini Portal
Submitted by matt on Wed, 2010-01-27 21:30The Second in my three-part series on Drupal an OpenAmplify has been published on their community site. If you missed the first part, you may want to start there. Part three, coming soon, will cover the API, and will focus on development instead of configuration.
Part 2
In part two, I walk through the process of building a "mini portal" by taking semantic information returned from an OpenAmplify analysis of a node, and using that information in conjunction with other web services. For this demonstration, I released a new version of the module, and added support for Shopping.Com and Bloglines, both of which can return some impressively rich content.
OpenAmplify Drupal Series: Part 1 - The Amplify Module
Submitted by matt on Wed, 2010-01-13 20:33Over at OpenAmplify's Community site, they are running Part 1 of a three-part series I've written about using OpenAmplify with Drupal.
Open Amplify
The first part covers the basics of using Acquia Drupal and the Amplify module to perform semantic analysis of your content.
Drupal and Sentiment Analysis on OpenAmplify Blog
Submitted by matt on Wed, 2009-08-26 09:16Over at the OpenAmplify blog, SteveS talks about how the CMS world has changed, and how Drupal has "come to his rescue" as he builds a new corporate website. He discusses using OpenAmplify and the Drupal Amplify module to analyze sentiment.
Sentiment analysis is all the rage right now, with the New York Times running a big story on it last Sunday. The Drupal Amplify module provides a foothold into this market already, and I'm excited to be talking about it in my QueryPath session at DrupalCon Paris next week.
TweetyPants in the News
Submitted by matt on Tue, 2009-06-23 09:01
TweetyPants (http://tweetypants.com) ranks Twitter users on Style, Smarts, and Shizzle (slang). It was built using QueryPath and OpenAmplify. TweetyPants has been mentioned several times in the news lately. Here's the roundup:
- Twi5, June 23, 2009: TweetyPants is featured as the Twitter App of the Day.
- Killer Startups, June 22, 2009: TweetyPants is discussed as an enticing example of the border between fun and insight.
- TechCrunchIT, June 17, 2009: TweetyPants (and the Drupal Amplify module) are both mentioned as implementations of OpenAmplify.
Amplify Module and TweetyPants.com on TechCrunchIT
Submitted by matt on Wed, 2009-06-17 07:51
OpenAmplify launched their new community portal yesterday, and TechCrunchIT picked up the story today. The Drupal Amplify module is highlighted in the story, as is my TweetyPants Twitter tweet-rating website. OpenAmplify provides semantic analysis tools, and the Drupal Amplify module can be used to submit node content and retrieve semantic information about the node.
How to Access OpenAmplify from QueryPath
Submitted by matt on Thu, 2009-06-11 16:14
I've written a handful of tools that make use of the OpenAmplify web service. In all cases, I've used QueryPath to retrieve the XML from the remote server and then work with it locally. In this short article, I will explain how QueryPath can be used to retrieve content from OpenAmplify's web service. I will also provide brief examples of how QueryPath can work with the results.
To see these techniques in action, you can visit TweetyPants. To see some functional code, take a look at the Amplify and QP Services modules for Drupal.
Retrieving Data from OpenAmplify
Let's begin with some example code. The following code performs a simple POST-based query against the OpenAmplify web service.
<?php require 'QueryPath/QueryPath.php'; $url = 'http://portaltnx.openamplify.com/AmplifyWeb/AmplifyThis?'; $key = 'OPENAMPLIFY_API_KEY_GOES_HERE'; $text = 'This is the text we are going to amplify.'; $params = array( 'apiKey' => $key, ); $url .= http_build_query($params); $options = array( 'http' => array( 'method' => 'POST', 'user_agent' => 'QueryPath/2.0', 'header' => 'Content-type: application/x-www-form-url-encoded', 'content' => http_build_query(array('inputText' => $text)), ), ); $context = stream_context_create($options); try { $qp = qp($url, NULL, array('context' => $context)); } catch (Exception $e) { print "Could not retrieve data from OpenAmplify." . $e->getMessage(); exit; } ?>
To begin, we define $url, $key, and $text. $url will just contain the URL of the OpenAmplify server. $key is the API key that OpenAmplify issues to you. $text is the text that we are going to amplify. Typically, this will come from some other source, like a document or user input.
The $params array is going to contain GET parameters. Posting documents to OpenAmplify will still require us to pass some information as part of the GET string. Namely, the API key must be passed in a URL like this:
http://portaltnx.openamplify.com/AmplifyWeb/AmplifyThis?apiKey=MY_KEY
The $options array is a little more complex. When working with QueryPath, we rely upon PHP stream contexts to configure a particular HTTP request. The $options array will be used to define the context.
For our purposes, we only need to configure the HTTP stream wrapper. Inside that array, we set the HTTP method to POST, define a user agent (which is optional), and add an HTTP header telling the remote server what type of encoding we are using. Finally, we add content, which holds the encoded name/value pairs that we need to pass to the server.
For our query, we only need to pass the inputText parameter, whose value will be the text we want to analyze.
Once we have the $options list created, we use this to build the stream context for PHP. And from there, we simply need to retrieve the data from OpenAmplify:
<?php $context = stream_context_create($options); try { $qp = qp($url, NULL, array('context' => $context)); } catch (Exception $e) { print "Could not retrieve data from OpenAmplify." . $e->getMessage(); exit; } ?>
There are a few things to notice here. First, the second argument to qp() is a null simply because we do not need to search the return document immediately. The third parameter holds the options for QueryPath. In our case, we need to set the stream context.
Finally, the try/catch block wraps this block so that we can detect an error right away.
This brief description should get you started when connecting to OpenAmplify. But what do you do with the resulting QueryPath object?
Working with the Results
From the point above, you can access the contents of the OpenAmplify XML document via the $qp variable. For example, this code prints out the top 20 proper nouns that OpenAmplify has identified:
<?php $qp->find('ProperNouns>TopicResult>Topic>Name')->slice(0, 20); // Set up the output: $out = qp(QueryPath::HTML_STUB, 'body')->append('<ul/>')->find('ul'); // Add a list item for each noun: foreach ($qp as $name) { $out->append('<li>' . $name->text() . '</li>'); } // Write the contents to STDOUT $out->writeHTML(); ?>
The first line of the code snippet above searches for the name of every proper noun and then slices (keeps) the first 20. Note that we use the direct child combinator (>) because it is faster than using the any descendant combinator (represented by an empty space).
The $out QueryPath object will be the output document. The foreach loop simply goes through each proper noun and adds it to an unordered list in the output HTML document.
Finally, the results are printed out as an HTML document.
This should give you some ideas on how to work with OpenAmplify content from within QueryPath. To see some of the other techniques, take a look at the QP Services Drupal module, which makes frequent use of OpenAmplify data.
TweetyPants: Mashup of the Day at Programmable Web
Submitted by matt on Tue, 2009-06-02 10:32
Mashup of the DayTweetyPants was selected as the "Mashup of the Day" on ProgrammableWeb.
TweetyPants demonstrates how QueryPath can be used to combine multiple XML and HTML sources. It takes a user's recent Twitter activity, cleans it up a little, and then submits it for analysis to OpenAmplify. OpenAmplify returns an XML document with a semantic analysis of the content. QueryPath then takes that information and generates some HTML to display the results in a silly way.
TweetyPants Video
Submitted by matt on Wed, 2009-05-20 16:03Here's a screencast walk-through of the TweetyPants intelligence analyzer.
Enter a user's screen name and TweetyPants does an analysis of recent tweets by that user. It then rates the user's style, smarts, and shizzle. No, it doesn't do anything useful.
TweetyPants: How smart are your Twitter friends?
Submitted by matt on Mon, 2009-05-18 20:42Are your Twitter friends smarty-pantses? Today I am releasing TweetyPants, a tool that uses QueryPath, OpenAmplify, and Twitter to evaluate a user's posts for three things:
- Style: The more verbose and flowery one's prose is, the higher the score.
- Shizzle: The more slang a post has, the higher the score.
- Smarts: The more educated one's tweets are, the higher the score.
Along with scoring a Twitter account against these three categories, TweetyPants also tells you what that person has been recently tweeting about.
So enter the name of a Twitter friend and see how smart your friends are.
TweetyPants
QueryPath News
Submitted by matt on Tue, 2009-04-28 21:05This week is "QueryPath week".
dw
IBM developerWorks has published Get to know the QueryPath PHP library: A fast, easy way to work with XML and HTML. The article walks discusses the design of the QueryPath library, and walks through a simple Twitter search application.
OpenAmplify
The folks at OpenAmplify have started tweeting about my screencast using QueryPath with OpenAmplify. I was gonna save the screencast for CMS Expo, but here it is. (If you are coming to CMS Expo, I might let you play with it.)
This short screencast presents a quick module I put together that uses QueryPath to retrieve and process web service information. The cornerstone of the application is the OpenAmplify web service, which provides lexical analysis of a text, returning information that can be used, well, to build stuff like this.








