alexa_modelbuilder 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 29a02805ad54f017357ba708f22df04007d448c2
4
- data.tar.gz: b0caf4832186a73f8934b8a787a2c24bf945f08b
3
+ metadata.gz: 66eacd2fdc394f26b8a5a507eca5b9353607e926
4
+ data.tar.gz: 2e5fa1114547e4195b0785a9c39d25e661668267
5
5
  SHA512:
6
- metadata.gz: e751188d404f465fcf07d63594e94ca8420db3187d16eb53312edd61dc1b0169b4bc3f53533cd36769723f1df503fe47bee15449a2363415816f326f64132a06
7
- data.tar.gz: fb9010de80a78700c832c877dde453d0355aadcc385ea7ddb7c25dd981ddca243bbf127f10ed45a38e15c69e2b3b24082e4108923276f35e4a48e219a8f4c664
6
+ metadata.gz: f69d6b3eef73d76ff90bad68b185f08029027668a5f147fe28a2c25ac4f1ef652e06f65f835e82aca8ad537a51e10310c2eeeabab8f6dd27cb4783a16073fde9
7
+ data.tar.gz: 3fcde44f9711facf4abab444d86327dd169c66001da3d97581097b36c8ee033938fc6a1027376266cb1817fb44f4149957bc340a74ecb117a12dc296f6d0790b
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,95 +1,95 @@
1
- #!/usr/bin/env ruby
2
-
3
- # file: alexa_modelbuilder.rb
4
-
5
-
6
- require 'json'
7
- require 'lineparser'
8
-
9
-
10
- class AlexaModelBuilder
11
-
12
- def initialize(s=nil, debug: false, locale: 'en-GB')
13
-
14
- @debug, @locale = debug, locale
15
- parse(s) if s
16
-
17
- end
18
-
19
- def read(s)
20
-
21
- h = JSON.parse(s, symbolize_names: true)
22
-
23
- lm = h[:interactionModel][:languageModel]
24
- lm[:invocationName]
25
-
26
- out = []
27
- out << 'invocation: ' + lm[:invocationName] + "\n"
28
- puts lm[:intents].inspect if @debug
29
-
30
- lm[:intents].each do |intent|
31
-
32
- puts 'intent: ' + intent[:name].inspect if @debug
33
- out << intent[:name] + "\n"
34
-
35
- if intent[:samples] then
36
-
37
- intent[:samples].each do |utterance|
38
- puts 'utterance: ' + utterance.inspect if @debug
39
- out << " " + utterance
40
- end
41
-
42
- if intent[:slots] and intent[:slots].any? then
43
-
44
- out << "\n slots:"
45
-
46
- intent[:slots].each do |slot|
47
- out << " %s: %s" % [slot[:name], slot[:type]]
48
- end
49
-
50
- end
51
-
52
- out << "\n" if intent[:samples].any?
53
- end
54
-
55
- end
56
-
57
- if lm[:types] and lm[:types].any? then
58
-
59
- out << "types:"
60
-
61
- lm[:types].each do |type|
62
-
63
- values = type[:values].map do |x|
64
-
65
- synonyms = x[:name][:synonyms]
66
- val = x[:name][:value]
67
- val += ' (' + synonyms.join(', ') + ')' if synonyms and synonyms.any?
68
- val
69
- end
70
-
71
- out << " %s: %s" % [type[:name], values.join(', ')]
72
- end
73
-
74
- end
75
- out << "\n"
76
-
77
- @s = out.join("\n")
78
- #parse(@s)
79
- self
80
- end
81
-
82
- def to_h()
83
- @h
84
- end
85
-
86
- def to_manifest(json: false)
87
- json ? JSON.pretty_generate(@manifest) : @manifest
88
- end
89
-
90
- ## A guideline of fields to include within the raw document
91
-
92
- =begin
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: alexa_modelbuilder.rb
4
+
5
+
6
+ require 'json'
7
+ require 'lineparser'
8
+
9
+
10
+ class AlexaModelBuilder
11
+
12
+ def initialize(s=nil, debug: false, locale: 'en-GB')
13
+
14
+ @debug, @locale = debug, locale
15
+ parse(s) if s
16
+
17
+ end
18
+
19
+ def read(s)
20
+
21
+ h = JSON.parse(s, symbolize_names: true)
22
+
23
+ lm = h[:interactionModel][:languageModel]
24
+ lm[:invocationName]
25
+
26
+ out = []
27
+ out << 'invocation: ' + lm[:invocationName] + "\n"
28
+ puts lm[:intents].inspect if @debug
29
+
30
+ lm[:intents].each do |intent|
31
+
32
+ puts 'intent: ' + intent[:name].inspect if @debug
33
+ out << intent[:name] + "\n"
34
+
35
+ if intent[:samples] then
36
+
37
+ intent[:samples].each do |utterance|
38
+ puts 'utterance: ' + utterance.inspect if @debug
39
+ out << " " + utterance
40
+ end
41
+
42
+ if intent[:slots] and intent[:slots].any? then
43
+
44
+ out << "\n slots:"
45
+
46
+ intent[:slots].each do |slot|
47
+ out << " %s: %s" % [slot[:name], slot[:type]]
48
+ end
49
+
50
+ end
51
+
52
+ out << "\n" if intent[:samples].any?
53
+ end
54
+
55
+ end
56
+
57
+ if lm[:types] and lm[:types].any? then
58
+
59
+ out << "types:"
60
+
61
+ lm[:types].each do |type|
62
+
63
+ values = type[:values].map do |x|
64
+
65
+ synonyms = x[:name][:synonyms]
66
+ val = x[:name][:value]
67
+ val += ' (' + synonyms.join(', ') + ')' if synonyms and synonyms.any?
68
+ val
69
+ end
70
+
71
+ out << " %s: %s" % [type[:name], values.join(', ')]
72
+ end
73
+
74
+ end
75
+ out << "\n"
76
+
77
+ @s = out.join("\n")
78
+ #parse(@s)
79
+ self
80
+ end
81
+
82
+ def to_h()
83
+ @h
84
+ end
85
+
86
+ def to_manifest(json: false)
87
+ json ? JSON.pretty_generate(@manifest) : @manifest
88
+ end
89
+
90
+ ## A guideline of fields to include within the raw document
91
+
92
+ =begin
93
93
  manifest
94
94
 
95
95
  vendorId: [generate from vendors.first]
@@ -100,213 +100,217 @@ description: input (default)
100
100
  keywords: input (default)
101
101
  examplePhrases: [generate from intent utterances]
102
102
  testingInstructions: input [generate from intent utterances]
103
- endpoint: input
104
- =end
105
-
106
- def build_manifest(h)
107
-
108
- manifest = {
109
- "vendorId" => '',
110
- "manifest" => {
111
- "publishingInformation" => {
112
- "locales" => {
113
- },
114
- "isAvailableWorldwide" => false,
115
- "testingInstructions" => "1) Say 'Alexa, say something'",
116
- "category" => "SMART_HOME",
117
- "distributionCountries" => [
118
- ]
119
- },
120
- "apis" => {
121
- "custom" => {
122
- "endpoint" => {
123
- "uri" => "https://someserver.com/alexaskills"
124
- }
125
- }
126
- },
127
- "manifestVersion" => "1.0",
128
- "privacyAndCompliance" => {
129
- "allowsPurchases" => false,
130
- "locales" => {
131
- },
132
- "isExportCompliant" => true,
133
- "isChildDirected" => false,
134
- "usesPersonalInfo" => false
135
- }
136
- }
137
- }
138
-
139
- manifest['vendorId'] = h[:vendor_id] if h[:vendor_id]
140
- m = manifest['manifest']
141
-
142
- h[:locale] ||= @locale
143
-
144
-
145
- info = {}
146
- info['summary'] = h[:summary] || h[:name]
147
-
148
- examples = ["Alexa, open %s." % h[:invocation]]
149
- examples += h[:intent].select{|x| x.is_a? Hash}.take(2).map do |x|
150
- phrases = x.first[-1][:utterance]
151
- puts 'phrases: ' + phrases.inspect if @debug
152
- "Alexa, %s." % (phrases.is_a?(Array) ? phrases.first : phrases)
153
- end
154
-
155
- info['examplePhrases'] = examples
156
- info['keywords'] = h[:keywords] ? h[:keywords] : \
157
- h[:name].split.map(&:downcase)
158
-
159
- info['name'] = h[:name] if h[:name]
160
- info['description'] = h[:description] || info['summary']
161
-
162
- m['publishingInformation']['locales'] = {h[:locale] => info}
163
- countries = {gb: %w(GB US), us: %w(US GB)}
164
- m['publishingInformation']['distributionCountries'] = \
165
- countries[h[:locale][/[A-Z]+/].downcase.to_sym]
166
- m['apis']['custom']['endpoint']['uri'] = h[:endpoint] if h[:endpoint]
167
-
168
- toc = {
169
- 'termsOfUseUrl' => 'http://www.termsofuse.sampleskill.com',
170
- 'privacyPolicyUrl' => 'http://www.myprivacypolicy.sampleskill.com'
171
- }
172
- m['privacyAndCompliance']['locales'] = {h[:locale] => toc}
173
-
174
-
175
- instruct = ["open %s" % h[:invocation]]
176
- instruct << h[:intent].select{|x| x.is_a? Hash}\
177
- .first.values.first[:utterance].first
178
-
179
- tests = instruct.map.with_index {|x, i| "%s) Say 'Alexa, %s'" % [i+1, x]}
180
- m['publishingInformation']['testingInstructions'] = tests.join(' ')
181
-
182
- manifest
183
- end
184
-
185
-
186
- def to_model(json: false)
187
- json ? JSON.pretty_generate(@interact_model) : @interact_model
188
- end
189
-
190
- def to_json(pretty: true)
191
- pretty ? JSON.pretty_generate(@interact_model) : @interact_model.to_json
192
- end
193
-
194
- def to_s()
195
- @s
196
- end
197
-
198
- private
199
-
200
- def parse(lines)
201
-
202
- puts 'inside parse' if @debug
203
-
204
- interaction = [
205
- [:root, 'invocation: :invocation', :invocation],
206
- [:root, 'types: :types', :types],
207
- [:types, /(.*)/, :type],
208
- [:root, ':intent', :intent],
209
- [:intent, ':utterance', :utterance],
210
- [:intent, /slots:/, :slots],
211
- [:slots, /(.*)/, :slot],
212
- [:all, /#/, :comment]
213
- ]
214
-
215
- a = %w(
216
- vendorId
217
- locale
103
+ endpoint: input
104
+ =end
105
+
106
+ def build_manifest(h)
107
+
108
+ manifest = {
109
+ "manifest" => {
110
+ "publishingInformation" => {
111
+ "locales" => {
112
+ },
113
+ "isAvailableWorldwide" => false,
114
+ "testingInstructions" => "1) Say 'Alexa, say something'",
115
+ "category" => "SMART_HOME",
116
+ "distributionCountries" => [
117
+ ]
118
+ },
119
+ "apis" => {
120
+ "custom" => {
121
+ "endpoint" => {
122
+ "sslCertificateType"=>"Trusted",
123
+ "uri" => "https://someserver.com/alexaskills"
124
+ }
125
+ }
126
+ },
127
+ "manifestVersion" => "1.0",
128
+ "privacyAndCompliance" => {
129
+ "allowsPurchases" => false,
130
+ "locales" => {
131
+ },
132
+ "isExportCompliant" => true,
133
+ "isChildDirected" => false,
134
+ "usesPersonalInfo" => false
135
+ }
136
+ }
137
+ }
138
+
139
+ manifest['vendorId'] = h[:vendor_id] if h[:vendor_id]
140
+ m = manifest['manifest']
141
+
142
+ h[:locale] ||= @locale
143
+
144
+
145
+ info = {}
146
+ info['summary'] = h[:summary] || h[:name]
147
+
148
+ examples = ["Alexa, open %s." % h[:invocation]]
149
+ examples += h[:intent].select{|x| x.is_a? Hash}.take(2).map do |x|
150
+ phrases = x.first[-1][:utterance]
151
+ puts 'phrases: ' + phrases.inspect if @debug
152
+ "Alexa, %s." % (phrases.is_a?(Array) ? phrases.first : phrases)
153
+ end
154
+
155
+ info['examplePhrases'] = examples
156
+ info['keywords'] = h[:keywords] ? h[:keywords] : \
157
+ h[:name].split.map(&:downcase)
158
+
159
+ info['name'] = h[:name] if h[:name]
160
+ info['description'] = h[:description] || info['summary']
161
+
162
+ m['publishingInformation']['locales'] = {h[:locale] => info}
163
+ countries = {gb: %w(GB US), us: %w(US GB)}
164
+ m['publishingInformation']['distributionCountries'] = \
165
+ countries[h[:locale][/[A-Z]+/].downcase.to_sym]
166
+ m['apis']['custom']['endpoint']['uri'] = h[:endpoint] if h[:endpoint]
167
+
168
+ toc = {
169
+ 'termsOfUseUrl' => 'http://www.termsofuse.sampleskill.com',
170
+ 'privacyPolicyUrl' => 'http://www.myprivacypolicy.sampleskill.com'
171
+ }
172
+ m['privacyAndCompliance']['locales'] = {h[:locale] => toc}
173
+
174
+
175
+ instruct = ["open %s" % h[:invocation]]
176
+ instruct << h[:intent].select{|x| x.is_a? Hash}\
177
+ .first.values.first[:utterance].first
178
+
179
+ tests = instruct.map.with_index {|x, i| "%s) Say 'Alexa, %s'" % [i+1, x]}
180
+ m['publishingInformation']['testingInstructions'] = tests.join(' ')
181
+
182
+ manifest
183
+ end
184
+
185
+
186
+ def to_model(json: false)
187
+ json ? JSON.pretty_generate(@interact_model) : @interact_model
188
+ end
189
+
190
+ def to_json(pretty: true)
191
+ pretty ? JSON.pretty_generate(@interact_model) : @interact_model.to_json
192
+ end
193
+
194
+ def to_s()
195
+ @s
196
+ end
197
+
198
+ private
199
+
200
+ def parse(lines)
201
+
202
+ puts 'inside parse' if @debug
203
+
204
+ interaction = [
205
+ [:root, 'invocation: :invocation', :invocation],
206
+ [:root, 'types: :types', :types],
207
+ [:types, /(.*)/, :type],
208
+ [:root, ':intent', :intent],
209
+ [:intent, ':utterance', :utterance],
210
+ [:intent, /slots:/, :slots],
211
+ [:slots, /(.*)/, :slot],
212
+ [:all, /#/, :comment]
213
+ ]
214
+
215
+ a = %w(
216
+ vendorId
217
+ locale
218
218
  name
219
- summary
220
- description
219
+ summary
220
+ description
221
221
  keywords
222
222
  examplePhrases
223
- testingInstructions
224
- endpoint
225
- )
226
-
227
-
228
- manifest = a.map do |word|
229
- x = word.gsub(/(?<=.)(?=[A-Z])/,'_').downcase
230
- [:root, "%s: :%s" % [x,x], x.to_sym]
231
- end
232
-
233
- a2 = manifest + interaction
234
- puts 'a2: ' + a2.inspect if @debug
235
- lp = LineParser.new a2, debug: @debug
236
- lp.parse lines
237
- @h = h = lp.to_h
238
- puts 'h: ' + h.inspect if @debug
239
-
240
- model = {
241
- 'interactionModel' => {
242
- 'languageModel' => {
243
- 'invocationName' => '',
244
- 'intents' => [],
245
- 'types' => []
246
- }
247
- }
248
- }
249
-
250
- lm = model['interactionModel']['languageModel']
251
- lm['invocationName'] = h[:invocation]
252
-
253
- intents = h[:intent].map do |row|
254
-
255
- name, value = row.is_a?(Hash) ? row.to_a.first : [row, {}]
256
- intent = {'name' => name , 'samples' => value[:utterance] || [] }
257
-
258
- slots = value[:slots]
259
-
260
- if slots then
261
-
262
- a = slots.is_a?(Array) ? value[:slots] : [slots]
263
-
264
- intent['slots'] = a.map do |slot|
265
-
266
- name, type = slot.split(/: */,2)
267
- {'name' => name, 'type' => type, 'samples' => []}
268
-
269
- end
270
-
271
- end
272
-
273
- intent
274
-
275
- end
276
-
277
- lm['intents'] = intents
278
-
279
- if h[:types] then
280
-
281
- (h[:types].is_a?(Array) ? h[:types] : [h[:types]]).map do |raw_type|
282
-
283
- name, raw_val = raw_type.split(/: */)
284
- values = raw_val.split(/, */)
285
-
286
- types = {'name' => name, 'values' => []}
287
-
288
- types['values'] = values.map do |raw_val|
289
-
290
- name, raw_synonyms = raw_val.split(/ *\(/,2)
291
-
292
- h2 = {'name' => {'value' => name }}
293
-
294
- if raw_synonyms then
295
- synonyms = raw_synonyms[0..-2].split(/, */)
296
- h2['synonyms'] = synonyms
297
- end
298
-
299
- h2
300
- end
301
-
302
- lm['types'] = types
303
- end
304
-
305
- end
306
-
307
- @manifest = build_manifest h
308
- @interact_model = model
309
-
310
- end
311
-
312
- end
223
+ testingInstructions
224
+ endpoint
225
+ )
226
+
227
+
228
+ manifest = a.map do |word|
229
+ x = word.gsub(/(?<=.)(?=[A-Z])/,'_').downcase
230
+ [:root, "%s: :%s" % [x,x], x.to_sym]
231
+ end
232
+
233
+ a2 = manifest + interaction
234
+ puts 'a2: ' + a2.inspect if @debug
235
+ lp = LineParser.new a2, debug: @debug
236
+ lp.parse lines
237
+ @h = h = lp.to_h
238
+ puts 'h: ' + h.inspect if @debug
239
+
240
+ model = {
241
+ 'interactionModel' => {
242
+ 'languageModel' => {
243
+ 'invocationName' => '',
244
+ 'intents' => [],
245
+ 'types' => []
246
+ }
247
+ }
248
+ }
249
+
250
+ lm = model['interactionModel']['languageModel']
251
+ lm['invocationName'] = h[:invocation]
252
+
253
+ intents = h[:intent].map do |row|
254
+
255
+ name, value = row.is_a?(Hash) ? row.to_a.first : [row, {}]
256
+
257
+ value[:utterance] ||= []
258
+ samples = value[:utterance].is_a?(Array) ? value[:utterance] : \
259
+ [value[:utterance]]
260
+ intent = {'name' => name , 'samples' => samples}
261
+
262
+ slots = value[:slots]
263
+
264
+ if slots then
265
+
266
+ a = slots.is_a?(Array) ? value[:slots] : [slots]
267
+
268
+ intent['slots'] = a.map do |slot|
269
+
270
+ name, type = slot.split(/: */,2)
271
+ {'name' => name, 'type' => type, 'samples' => []}
272
+
273
+ end
274
+
275
+ end
276
+
277
+ intent
278
+
279
+ end
280
+
281
+ lm['intents'] = intents
282
+
283
+ if h[:types] then
284
+
285
+ (h[:types].is_a?(Array) ? h[:types] : [h[:types]]).map do |raw_type|
286
+
287
+ name, raw_val = raw_type.split(/: */)
288
+ values = raw_val.split(/, */)
289
+
290
+ types = {'name' => name, 'values' => []}
291
+
292
+ types['values'] = values.map do |raw_val|
293
+
294
+ name, raw_synonyms = raw_val.split(/ *\(/,2)
295
+
296
+ h2 = {'name' => {'value' => name }}
297
+
298
+ if raw_synonyms then
299
+ synonyms = raw_synonyms[0..-2].split(/, */)
300
+ h2['synonyms'] = synonyms
301
+ end
302
+
303
+ h2
304
+ end
305
+
306
+ lm['types'] = types
307
+ end
308
+
309
+ end
310
+
311
+ @manifest = build_manifest h
312
+ @interact_model = model
313
+
314
+ end
315
+
316
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_modelbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  EgZc9/Cpxo+WohlXR69qWm5QxX8PvdLu5ZjGD2OH5pBAPToJQyk9O8kZB9OdDMZT
31
31
  tns=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-06-30 00:00:00.000000000 Z
33
+ date: 2018-07-09 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: lineparser
metadata.gz.sig CHANGED
Binary file