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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
var api = "http://portaltnx20.openamplify.com/AmplifyWeb_v20/AmplifyThis";
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)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100);
}; } $("#comments").keyup(debounce(function(e) {
$("#commentText").html("");
var text = $.trim($(this).val());
if(text == '') return;
if(text.length < 5) return; $.getScript(apiURL + "&inputText="+escape(text),function(data,status) {
var content = "";
content += "Your comment is generally " + amplifyOutput.StylesResponse.StylesReturn.Styles.Polarity.Mean.Name + "<br>";
content += "Is your comment offering guidance? " + amplifyOutput.StylesResponse.StylesReturn.Styles.OfferingGuidance.Name + "<br>";
content += "Is your comment requesting guidance? " + amplifyOutput.StylesResponse.StylesReturn.Styles.RequestingGuidance.Name + "<br>";
content += "How decisive is your comment? " + amplifyOutput.StylesResponse.StylesReturn.Styles.Decisiveness.Name + "<br>";
content += "Uses slang? " + amplifyOutput.StylesResponse.StylesReturn.Styles.Slang.Name + "<br>";
content += "How flamboyant? " + amplifyOutput.StylesResponse.StylesReturn.Styles.Flamboyance.Name + "<br>"; $("#commentText").html(content);
});
},500));
});
</script>
</head> <body> <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.
Archived Comments
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.
;)
--Dave
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. :)
Maybe it considers the contraction to be more informal - and therefore close to slang?
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
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.