suchowan / watson-api-client

An IBM Watson™ API client
MIT License
27 stars 10 forks source link

Method for extracting Concepts tag using AlchemyLanguage API. #6

Closed abhinaykumar closed 8 years ago

abhinaykumar commented 8 years ago

I am trying to use AlchemyApi for extracting concepts tag from a text but for some reason it keeps throwing the error undefined method concepts for #<WatsonAPIClient::AlchemyLanguage:0x007f9d86754088> when trying to pass text using the similar syntax as shown in the exmaple. service.concepts(....). I am not sure if this is the right method also, I couldn't find any relevant info. regarding the same. Can you please tell me what is the method name for concepts tag and how to pass a text to it.

suchowan commented 8 years ago

Alchemy API was originally by a third-party service, later has been integrated into Watson API. Therefore, its API specifications deviate from the local rule at the first time. The rearranging of a naming convention of the method names is necessary. I am thankful when you can suggest some idea.

abhinaykumar commented 8 years ago

I figured out on how to post data using RestClient to get Concept-Tags , Personality-Insight and Tone-Analyzer. below is the working sample code for Concept-Tags:

concept_api_url = "https://gateway-a.watsonplatform.net/calls/text/TextGetRankedConcepts"
options = { text: "text", content_type: 'text/plain', apikey: 'xxxxx', url: 'http://example.com', outputMode: 'json', knowledgeGraph: 1 }
begin
  response = RestClient.post(concept_api_url, options)
rescue RestClient::ExceptionWithResponse => err
  puts err.response
end

Sample code for Personality-Insight:

profile_api_url = "https://gateway.watsonplatform.net/personality-insights/api/v2/profile"
client = RestClient::Resource.new(profile_api_url, 'username given by Api', 'password given by Api')
begin
  response = client.post text, content_type: 'text/plain'
rescue RestClient::ExceptionWithResponse => err
  puts err.response
end

I thought of adding the same to your library but I think you are following a different way to hit the Api endpoints.

suchowan commented 8 years ago

I'm going to have made sure that the APIs which belong to the Alchemy APIs will also work, but does it work at your place well?

abhinaykumar commented 8 years ago

Yeah it works pretty much everywhere.