Contents


Overview

Skill Level: Any Skill Level

Let's say you want to analyze stocks or some news from different data sources and interpret the message, Alchemy News API lets you make a query based on some input parameters and returns the data. One of the data that would help is the "sentiment".

Ingredients

An account in Bluemix.

Create the Alchemy service.

Jot down the API key credentials. this will be used when feeding the URL to query data from the Alchemy APIs.

Step-by-step

  1. Create Bluemix account and Alchemy API.

     

    Login to Bluemix at https://console.ng.bluemix.net. ( Create a new one if you do not have it )

    Screen-Shot-2017-01-13-at-3.58.18-PM

     

    Set up for the Alchemy service. Once created – note down the credentials and the API_KEY for further use.

    Screen-Shot-2017-01-13-at-2.26.02-PM

     

    Screen-Shot-2017-01-13-at-3.59.44-PM

  2. Interpret the news.

    Let's say the user wants to know if he wants to invest in bullion, or metals ( in this case we pick Copper ). I would want to know if it is a good thing to buy, sell or hold.

    Here I will give various examples on how to get this data and read the sentiments and other data.

    First,

    A simple API call would be to get all information about a particular industry sector i.e metals. ( e.g: Copper ) and return the data.

    Create an URL including the API_KEY and mention the query ( referenced by the letter q below ) and mention how the return has to be, in this case return a JSON of title and url and post it in the browser.

    https://access.alchemyapi.com/calls/data/GetNews?apikey=518c5d460c4c186240d0bab3fcaa0cb0301cf3e9&start=1483660800&end=1484351999&outputMode=json&count=25&q.enriched.url.url=copper&return=enriched.url.url,enriched.url.title

    Note : The return = url and title and watch the output, “return = enriched.url.url¬† and enriched.url.title”

    The query in the URL is “q.enriched.url.url”

     

    Screen-Shot-2017-01-13-at-12.54.06-PM

     

    Screen-Shot-2017-01-13-at-12.59.19-PM

  3. Watch for daily query limits - or else you can encounter an error as shown.

    Sometimes you might run out of number of queries for a day. There is a certain limit per day for 'unlicensed' users – then we can expect to see such an error. To resolve one has to purchase a licensed version of the API.

     

    A snapshot of transactions exceeded message :

    Screen-Shot-2017-01-13-at-1.10.54-PM

     

  4. Query for news having "Trump" as the keyword in the title and in the Government and Politics section.

    Here, I want to query for News that has the “trump” in it's title, Start and End Date, and look in the “Govt and Politics” section.

     

    Screen-Shot-2017-01-13-at-2.19.27-PM

     

    The same API in text here:

    https://access.alchemyapi.com/calls/data/GetNews?apikey=YOUR_API_KEY_HERE&return=enriched.url.title,enriched.url.url,enriched.url.enrichedTitle.docSentiment&start=1480897800&end=1484245800&q.enriched.url.enrichedTitle.entities.entity=|text=trump,type=person|&q.enriched.url.enrichedTitle.docSentiment.type=positive&q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label=law,%20govt%20and%20politics&count=25&outputMode=json

     

    The resulting JSON output would be something like :

    Note the “return” in the API where we specify the different types of information we need to see.

    We can also see the “document sentiment” along with a score to help us make some business decisions.

    The inputs are mentioned by the “q -query “parameter in the API.

    e.g: enriched.url.enrichedTitle.entities

    enriched.url.enriched…..taxonomy,

    More such keys can be found at this URL : http://www.ibm.com/watson/developercloud/alchemydata-news/api/v1/

    Screen-Shot-2017-01-13-at-2.21.01-PM

  5. References

    https://www.ibm.com/watson/developercloud/alchemy-language.html

    https://www.ibm.com/watson/developercloud/doc/alchemylanguage/

     

  6. Various Input and Output possibilities

    User can provide different inputs to the API like

    – Start and End date.

    – Subject we are interested in ( like name of a person, city etc )

    – Sentiment – where we can specify to query for 'positive' or negative sentiments ( or both )

    – Location of the key word we are searching for like is it in the Text /body or Title

    – Taxonomy ( or different categories ) that we would like to query the data from . e.g: search for 'Trump' in the Govt and Politics section.

     

    Please refer to http://www.ibm.com/watson/developercloud/alchemy-language/api/v1/ for more information on various parameters that can be fed to the API.

Join The Discussion