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.
gem install openamplify
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
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
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
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
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'
rake test OPEN_AMPLIFY_KEY=YOUR_KEY