Created
May 10, 2017 09:29
-
-
Save iant/db9353aa35c4b83079e0591c887ef727 to your computer and use it in GitHub Desktop.
Watson natural language understanding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://www.ibm.com/watson/developercloud/natural-language-understanding/api/v1/ | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
require 'pp' | |
uri = URI.parse("https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2017-02-27") | |
request = Net::HTTP::Post.new(uri) | |
request.basic_auth(user_id, password) | |
request.content_type = "application/json" | |
request.body = { | |
"text": "IBM is an American multinational technology company headquartered in Armonk, New York, United States, with operations in over 170 countries.", | |
"features": { | |
"entities": { | |
"emotion": true, | |
"sentiment": true, | |
"limit": 10 | |
}, | |
"keywords": { | |
"emotion": true, | |
"sentiment": true, | |
"limit": 10 | |
} | |
} | |
}.to_json | |
req_options = { | |
use_ssl: uri.scheme == "https", | |
} | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
response.code | |
pp JSON.parse(response.body);nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment