Monday, June 16, 2014

IDOL OnDemand API call using JavaScript

IDOL OnDemand API Tutorial
IDOL OnDemand delivers a rich set of web service APIs to enable developers to create ground-breaking data driven apps.To view complete set of API here
In this tutorial we are going to cover only 3 APIs,
  • Find Similar
  • OCR Document
  • Sentiment Analysis


Find Similar API : Finds documents that are conceptually similar to your text or a document. Returns documents in the IDOL OnDemand databases that are similar to text or a document that we provide. we can either submit text, an index reference, a file, an object store reference, or a URL.
In this tutorial, Find Similar API call from Wikipedia on the phrase 'Hello World'.
 
$.ajax({url:"https://api.idolondemand.com
/1/api/sync/findsimilar/v1?text=Hello+World&indexes=wiki_eng&
apikey=dac630d2-4aed-45b7-8fc7-99fa87858460",
success:function(result)
{window.reference = result.documents[0].reference;..}
Output response will be
  "documents": [
    {
      "reference": "http://en.wikipedia.org/wiki/Hell",
      "weight": 89.25,
      "links": [
        "HELL",
        "WORLD"
      ],
      "index": "wiki_eng",
      "title": "Hell"
    },
    {
      "reference": "http://en.wikipedia.org/wiki/Hello world program",
      "weight": 89.07,
      "links": [
        "HELL",
        "WORLD"
      ],
      "index": "wiki_eng",
      "title": "Hello world program"
    }, 


OCR Document API : The OCR Document API extracts text from an image that we provide. The API returns the extracted text, along with information about the location of the detected text in the original image.
In this tutorial, OCR Document API will call from the following image: 'http://www.java-made-easy.com/images/hello-world.jpg' and display the extracted text.
$.ajax({url:"https://api.idolondemand.com/1/api/sync
/ocrdocument/v1?url=http%3A%2F%2Fwww.java-made-easy.com%2Fimages%2F
hello-world.jpg&apikey=dac630d2-4aed-45b7-8fc7-99fa87858460",
success:function(result){ ..}
Output response will be
{
  "text_block": [
    {
      "text": "= 5\nJR '\npublic class Hellouorld {\n/ # 'X;
\n* @param args\n*!\n; public static void main
(String[] argsj {\n// TODO Auto-generated method stub El\nSystem
.out.printlnl"Hello world!"1;\n}\n}\n< ) i",
      "left": 0,
      "top": 0,
      "width": 562,
      "height": 472
    }
  ]
}


Sentiment Analysis API : The Sentiment Analysis API analyzes text to return the sentiment as positive, negative or neutral. It contains a dictionary of positive and negative words of different types, and defines patterns that describe how to combine these words to form positive and negative phrases.
In this tutorial, Sentiment Analysis API call with the text from the Hello World response (i.e reference link ). Display the Sentiment Score along with the Sentiment Rating
 var url3 = 'https://api.idolondemand.com/1/api/
sync/analyzesentiment/v1?url='+reference+'&
apikey=dac630d2-4aed-45b7-8fc7-99fa87858460';
$.ajax({url:url3,success:function(result){ var sentiment = result.aggregate.sentiment; var score = result.aggregate.score;}
Output response will be
 "aggregate": {
    "sentiment": "neutral",
    "score": -0.06540204218347706
  }

No comments: