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 +4 -4
- data/lib/luis.rb +17 -2
- data/lib/luis/action.rb +2 -0
- data/lib/luis/base.rb +4 -0
- data/lib/luis/composite_entity.rb +12 -0
- data/lib/luis/composite_entity_child.rb +6 -0
- data/lib/luis/dialog.rb +10 -1
- data/lib/luis/entity.rb +1 -0
- data/lib/luis/intent.rb +3 -0
- data/lib/luis/parameter.rb +1 -0
- data/lib/luis/result.rb +14 -1
- data/lib/luis/version.rb +1 -1
- metadata +5 -5
- data/lib/luis/combosite_entity_child.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6030d5eed1e23c08ede610bf535cc646547c9052
|
4
|
+
data.tar.gz: 30c2f208a3e38c1dcecb58857178cbfd0a9df25a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
19
|
-
|
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
data/lib/luis/base.rb
CHANGED
@@ -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
|
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, :
|
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
data/lib/luis/intent.rb
CHANGED
data/lib/luis/parameter.rb
CHANGED
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 &&
|
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
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
|
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-
|
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:
|
115
|
+
version: '0'
|
116
116
|
requirements: []
|
117
117
|
rubyforge_project:
|
118
118
|
rubygems_version: 2.6.6
|
File without changes
|