luis 0.1.0.pre.alpha1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20b89c0201f2815959c4bc71542c32504ff338fe
4
- data.tar.gz: 8e32841762775a9c9f282524a36e301e9efa4da8
3
+ metadata.gz: 6030d5eed1e23c08ede610bf535cc646547c9052
4
+ data.tar.gz: 30c2f208a3e38c1dcecb58857178cbfd0a9df25a
5
5
  SHA512:
6
- metadata.gz: 31332d6ef01a60e03a9d84b87e211266723d58379bf700dddd3a509e3c43a307506ca4243704976eb56554c8f884ec09f3a519ad1fd7efc0bf1e77d11f91ed51
7
- data.tar.gz: ed93283d7e347d373881e1f493b126b73875300a9e70d3cd7bfe970463b5a23c031fbe068846d68998cfc972ca1cfb7188feefc0d2585de519f6078e6d7232c3
6
+ metadata.gz: ab9c0a510d98b53df9e10d9c5a8f7c7c910b6bb6dee220f73ff248ba1ea33c8bece29d988992767733d69054666144bc6bb4ba40623fd5b1a17cf87b18bbbf7a
7
+ data.tar.gz: 0b3c4df3c5a59a6c327d0c81bef5769ec8d574c1f96304d68443d19aafec0c743beba8bce6cbf7ca228287d5dc92e1dfeddbb4744c05d683bd9a050f6360c245
data/lib/luis.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'luis/version'
2
2
  require 'httparty'
3
+ # Luis Module
3
4
  module Luis
4
5
  autoload :Base, 'luis/base'
5
6
  autoload :Result, 'luis/result'
@@ -15,15 +16,29 @@ module Luis
15
16
  end
16
17
  API_URL = 'https://api.projectoxford.ai/luis/v1/application/preview'.freeze
17
18
 
18
- def self.query(query)
19
- response = get(API_URL, query: { 'id' => id, 'subscription-key' => subscription_key, 'q' => query })
19
+ # Query method for the luis
20
+ #
21
+ # @param [String,#read] query text
22
+ # @param [Luis::Result] Luis result object
23
+ def self.query(query, context_id = nil)
24
+ options = default_options
25
+ options['q'] = query
26
+ options['contextId'] = context_id if context_id
27
+ response = get(API_URL, query: options)
20
28
  Result.new JSON.parse(response.body)
21
29
  end
22
30
 
31
+ # Configure luis credentials and settings
32
+ #
33
+ # @param [options] contains list of options to set
23
34
  def self.configure(options = {})
24
35
  options.each do |key, value|
25
36
  instance_variable_set("@#{key}", value)
26
37
  end
27
38
  yield(self) if block_given?
28
39
  end
40
+
41
+ def self.default_options
42
+ { 'id' => id, 'subscription-key' => subscription_key }
43
+ end
29
44
  end
data/lib/luis/action.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  module Luis
2
+ # Luis action class
2
3
  class Action < Base
3
4
  attr_accessor :triggered, :name, :parameters
4
5
 
6
+ # @return [Array] parameters in the action
5
7
  def parameters
6
8
  @parameters.map { |parameter| Parameter.new parameter }
7
9
  end
data/lib/luis/base.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module Luis
2
+ # Baseclass for luis objects
2
3
  class Base
4
+ # Constructor to set options specified as instance variables
5
+ #
6
+ # @param [Hash] options hash
3
7
  def initialize(options = {})
4
8
  options.each do |key, value|
5
9
  instance_variable_set("@#{key}", value)
@@ -0,0 +1,12 @@
1
+ module Luis
2
+ # Luis composite entity class
3
+ #
4
+ class CompositeEntity < Base
5
+ attr_accessor :parentType, :value, :children
6
+
7
+ # @return [Array] list of child entities
8
+ def children
9
+ @children.map { |child| CompositeEntityChild.new child }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ module Luis
2
+ # Luis composite entry child class
3
+ class CompositeEntityChild < Base
4
+ attr_accessor :type, :value
5
+ end
6
+ end
data/lib/luis/dialog.rb CHANGED
@@ -1,13 +1,22 @@
1
1
  module Luis
2
+ # Luis dialog class
2
3
  class Dialog < Base
3
- attr_accessor :prompt, :parameterName, :parameterType, :contentId, :status
4
+ attr_accessor :prompt, :parameterName, :parameterType, :contextId, :status
4
5
 
6
+ # @return whether the dialog is finished
5
7
  def finished?
6
8
  status == 'Finished'
7
9
  end
8
10
 
11
+ # @return whether the dialog is question
9
12
  def question?
10
13
  status == 'Question'
11
14
  end
15
+
16
+ # Reply to dialog
17
+ # @param reply message
18
+ def reply(query)
19
+ Luis.query(query, contextId)
20
+ end
12
21
  end
13
22
  end
data/lib/luis/entity.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Luis
2
+ # Luis entity class
2
3
  class Entity < Base
3
4
  attr_accessor :entity, :type, :startIndex, :endIndex, :score
4
5
  end
data/lib/luis/intent.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  module Luis
2
+ # Luis intent class
2
3
  class Intent < Base
3
4
  attr_accessor :intent, :score, :actions
4
5
 
6
+ # Action list of the intent
7
+ # @return [Array] list of actions
5
8
  def actions
6
9
  @actions.map { |action| Action.new action }
7
10
  end
@@ -1,4 +1,5 @@
1
1
  module Luis
2
+ # Luis Parameter class
2
3
  class Parameter < Base
3
4
  attr_accessor :name, :required, :value
4
5
  end
data/lib/luis/result.rb CHANGED
@@ -1,27 +1,40 @@
1
1
  module Luis
2
+ # Luis result class
2
3
  class Result < Base
3
4
  attr_accessor :query, :intents, :entities, :dialog, :top_scoring_indent
4
5
 
6
+ # Intent with maximum score
7
+ # @return intent with maximum score
5
8
  def top_scoring_intent
6
9
  @topScoringIndent ||= @intents.first
7
10
  end
8
11
 
12
+ # List of intents
9
13
  def intents
10
14
  (@intents ||= [@topScoringIntent]).map do |intent|
11
15
  Intent.new intent
12
16
  end
13
17
  end
14
18
 
19
+ # Dialog object
15
20
  def dialog
16
21
  Dialog.new @dialog
17
22
  end
18
23
 
24
+ # List of entities
19
25
  def entities
20
26
  @entities.map { |entity| Entity.new entity }
21
27
  end
22
28
 
29
+ # Weather dialog is waiting for a response
23
30
  def awaiting_dialog_response?
24
- dialog && (dialog['status'] == 'Question')
31
+ dialog && dialog.question?
32
+ end
33
+
34
+ # Reply to dialog is dialog is waiting for a response
35
+ def reply(query)
36
+ return false unless awaiting_dialog_response?
37
+ dialog.reply(query)
25
38
  end
26
39
  end
27
40
  end
data/lib/luis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Luis
2
- VERSION = '0.1.0-alpha1'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre.alpha1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aboobacker MK
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-26 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,8 +86,8 @@ files:
86
86
  - lib/luis.rb
87
87
  - lib/luis/action.rb
88
88
  - lib/luis/base.rb
89
- - lib/luis/combosite_entity_child.rb
90
89
  - lib/luis/composite_entity.rb
90
+ - lib/luis/composite_entity_child.rb
91
91
  - lib/luis/dialog.rb
92
92
  - lib/luis/entity.rb
93
93
  - lib/luis/intent.rb
@@ -110,9 +110,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ">"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: 1.3.1
115
+ version: '0'
116
116
  requirements: []
117
117
  rubyforge_project:
118
118
  rubygems_version: 2.6.6
File without changes