Real time textual analysis via OpenAmplify

This post is more than 2 years old.

I've blogged before (see related entries below) about the coolness that is OpenAmplify. OpenAmplify provides an APi that does deep language parsing. It's not perfect of course - but in my testing it can be eerily spot on. In my previous blog entry on the topic I talked about how to use it via ColdFusion. You could imagine using OpenAmplify as a nightly task to scan the user generated content on your site and provide statistics on the general mood as well as topics covered in your discussions. For a site getting lots of dynamic content from their community, that could be vital. What I discovered this week though that is OpenAmplify also provides a JavaScript API. Here is a simple demo I created that uses their API, along with jQuery, to provide contextual analysis while you type. This could get annoying on a real forum perhaps, but it's kinda cool here.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src=""></script> <script> var api = ""; var apikey = "dhj34antjkh87bs6fmrrhymganaz78d5"; var apiURL = api + "?apiKey="+apikey+"&analysis=styles&outputFormat=json_js";

$(document).ready(function() {

var debounce = function (func, threshold, execAsap) {
    var timeout;
    return function debounced () {
        var obj = this, args = arguments;
        function delayed () {
            if (!execAsap)
                func.apply(obj, args);
            timeout = null; 
        if (timeout)
        else if (execAsap)
            func.apply(obj, args);
        timeout = setTimeout(delayed, threshold || 100); 

$("#comments").keyup(debounce(function(e) {
	var text = $.trim($(this).val());
	if(text == '') return;
	if(text.length &lt; 5) return;

	$.getScript(apiURL + "&inputText="+escape(text),function(data,status) {
		var content = "";
		content += "Your comment is generally " + amplifyOutput.StylesResponse.StylesReturn.Styles.Polarity.Mean.Name + "&lt;br&gt;";
		content += "Is your comment offering guidance?  " + amplifyOutput.StylesResponse.StylesReturn.Styles.OfferingGuidance.Name + "&lt;br&gt;";
		content += "Is your comment requesting guidance?  " + amplifyOutput.StylesResponse.StylesReturn.Styles.RequestingGuidance.Name + "&lt;br&gt;";
		content += "How decisive is your comment?  " + amplifyOutput.StylesResponse.StylesReturn.Styles.Decisiveness.Name + "&lt;br&gt;";
		content += "Uses slang?  " + amplifyOutput.StylesResponse.StylesReturn.Styles.Slang.Name + "&lt;br&gt;";
		content += "How flamboyant?  " + amplifyOutput.StylesResponse.StylesReturn.Styles.Flamboyance.Name + "&lt;br&gt;";

}); </script> </head>


<form> <textarea name="comments" id="comments" cols="30" rows="10"></textarea> <div id="commentText"></div> </form> </body> </html>

The HTML view portion of this is just the form with the text area. Pretend it's the blog comment form. The div beneath is blank and will be used for feedback. Now scroll to the top. The debounce function is something I've mentioned before. It's just going to be used to slow things down a bit as we type. We use it within our keyup event handler for the textarea. I grab the current value, and if it's big enough, we do a getScript() call to load in the remote OpenAmplify service. I specifically focused on the style portion of their API. They provide a lot more. I take the result, a JSON object, and then just create a nice result string from it. So how does it work? Check out the video:

I setup an online demo of this as well, but with my personal API key being used, it may start throwing errors under load. Be gentle.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Dave Ferguson posted on 6/3/2011 at 7:43 AM

This is sooooo cool. I was thinking of uses for this in the real world. I thought this would be great for a support group to scan email content and route email based on content.

So, if the email is full of anger you can delete it. Alternatively , if it is full of praise you can auto forward to your boss.



Comment 2 by Brian Swartzfager posted on 6/3/2011 at 3:43 PM

That is pretty cool. But it doesn't take much to get your text tagged as "slang": apparently it considers "isn't" to be slang. :)

Comment 3 by Raymond Camden posted on 6/3/2011 at 3:46 PM

Maybe it considers the contraction to be more informal - and therefore close to slang?

Comment 4 by Darrell Berry posted on 6/21/2011 at 6:23 PM

You'll get better results with the latest (2.1) version of the APi -- just change the endpoint so it's AmplifyWeb_v21 not AmplifyWeb_v20

Comment 5 by Raymond Camden posted on 6/21/2011 at 6:25 PM

Interesting. It would be cool if OpenAmplify could do something like jQuery's CDN - where you could just ask for version X and you automatically get the latest point release.