Coder Social home page Coder Social logo

openamplify's Introduction

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.

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

openamplify's People

Contributors

gregmoreno avatar

Stargazers

David Lazar avatar

Watchers

David Lazar avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.