Ruby gem for using the OpenAmplify API
Switch branches/tags
Clone or download
Pull request Compare This branch is 19 commits behind gregmoreno:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.gitignore
History
LICENSE
README.rdoc
Rakefile
VERSION.yml
openamplify.gemspec

README.rdoc

OpenAmplify

The OpenAmplify API reads text you supply and returns linguistic data explaining and classifying the content. What you do with that analysis is, in the fine tradition of APIs and mashups, up to you. Some possibilities might include pairing ads with articles, creating rich tag-clouds, or monitoring the tone of forum threads.

Helpful links

Install

gem install openamplify

Usage

Show the result from OpenAmplify as a Hash

require 'openamplify'

API_KEY = "register to get a key"
client = OpenAmplify::Client.new(:api_key => API_KEY)

text = "After getting the MX1000 laser mouse and the Z-5500 speakers i fell in love with logitech"
response = client.analyze_text(text)

# List all the keys and values returned by OpenAmplify
response.each do |k, v|
  pp k
  pp v
end

# 'response' works like a Hash
puts response['Topics']

# or use the shortcuts
response.top_topics
response.proper_nouns
response.locations
response.domains

Output Format

In case you need a different format, OpenAmplify supports XML, JSON, RDF, CSV. It can also return the result as a fancy HTML page.

# assuming you use Nokogiri
doc = Nokogiri::XML(response.to_xml)

# or you want a JSON
json = JSON.parse(response.to_json)

# you should really try the pretty formats
puts response.to_pretty
# or
puts response.to_signals

Analysis options

By default, OpenAmplify returns a number of 'signals' about your text. You can limit the result by setting the 'analysis' option.

The different options and explanations are available at community.openamplify.com/blogs/quickstart/pages/overview.aspx

client = OpenAmplify::Client.new(:api_key => API_KEY, :analysis => 'topics')

# or if you have a client instance already
client.analysis = 'topics'

response = client.analyze_text(text)
response['Topics']  # => should be another big Hash of key-value pairs
response['Demographics'] # => nil

POST method

By default, GET is used. If you need to analyze lots of text, use POST

client = OpenAmplify::Client.new(:api_key => API_KEY, :method => :post)

# or
client.method = :post

Request URL

In case you are wondering what the request URL looks like:

response.request_url

If someday, OpenAmplify decides to change their API URL:

client.base_url = 'http://newurl'

Testing

rake test OPEN_AMPLIFY_KEY=YOUR_KEY