Class: MaluubaNapi::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/maluuba_napi.rb

Overview

Provides simple access to the Maluuba NLP API (developer.maluuba.com) for Ruby scripts.

Basic Usage:

client = MaluubaNapi::Client.new 'your_apikey_here'
client.interpret phrase: 'who is barack obama'
client.normalize phrase: 'tomorrow', type: 'daterange', timezone: 'EST'

Your apikey is your ‘Consumer Key’ on (developer.maluuba.com)

For more information see (github.com/Maluuba/napi-ruby) Also visit us on our IRC channel at #maluuba on irc.freenode.net

Instance Method Summary collapse

Constructor Details

#initialize(apikey, options = {}) ⇒ Client

Creates a new client object

Parameters:

  • apikey (String)

    the consumer_key given

  • option (Hash)

    options optional parameters



30
31
32
33
# File 'lib/maluuba_napi.rb', line 30

def initialize(apikey, options={})
  @auth = {}
  @auth[:apikey] = apikey
end

Instance Method Details

#interpret(query_parameters = {}) ⇒ Hash

Calls the Interpret Endpoint

Parameters:

  • query_parameters (Hash) (defaults to: {})

    a hash of query parameters, :phrase is required

Returns:

  • (Hash)

    a hash consisting of :entities, :category and :action



38
39
40
41
42
43
# File 'lib/maluuba_napi.rb', line 38

def interpret(query_parameters={})
  response = query "/#{MaluubaNapi::Configuration::VERSION}/interpret", query_parameters
  response[:category] = response[:category].to_sym
  response[:action] = response[:action].to_sym
  response
end

#normalize(query_parameters = {}) ⇒ Hash

Calls the Normalize Endpoint

Parameters:

  • query_parameters (Hash) (defaults to: {})

    a hash of query parameters, :phrase and :type required

Returns:

  • (Hash)

    a hash consisting of :entities and :context



48
49
50
# File 'lib/maluuba_napi.rb', line 48

def normalize(query_parameters={})
  query "/#{MaluubaNapi::Configuration::VERSION}/normalize", query_parameters
end