Dream to Learn is shutting down...

We are very sorry to say that Dream to Learn will be shutting down as of December 28th, 2019. If you have content that you wish to keep, you should make a copy of it before that date.


1COMMENTS0RECOMMENDS

IBM Watson & AlchemyAPI - Playing with Python (Part 2)

88
POSTED IN: Data Analytics & Visualization Blog

Python !?!

I'm exploring the AlchemyAPI APIs - they are pretty cool.

In March of 2015 - IBM Acquired AlchemyAPI - self-described as a 'cloud platform and community where developers can quickly build applications that achieve new insights and capabilities by applying advanced text analysis, computer vision and data storage services to huge volumes of unstructured data.'

In my prior post (Part 1), I did a 'hello world' with the R Programming language.  

I'm not a "Python Guy" - however because AlchemyAPI has so many 'ready to roll' resources in the Software Development Kits (SDKs) - I thought it would be worth getting some basic code running in Python, to help port the choicest cuts back to R.

I must say, I'm warming up to Python.

A few comments about the code and images below

  1. I installed python from here -https://www.python.org/downloads/windows/  - I installed the 2.7 version because I've seen/heard that 3.X doesnt support some older/mature features.  (Safe bet) - PAY ATTENTION TO PATHS in instructions - it will save you time.
  2. What is below is a first touch - straight out of the Python SDK - it's a subset of the example.PY file.  One of about 10 examples.  Wanted to keep it simple - start small and build up.
  3. If you don't know python, dont worry - there are heaps of starter resources out there, and I'll probably blog about 'getting started' here.
  4. I've replaced the generic JPG and HTML pages with my own (you can see other pages I tried commented out, try un-commenting)

Overall, getting initial contact was much easier than I expected.  I also think I got a bit lucky :)

One of the first I tried was our dream to learn 'about us' image 

SKY & MOUNTAIN

 

DOG, ANIMAL, and BEAR

this was a fun analysis - before it ran, because the image is 'missing' the body - we speculated whether Watson/Alchemy would guess a dog.  it's a very reasonable assertion.

 

#!/usr/bin/env python

#    Copyright 2013 AlchemyAPI
#   This code is a customized subset from code here: #   http://www.alchemyapi.com/developers/getting-started-guide/using-alchemyapi-with-python#clone-sdk 
#   Developed as part of an introductory learning module  www.dreamtolearn.com

from __future__ import print_function
from alchemyapi import AlchemyAPI
import json

#demo_text = 'Dream to Learn brings people together around a shared dream or goal. Todays student may be tomorrows teacher. Distant dreams can become reality when kindred spirits share a goal and support each other.'
 #demo_url = 'http://www.npr.org/2013/11/26/247336038/dont-stuff-the-turkey-and-other-tips-from-americas-test-kitchen'
 #demo_url = 'https://dreamtolearn.com/content/about.html'
#demo_html = '<html><head><title>Python Demo | AlchemyAPI</title></head><body><h1>Did you know that AlchemyAPI works on HTML?</h1><p>Well, you do now.</p></body></html>'
#image_url = 'http://demo1.alchemyapi.com/images/vision/football.jpg'
#image_url = 'https://dreamtolearn.com/internal/doc-asset/TPSH5N2R5BTR5QPU2QHVO6SY/Lucy_and_Julia.jpg'
#image_url = 'https://dreamtolearn.com/static/img/aspirational.jpg'
#image_url = 'http://www.plumbingproducts.com/images/pp-leaky-toilet.jpg'
#image_url = 'http://www.thepetmatchmaker.com/wp-content/uploads/2014/08/cats-in-sunglasses3-1.jpg'
#image_url ='http://www.purtonvets.co.uk/communities/8/004/011/970/238//images/4600405359_402x273.png'
#image_url ='http://rgmag.com/wp-content/uploads/2015/03/clouds.jpg'
#image_url = 'http://images.wisegeek.com/polar-bear.jpg'
#image_url = 'http://serbiandentaltourism.com/wp-content/uploads/2015/01/WhitenTeeth.jpg'
image_url = 'http://static.guim.co.uk/sys-images/Arts/Arts_/Pictures/2009/3/31/1238515405719/Brown-bear-001.jpg'

# Create the AlchemyAPI Object
alchemyapi = AlchemyAPI()

print('############################################')
print('#   Image Extraction Example               #')
print('############################################')
print('Processing url: ', image_url)

#### IMAGE TAGGING
response = alchemyapi.imageTagging('url', image_url)
if response['status'] == 'OK':
    print('## Keywords ##')
    for keyword in response['imageKeywords']:
        print(keyword['text'], ' : ', keyword['score'])
    print('')
else:
    print('Error in image tagging call: ', response['statusInfo'])
    

 

##########

Update Sept 17, 2015 - can also see some more code here:

https://github.com/rustyoldrake/R_Scripts_for_Watson

Interested in more content by this author?

About the Author

Ryan Anderson

Ryan Anderson

Hi! I like to play with data, analytics and hack around with robots and gadgets in my garage. Lately I've been learning about machine learning.

About this blog

Description is...<br/>Data Analytics & Visualization Blog - Generating insights from Data since 2013

Created: July 25, 2014

Englishfrançais

Up Next