alexa_modelbuilder 0.2.2 → 0.2.3

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: 7adaae5e55c22c5a56b8638f9d4136ccd3c26f79
4
- data.tar.gz: 415679be2f5e3495c35aa270dd32d2bb44128e61
3
+ metadata.gz: a547500e95eeeadcec607967625ad47db8e74ae7
4
+ data.tar.gz: b83dd6487e2774444abbdb2df0594eccd939a872
5
5
  SHA512:
6
- metadata.gz: 967e8ca5b53a155590556be2647677325514d92e74706044846d02aa5287e51e4e7364d54696196ce5f38d1b165cf3ae9e390a98687a01eba1259928fe74172f
7
- data.tar.gz: d36b7804a5cbfd00fcc2931e5a5389f464e19d08873f124de4b05a151da1fe94c42d10be2b24c4b3c22531a9e1231c49c826d056202722a4f8638cdb7f3b1828
6
+ metadata.gz: a61d11aee196ce8c44ef060395d77db5add8c9f270cb9d17650188228f0828b80ee39ea66dad5f9d94519131cda3b968875e8c0ffcd9240bf388dc12883ae8d6
7
+ data.tar.gz: cd26e6b949d90941f6f36feefcba5178a69fdee3a7ec7bdc61fd5d444414a78710e5f140b24dacccfa5214eb13a0f841d4e79555df9346fc11b88346ecc6b3c0
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,2 +1,2 @@
1
- ��O���q��2Qg�^�j䚇��� �)9��v����vMxL�;�Ǟ��_Wj�c\,�kI�K7��4���gT��4�X�k0\�|��zty��)-O'6C�n�t�� }���cjo�"Of���k ����)�mG�=�[[�C��0�3�:������}F`�˺���:k2��2���+�B;�Sp<~���ㄱ2�m���/��� y�s���@0�Ϸb���ڥ�h�Nb�������F�$��Wr�
2
- ��}
1
+ m4�؍$sr���1��x��3e���_0���X�k8Je��A���>�]�ֲ�T����a������g$Zy l}��}�9��f�d5r��>�!�]]=i m �Jː�Ĝ�y�&��0&��=���
2
+ � �&5'"�������%�m�����h�G��P�噞^���9�������$/�gZHŒ���027����Sr���1V�g��I!s{�U�X��(�7���D�`�M�U2��
@@ -80,11 +80,11 @@ class AlexaModelBuilder
80
80
  end
81
81
 
82
82
  def to_h()
83
- @h
83
+ @interact_model
84
84
  end
85
85
 
86
86
  def to_json(pretty: true)
87
- pretty ? JSON.pretty_generate(@h) : @h.to_json
87
+ pretty ? JSON.pretty_generate(@interact_model) : @interact_model.to_json
88
88
  end
89
89
 
90
90
  def to_s()
@@ -95,21 +95,45 @@ class AlexaModelBuilder
95
95
 
96
96
  def parse(lines)
97
97
 
98
- patterns = [
98
+ puts 'inside parse' if @debug
99
+
100
+ interaction = [
99
101
  [:root, 'invocation: :invocation', :invocation],
100
102
  [:root, 'types: :types', :types],
101
103
  [:types, /(.*)/, :type],
102
104
  [:root, ':intent', :intent],
103
105
  [:intent, ':utterance', :utterance],
104
- [:intent, 'slots: :slots', :slots],
106
+ [:intent, /slots:/, :slots],
105
107
  [:slots, /(.*)/, :slot],
106
108
  [:all, /#/, :comment]
107
109
  ]
108
110
 
109
- lp = LineParser.new patterns
110
- r = lp.parse lines
111
-
112
- h = {
111
+ a = %w(
112
+ vendorId
113
+ locale
114
+ name
115
+ summary
116
+ description
117
+ keywords
118
+ examplePhrases
119
+ testingInstructions
120
+ endpoint
121
+ )
122
+
123
+
124
+ manifest = a.map do |word|
125
+ x = word.gsub(/(?<=.)(?=[A-Z])/,'_').downcase
126
+ [:root, "%s: :%s" % [x,x], x.to_sym]
127
+ end
128
+
129
+ a2 = manifest + interaction
130
+ puts 'a2: ' + a2.inspect if @debug
131
+ lp = LineParser.new a2, debug: @debug
132
+ lp.parse lines
133
+ h = lp.to_h
134
+ puts 'h: ' + h.inspect if @debug
135
+
136
+ model = {
113
137
  'interactionModel' => {
114
138
  'languageModel' => {
115
139
  'invocationName' => '',
@@ -119,65 +143,64 @@ class AlexaModelBuilder
119
143
  }
120
144
  }
121
145
 
122
- lm = h['interactionModel']['languageModel']
123
- lm['invocationName'] = r[0][1].values.first
146
+ lm = model['interactionModel']['languageModel']
147
+ lm['invocationName'] = h[:invocation]
124
148
 
125
- raw_intents = r.select {|x| x.first == :intent}
149
+ intents = h[:intent].map do |row|
126
150
 
127
- intents = raw_intents.map do |x|
151
+ name, value = row.is_a?(Hash) ? row.to_a.first : [row, {}]
152
+ intent = {'name' => name , 'samples' => value[:utterance] || [] }
128
153
 
129
- raw_utterances = x[3].select {|y| y.first == :utterance}
154
+ slots = value[:slots]
130
155
 
131
- utterances = raw_utterances.map {|z| z[2].first.rstrip }
156
+ if slots then
132
157
 
133
- intent = {'name' => x[1].values.first, 'samples' => utterances }
134
- raw_slots = x[3].find {|x| x.first == :slots }
158
+ a = slots.is_a?(Array) ? value[:slots] : [slots]
135
159
 
136
- if raw_slots then
137
-
138
- intent['slots'] = raw_slots[3].map do |slot|
160
+ intent['slots'] = a.map do |slot|
139
161
 
140
- name, type = slot[2].first.split(/: */,2)
162
+ name, type = slot.split(/: */,2)
141
163
  {'name' => name, 'type' => type, 'samples' => []}
142
164
 
143
- end
165
+ end
166
+
144
167
  end
145
168
 
146
169
  intent
147
170
 
148
171
  end
149
172
 
150
-
151
173
  lm['intents'] = intents
152
174
 
153
- raw_types = r.find {|x| x.first == :types}
175
+ if h[:types] then
154
176
 
155
- if raw_types then
177
+ (h[:types].is_a?(Array) ? h[:types] : [h[:types]]).map do |raw_type|
156
178
 
157
- name, raw_val = raw_types[2][1].first.split(/: */)
158
- values = raw_val.split(/, */)
179
+ name, raw_val = raw_type.split(/: */)
180
+ values = raw_val.split(/, */)
159
181
 
160
- types = {'name' => name, 'values' => []}
161
-
162
- types['values'] = values.map do |raw_val|
163
-
164
- name, raw_synonyms = raw_val.split(/ *\(/,2)
165
-
166
- h2 = {'name' => {'value' => name }}
167
-
168
- if raw_synonyms then
169
- synonyms = raw_synonyms[0..-2].split(/, */)
170
- h2['synonyms'] = synonyms
171
- end
172
-
173
- h2
174
- end
182
+ types = {'name' => name, 'values' => []}
183
+
184
+ types['values'] = values.map do |raw_val|
185
+
186
+ name, raw_synonyms = raw_val.split(/ *\(/,2)
187
+
188
+ h2 = {'name' => {'value' => name }}
189
+
190
+ if raw_synonyms then
191
+ synonyms = raw_synonyms[0..-2].split(/, */)
192
+ h2['synonyms'] = synonyms
193
+ end
194
+
195
+ h2
196
+ end
175
197
 
176
- lm['types'] = types
198
+ lm['types'] = types
199
+ end
177
200
 
178
201
  end
179
202
 
180
- @h = h
203
+ @interact_model = model
181
204
 
182
205
  end
183
206
 
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.2.2
4
+ version: 0.2.3
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-19 00:00:00.000000000 Z
33
+ date: 2018-06-30 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: lineparser
metadata.gz.sig CHANGED
Binary file