alexa_generator 0.2.1 → 0.3.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: 0515d8aff0f5502ee500bf27643d2db00c5f2257
4
- data.tar.gz: d54b203ce894bcbfc40604c78e5f5442d5315755
3
+ metadata.gz: df62fac43ca92e9a3c82c42a1fae04bd1feecc1a
4
+ data.tar.gz: 89650a53d1d39eb8469beef10a1999e8a671ae96
5
5
  SHA512:
6
- metadata.gz: e2c2dd3201dd4f1b5928f1459ab2fb1353b5f2a88d4e2037fc17434960966ba63e602ece410236c44ea7fbfa1b8a03d365621b15ea17fb5869a3f9bbd3b9131f
7
- data.tar.gz: 005652fc3257af55532d8dc618268a5b8bcf66e4819fb01ccf2692157cf1ed8834109ec3c4dc10ac48d07c84747d164acc4bcfe775bd030f8d961082345e9d89
6
+ metadata.gz: 44a03f30c76b4f5c7d7085413e606ba77c3b1d4371c08c497d50270b8864e1362efdd8d8163e1dac80cec0c03042c662c841075ad5305efc97952f25bef7f479
7
+ data.tar.gz: a515a2e4824e6d1d3ae968a0c59bf7dabbc454f440ea7f64f0bd08a5d124e85f2591a887463ce75004ff31f4d259f9959b0b879fcc7c2a3498b5faa3ac1bef57
@@ -92,10 +92,7 @@ module AlexaGenerator
92
92
  slot_value_combinations.each do |value_binding|
93
93
  raw_template = template.template.dup
94
94
 
95
- # puts value_binding.inspect
96
-
97
95
  value_binding.each do |binding|
98
- # puts "----> #{binding}"
99
96
  binding.bind_to_template!( raw_template )
100
97
  end
101
98
 
@@ -111,6 +108,26 @@ module AlexaGenerator
111
108
  "#{intent_name} #{utterance}"
112
109
  end
113
110
  end
111
+
112
+ def slot_type_values(slot_type)
113
+ bindings = Set.new
114
+ @intents.values.each do |intent|
115
+ intent.slots.each do |slot|
116
+ if slot.type.to_s == slot_type.to_s
117
+ bindings += slot.bindings
118
+ end
119
+ end
120
+ end
121
+ bindings.to_a
122
+ end
123
+
124
+ def custom_slot_types
125
+ slots = collect_slot_types
126
+ custom_types = slots.values.select do |x|
127
+ AlexaGenerator::Slot::SlotType.custom?(x)
128
+ end
129
+ Set.new(custom_types).to_a
130
+ end
114
131
 
115
132
  def collect_slot_types
116
133
  out = {}
@@ -10,6 +10,10 @@ module AlexaGenerator
10
10
  def self.literal?(value)
11
11
  [:LITERAL, LITERAL].include?(value.to_sym)
12
12
  end
13
+
14
+ def self.custom?(value)
15
+ !literal?(value) && !value.to_s.start_with?('AMAZON.')
16
+ end
13
17
  end
14
18
 
15
19
  class Builder
@@ -30,15 +34,16 @@ module AlexaGenerator
30
34
  end
31
35
 
32
36
  def create
33
- Slot.new(@name, @type)
37
+ Slot.new(@name, @type, @bindings)
34
38
  end
35
39
  end
36
40
 
37
- attr_reader :name, :type
41
+ attr_reader :name, :type, :bindings
38
42
 
39
- def initialize(name, type)
43
+ def initialize(name, type, bindings)
40
44
  @name = name.to_sym
41
45
  @type = type
46
+ @bindings = bindings
42
47
  end
43
48
 
44
49
  def self.build(name, type, &block)
@@ -1,3 +1,3 @@
1
1
  module AlexaGenerator
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -140,11 +140,6 @@ describe AlexaGenerator::InteractionModel do
140
140
  end
141
141
 
142
142
  context 'with a single template' do
143
- intents = [
144
- AlexaGenerator::Intent.new(
145
- :MyIntent, [ AlexaGenerator::Slot.new(:SlotOne, AlexaGenerator::Slot::SlotType::LITERAL) ]
146
- )
147
- ]
148
143
  utterance_templates = [
149
144
  AlexaGenerator::SampleUtteranceTemplate.new( :MyIntent, 'Alexa, please {SlotOne}')
150
145
  ]
@@ -152,6 +147,11 @@ describe AlexaGenerator::InteractionModel do
152
147
  AlexaGenerator::SlotBinding.new( :SlotOne, 'make me a sandwich' ),
153
148
  AlexaGenerator::SlotBinding.new( :SlotOne, 'fix my motorcycle' )
154
149
  ]
150
+ intents = [
151
+ AlexaGenerator::Intent.new(
152
+ :MyIntent, [ AlexaGenerator::Slot.new(:SlotOne, AlexaGenerator::Slot::SlotType::LITERAL, slot_bindings) ]
153
+ )
154
+ ]
155
155
 
156
156
  it 'should produce bound utterances' do
157
157
  actual = AlexaGenerator::InteractionModel.new(intents, utterance_templates, slot_bindings).sample_utterances(:MyIntent)
@@ -163,28 +163,32 @@ describe AlexaGenerator::InteractionModel do
163
163
  end
164
164
 
165
165
  context 'with multiple templates' do
166
+ s1_bindings = [
167
+ AlexaGenerator::SlotBinding.new( :SlotOne, 'make me a sandwich' ),
168
+ AlexaGenerator::SlotBinding.new( :SlotOne, 'fix my motorcycle' )
169
+ ]
170
+ s2_bindings = [
171
+ AlexaGenerator::SlotBinding.new( :SlotTwo, 'one' ),
172
+ AlexaGenerator::SlotBinding.new( :SlotTwo, 'two' ),
173
+ ]
174
+ s3_bindings = [
175
+ AlexaGenerator::SlotBinding.new( :SlotThree, '6 a.m.' ),
176
+ AlexaGenerator::SlotBinding.new( :SlotThree, 'noon' ),
177
+ ]
178
+
166
179
  intents = [
167
180
  AlexaGenerator::Intent.new(
168
181
  :MyIntent, [
169
- AlexaGenerator::Slot.new(:SlotOne, AlexaGenerator::Slot::SlotType::LITERAL),
170
- AlexaGenerator::Slot.new(:SlotTwo, AlexaGenerator::Slot::SlotType::NUMBER),
171
- AlexaGenerator::Slot.new(:SlotThree, AlexaGenerator::Slot::SlotType::TIME),
182
+ AlexaGenerator::Slot.new(:SlotOne, AlexaGenerator::Slot::SlotType::LITERAL, s1_bindings),
183
+ AlexaGenerator::Slot.new(:SlotTwo, AlexaGenerator::Slot::SlotType::NUMBER, s2_bindings),
184
+ AlexaGenerator::Slot.new(:SlotThree, AlexaGenerator::Slot::SlotType::TIME, s3_bindings),
172
185
  ],
173
186
  )
174
187
  ]
175
188
  utterance_templates = [
176
189
  AlexaGenerator::SampleUtteranceTemplate.new( :MyIntent, 'Alexa, please {SlotOne} {SlotTwo} at {SlotThree}')
177
190
  ]
178
- slot_bindings = [
179
- AlexaGenerator::SlotBinding.new( :SlotOne, 'make me a sandwich' ),
180
- AlexaGenerator::SlotBinding.new( :SlotOne, 'fix my motorcycle' ),
181
-
182
- AlexaGenerator::SlotBinding.new( :SlotTwo, 'one' ),
183
- AlexaGenerator::SlotBinding.new( :SlotTwo, 'two' ),
184
-
185
- AlexaGenerator::SlotBinding.new( :SlotThree, '6 a.m.' ),
186
- AlexaGenerator::SlotBinding.new( :SlotThree, 'noon' ),
187
- ]
191
+ slot_bindings = s1_bindings + s2_bindings + s3_bindings
188
192
 
189
193
  it 'should produce bound utterances' do
190
194
  actual = AlexaGenerator::InteractionModel.new(intents, utterance_templates, slot_bindings).sample_utterances(:MyIntent)
@@ -195,4 +199,36 @@ describe AlexaGenerator::InteractionModel do
195
199
  expect(actual).to include('MyIntent Alexa, please {make me a sandwich|SlotOne} {SlotTwo} at {SlotThree}')
196
200
  end
197
201
  end
202
+
203
+ context 'with custom slot types' do
204
+ model = AlexaGenerator::InteractionModel.build do |iface|
205
+ iface.add_intent(:IntentOne) do |intent|
206
+ intent.add_slot(:SlotOne, 'SlotType1') do |slot|
207
+ slot.add_bindings(*%w(value1 value2 value3))
208
+ end
209
+ end
210
+
211
+ iface.add_intent(:IntentTwo) do |intent|
212
+ intent.add_slot(:SlotA, 'SlotType1') do |slot|
213
+ slot.add_binding('value4')
214
+ end
215
+
216
+ intent.add_slot(:SlotB, :SlotType2) do |slot|
217
+ slot.add_binding('valueA')
218
+ end
219
+
220
+ intent.add_slot(:SlabC, AlexaGenerator::Slot::SlotType::NUMBER)
221
+ end
222
+ end
223
+
224
+ it 'should map slot bindings appropriately' do
225
+ expect(model.custom_slot_types).to contain_exactly(*%w(SlotType1 SlotType2))
226
+
227
+ type1_bindings = model.slot_type_values('SlotType1')
228
+ expect(type1_bindings).to contain_exactly(*%w(value1 value2 value3 value4))
229
+
230
+ type2_bindings = model.slot_type_values('SlotType2')
231
+ expect(type2_bindings).to contain_exactly(*%w(valueA))
232
+ end
233
+ end
198
234
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec