ruby_speech 1.1.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,244 +44,6 @@ module RubySpeech
44
44
  end
45
45
  end
46
46
  end
47
-
48
- describe "#potential_match?" do
49
- before do
50
- items.each { |item| subject << item }
51
- end
52
-
53
- context "with a single item of '6'" do
54
- let(:items) { [Item.new << (Token.new << '6')] }
55
-
56
- it "should be true for '6'" do
57
- subject.potential_match?('6').should be true
58
- end
59
-
60
- %w{5 7}.each do |input|
61
- it "should be false for '#{input}'" do
62
- subject.potential_match?(input).should be false
63
- end
64
- end
65
- end
66
-
67
- context "with options of '6' or '7'" do
68
- let(:items) { [Item.new << (Token.new << '6'), Item.new << (Token.new << '7')] }
69
-
70
- %w{6 7}.each do |input|
71
- it "should be true for '#{input}'" do
72
- subject.potential_match?(input).should be true
73
- end
74
- end
75
-
76
- %w{5 8 67 76}.each do |input|
77
- it "should be false for '#{input}'" do
78
- subject.potential_match?(input).should be false
79
- end
80
- end
81
- end
82
-
83
- context "with options of '67' or '25'" do
84
- let(:items) { [Item.new << (Token.new << '6') << (Token.new << '7'), Item.new << (Token.new << '2') << (Token.new << '5')] }
85
-
86
- %w{6 2}.each do |input|
87
- it "should be true for '#{input}'" do
88
- subject.potential_match?(input).should be true
89
- end
90
- end
91
-
92
- %w{3 7 5 65 27 76 52}.each do |input|
93
- it "should be false for '#{input}'" do
94
- subject.potential_match?(input).should be false
95
- end
96
- end
97
- end
98
-
99
- context "with options of '678' or '251'" do
100
- let(:items) { [Item.new << (Token.new << '6') << (Token.new << '7') << (Token.new << '8'), Item.new << (Token.new << '2') << (Token.new << '5') << (Token.new << '1')] }
101
-
102
- %w{6 67 2 25}.each do |input|
103
- it "should be true for '#{input}'" do
104
- subject.potential_match?(input).should be true
105
- end
106
- end
107
-
108
- %w{3 7 5 65 27 76 52}.each do |input|
109
- it "should be false for '#{input}'" do
110
- subject.potential_match?(input).should be false
111
- end
112
- end
113
- end
114
-
115
- context "with options of '6' or ('7' repeated twice)" do
116
- let(:items) { [Item.new << (Token.new << '6'), Item.new << (Item.new(:repeat => 2) << (Token.new << '7'))] }
117
-
118
- %w{6 7 77}.each do |input|
119
- it "should be true for '#{input}'" do
120
- pending
121
- subject.potential_match?(input).should be true
122
- end
123
- end
124
-
125
- %w{5 67 76 66}.each do |input|
126
- it "should be false for '#{input}'" do
127
- subject.potential_match?(input).should be false
128
- end
129
- end
130
- end
131
- end
132
-
133
- describe "#longest_potential_match" do
134
- before do
135
- items.each { |item| subject << item }
136
- end
137
-
138
- context "with a single item of '6'" do
139
- let(:items) { [Item.new << (Token.new << '6')] }
140
-
141
- %w{6 65 6776}.each do |input|
142
- it "should be '6' for '#{input}'" do
143
- subject.longest_potential_match(input).should == '6'
144
- end
145
- end
146
-
147
- %w{5 7 55 56}.each do |input|
148
- it "should be '' for '#{input}'" do
149
- subject.longest_potential_match(input).should == ''
150
- end
151
- end
152
- end
153
-
154
- context "with options of '6' or '7'" do
155
- let(:items) { [Item.new << (Token.new << '6'), Item.new << (Token.new << '7')] }
156
-
157
- %w{6 65 6776}.each do |input|
158
- it "should be '6' for '#{input}'" do
159
- subject.longest_potential_match(input).should == '6'
160
- end
161
- end
162
-
163
- %w{7 74 726}.each do |input|
164
- it "should be '7' for '#{input}'" do
165
- subject.longest_potential_match(input).should == '7'
166
- end
167
- end
168
-
169
- %w{5 55 56}.each do |input|
170
- it "should be '' for '#{input}'" do
171
- subject.longest_potential_match(input).should == ''
172
- end
173
- end
174
- end
175
-
176
- context "with options of '67' or '25'" do
177
- let(:items) { [Item.new << (Token.new << '6') << (Token.new << '7'), Item.new << (Token.new << '2') << (Token.new << '5')] }
178
-
179
- %w{6}.each do |input|
180
- it "should be '6' for '#{input}'" do
181
- subject.longest_potential_match(input).should == '6'
182
- end
183
- end
184
-
185
- %w{67 675 6767 6756}.each do |input|
186
- it "should be '67' for '#{input}'" do
187
- subject.longest_potential_match(input).should == '67'
188
- end
189
- end
190
-
191
- %w{2}.each do |input|
192
- it "should be '2' for '#{input}'" do
193
- subject.longest_potential_match(input).should == '2'
194
- end
195
- end
196
-
197
- %w{25 259 2525 2567}.each do |input|
198
- it "should be '25' for '#{input}'" do
199
- subject.longest_potential_match(input).should == '25'
200
- end
201
- end
202
-
203
- %w{5 7 72 56}.each do |input|
204
- it "should be '' for '#{input}'" do
205
- subject.longest_potential_match(input).should == ''
206
- end
207
- end
208
- end
209
-
210
- context "with options of '678' or '251'" do
211
- let(:items) { [Item.new << (Token.new << '6') << (Token.new << '7') << (Token.new << '8'), Item.new << (Token.new << '2') << (Token.new << '5') << (Token.new << '1')] }
212
-
213
- %w{6}.each do |input|
214
- it "should be '6' for '#{input}'" do
215
- subject.longest_potential_match(input).should == '6'
216
- end
217
- end
218
-
219
- %w{67 675 6767 6756}.each do |input|
220
- it "should be '67' for '#{input}'" do
221
- subject.longest_potential_match(input).should == '67'
222
- end
223
- end
224
-
225
- %w{678 6785 678678 67856}.each do |input|
226
- it "should be '678' for '#{input}'" do
227
- subject.longest_potential_match(input).should == '678'
228
- end
229
- end
230
-
231
- %w{2}.each do |input|
232
- it "should be '2' for '#{input}'" do
233
- subject.longest_potential_match(input).should == '2'
234
- end
235
- end
236
-
237
- %w{25 259 2525 2567}.each do |input|
238
- it "should be '25' for '#{input}'" do
239
- subject.longest_potential_match(input).should == '25'
240
- end
241
- end
242
-
243
- %w{251 2519 251251 25167}.each do |input|
244
- it "should be '251' for '#{input}'" do
245
- subject.longest_potential_match(input).should == '251'
246
- end
247
- end
248
-
249
- %w{5 7 72 56}.each do |input|
250
- it "should be '' for '#{input}'" do
251
- subject.longest_potential_match(input).should == ''
252
- end
253
- end
254
- end
255
-
256
- context "with options of '6' or '7' repeated twice" do
257
- let(:items) { [Item.new << (Token.new << '6'), Item.new << (Item.new(:repeat => 2) << (Token.new << '7'))] }
258
-
259
- %w{6 65 6776}.each do |input|
260
- it "should be '6' for '#{input}'" do
261
- subject.longest_potential_match(input).should == '6'
262
- end
263
- end
264
-
265
- %w{7 74 726}.each do |input|
266
- it "should be '7' for '#{input}'" do
267
- subject.longest_potential_match(input).should == '7'
268
- end
269
- end
270
-
271
- %w{7 77 774 7726}.each do |input|
272
- it "should be '77' for '#{input}'" do
273
- pending
274
- subject.longest_potential_match(input).should == '77'
275
- end
276
- end
277
-
278
- %w{5 55 56}.each do |input|
279
- it "should be '' for '#{input}'" do
280
- subject.longest_potential_match(input).should == ''
281
- end
282
- end
283
- end
284
- end
285
47
  end # OneOf
286
48
  end # GRXML
287
49
  end # RubySpeech
@@ -3,32 +3,22 @@ require 'spec_helper'
3
3
  describe RubySpeech::NLSML do
4
4
  let :example_document do
5
5
  '''
6
- <result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:xf="http://www.w3.org/2000/xforms" xmlns:myApp="foo" grammar="http://flight">
7
- <interpretation confidence="60">
6
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
7
+ <interpretation confidence="0.6">
8
8
  <input mode="speech">I want to go to Pittsburgh</input>
9
- <xf:model>
10
- <xf:group name="airline">
11
- <xf:string name="to_city"/>
12
- </xf:group>
13
- </xf:model>
14
- <xf:instance>
15
- <myApp:airline>
16
- <myApp:to_city>Pittsburgh</myApp:to_city>
17
- </myApp:airline>
18
- </xf:instance>
9
+ <instance>
10
+ <airline>
11
+ <to_city>Pittsburgh</to_city>
12
+ </airline>
13
+ </instance>
19
14
  </interpretation>
20
- <interpretation confidence="40">
15
+ <interpretation confidence="0.4">
21
16
  <input>I want to go to Stockholm</input>
22
- <xf:model>
23
- <xf:group name="airline">
24
- <xf:string name="to_city"/>
25
- </xf:group>
26
- </xf:model>
27
- <xf:instance>
28
- <myApp:airline>
29
- <myApp:to_city>Stockholm</myApp:to_city>
30
- </myApp:airline>
31
- </xf:instance>
17
+ <instance>
18
+ <airline>
19
+ <to_city>Stockholm</to_city>
20
+ </airline>
21
+ </instance>
32
22
  </interpretation>
33
23
  </result>
34
24
  '''
@@ -40,18 +30,12 @@ describe RubySpeech::NLSML do
40
30
  end
41
31
 
42
32
  it "should allow building a document" do
43
- document = RubySpeech::NLSML.draw(grammar: 'http://flight', 'xmlns:myApp' => 'foo') do
33
+ document = RubySpeech::NLSML.draw(grammar: 'http://flight') do
44
34
  interpretation confidence: 0.6 do
45
35
  input "I want to go to Pittsburgh", mode: :speech
46
36
 
47
- model do
48
- group name: 'airline' do
49
- string name: 'to_city'
50
- end
51
- end
52
-
53
37
  instance do
54
- self['myApp'].airline do
38
+ airline do
55
39
  to_city 'Pittsburgh'
56
40
  end
57
41
  end
@@ -60,27 +44,40 @@ describe RubySpeech::NLSML do
60
44
  interpretation confidence: 0.4 do
61
45
  input "I want to go to Stockholm"
62
46
 
63
- model do
64
- group name: 'airline' do
65
- string name: 'to_city'
66
- end
67
- end
68
-
69
47
  instance do
70
- self['myApp'].airline do
48
+ airline do
71
49
  to_city "Stockholm"
72
50
  end
73
51
  end
74
52
  end
75
53
  end
76
54
 
77
- if RUBY_ENGINE == 'jruby'
78
- expected_document.gsub! 'myApp:to_city', 'to_city'
79
- expected_document.gsub! 'xf:group', 'group'
80
- expected_document.gsub! 'xf:string', 'string'
55
+ document.to_xml.should == expected_document
56
+ end
57
+
58
+ context "with a string instance" do
59
+ let :example_document do
60
+ '''
61
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
62
+ <interpretation confidence="0.6">
63
+ <input mode="speech">I want to go to Pittsburgh</input>
64
+ <instance>I want to go to Pittsburgh</instance>
65
+ </interpretation>
66
+ </result>
67
+ '''
81
68
  end
82
69
 
83
- document.to_xml.should == expected_document
70
+ it "should allow building a document" do
71
+ document = RubySpeech::NLSML.draw(grammar: 'http://flight') do
72
+ interpretation confidence: 0.6 do
73
+ input "I want to go to Pittsburgh", mode: :speech
74
+
75
+ instance "I want to go to Pittsburgh"
76
+ end
77
+ end
78
+
79
+ document.to_xml.should == expected_document
80
+ end
84
81
  end
85
82
  end
86
83
 
@@ -89,7 +86,7 @@ describe RubySpeech::NLSML do
89
86
  RubySpeech.parse example_document
90
87
  end
91
88
 
92
- let(:empty_result) { '<result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:xf="http://www.w3.org/2000/xforms"/>' }
89
+ let(:empty_result) { '<result xmlns="http://www.ietf.org/xml/ns/mrcpv2"/>' }
93
90
 
94
91
  its(:grammar) { should == 'http://flight' }
95
92
 
@@ -127,14 +124,14 @@ describe RubySpeech::NLSML do
127
124
  subject.should_not be == RubySpeech.parse(empty_result)
128
125
  end
129
126
 
130
- context "with an interpretation that has no model/instance" do
127
+ context "with an interpretation that has no instance" do
131
128
  let :example_document do
132
129
  '''
133
- <result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
134
- <interpretation confidence="60">
130
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
131
+ <interpretation confidence="0.6">
135
132
  <input mode="speech">I want to go to Pittsburgh</input>
136
133
  </interpretation>
137
- <interpretation confidence="40">
134
+ <interpretation confidence="0.4">
138
135
  <input>I want to go to Stockholm</input>
139
136
  </interpretation>
140
137
  </result>
@@ -166,6 +163,35 @@ describe RubySpeech::NLSML do
166
163
  its(:best_interpretation) { should == expected_best_interpretation }
167
164
  end
168
165
 
166
+ context "with a string instance" do
167
+ let :example_document do
168
+ '''
169
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
170
+ <interpretation confidence="0.6">
171
+ <input mode="speech">I want to go to Pittsburgh</input>
172
+ <instance>I want to go to Pittsburgh</instance>
173
+ </interpretation>
174
+ </result>
175
+ '''
176
+ end
177
+
178
+ let(:expected_best_interpretation) do
179
+ {
180
+ confidence: 0.6,
181
+ input: { mode: :speech, content: 'I want to go to Pittsburgh' },
182
+ instance: 'I want to go to Pittsburgh',
183
+ instances: ['I want to go to Pittsburgh']
184
+ }
185
+ end
186
+
187
+ let(:expected_interpretations) do
188
+ [expected_best_interpretation]
189
+ end
190
+
191
+ its(:interpretations) { should == expected_interpretations }
192
+ its(:best_interpretation) { should == expected_best_interpretation }
193
+ end
194
+
169
195
  context "without any interpretations" do
170
196
  subject do
171
197
  RubySpeech.parse empty_result
@@ -177,32 +203,22 @@ describe RubySpeech::NLSML do
177
203
  context "with interpretations out of confidence order" do
178
204
  let :example_document do
179
205
  '''
180
- <result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:myApp="foo" xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
181
- <interpretation confidence="40">
206
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
207
+ <interpretation confidence="0.4">
182
208
  <input>I want to go to Stockholm</input>
183
- <xf:model>
184
- <xf:group name="airline">
185
- <xf:string name="to_city"/>
186
- </xf:group>
187
- </xf:model>
188
- <xf:instance>
189
- <myApp:airline>
190
- <myApp:to_city>Stockholm</myApp:to_city>
191
- </myApp:airline>
192
- </xf:instance>
209
+ <instance>
210
+ <airline>
211
+ <to_city>Stockholm</to_city>
212
+ </airline>
213
+ </instance>
193
214
  </interpretation>
194
- <interpretation confidence="60">
215
+ <interpretation confidence="0.6">
195
216
  <input mode="speech">I want to go to Pittsburgh</input>
196
- <xf:model>
197
- <xf:group name="airline">
198
- <xf:string name="to_city"/>
199
- </xf:group>
200
- </xf:model>
201
- <xf:instance>
202
- <myApp:airline>
203
- <myApp:to_city>Pittsburgh</myApp:to_city>
204
- </myApp:airline>
205
- </xf:instance>
217
+ <instance>
218
+ <airline>
219
+ <to_city>Pittsburgh</to_city>
220
+ </airline>
221
+ </instance>
206
222
  </interpretation>
207
223
  </result>
208
224
  '''
@@ -215,24 +231,19 @@ describe RubySpeech::NLSML do
215
231
  context "with multiple instances for a single interpretation" do
216
232
  let :example_document do
217
233
  '''
218
- <result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:myApp="foo" xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
219
- <interpretation confidence="100">
234
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
235
+ <interpretation confidence="1">
220
236
  <input mode="speech">I want to go to Boston</input>
221
- <xf:model>
222
- <xf:group name="airline">
223
- <xf:string name="to_city"/>
224
- </xf:group>
225
- </xf:model>
226
- <xf:instance>
227
- <myApp:airline>
228
- <myApp:to_city>Boston, MA</myApp:to_city>
229
- </myApp:airline>
230
- </xf:instance>
231
- <xf:instance>
232
- <myApp:airline>
233
- <myApp:to_city>Boston, UK</myApp:to_city>
234
- </myApp:airline>
235
- </xf:instance>
237
+ <instance>
238
+ <airline>
239
+ <to_city>Boston, MA</to_city>
240
+ </airline>
241
+ </instance>
242
+ <instance>
243
+ <airline>
244
+ <to_city>Boston, UK</to_city>
245
+ </airline>
246
+ </instance>
236
247
  </interpretation>
237
248
  </result>
238
249
  '''
@@ -254,68 +265,20 @@ describe RubySpeech::NLSML do
254
265
  its(:best_interpretation) { should == expected_interpretation }
255
266
  end
256
267
 
257
- context "with no namespaces (because some vendors think this is ok)" do
268
+ context "with no namespace" do
258
269
  let :example_document do
259
270
  '''
260
271
  <result grammar="http://flight">
261
- <interpretation confidence="60">
262
- <input mode="speech">I want to go to Pittsburgh</input>
263
- <model>
264
- <group name="airline">
265
- <string name="to_city"/>
266
- </group>
267
- </model>
268
- <instance>
269
- <airline>
270
- <to_city>Pittsburgh</to_city>
271
- </airline>
272
- </instance>
273
- </interpretation>
274
- <interpretation confidence="40">
275
- <input>I want to go to Stockholm</input>
276
- <model>
277
- <group name="airline">
278
- <string name="to_city"/>
279
- </group>
280
- </model>
281
- <instance>
282
- <airline>
283
- <to_city>Stockholm</to_city>
284
- </airline>
285
- </instance>
286
- </interpretation>
287
- </result>
288
- '''
289
- end
290
-
291
- its(:interpretations) { should == expected_interpretations }
292
- its(:best_interpretation) { should == expected_best_interpretation }
293
- end
294
-
295
- context "with just an NLSML namespace (because we need something, damnit!)" do
296
- let :example_document do
297
- '''
298
- <result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
299
- <interpretation confidence="60">
272
+ <interpretation confidence="0.6">
300
273
  <input mode="speech">I want to go to Pittsburgh</input>
301
- <model>
302
- <group name="airline">
303
- <string name="to_city"/>
304
- </group>
305
- </model>
306
274
  <instance>
307
275
  <airline>
308
276
  <to_city>Pittsburgh</to_city>
309
277
  </airline>
310
278
  </instance>
311
279
  </interpretation>
312
- <interpretation confidence="40">
280
+ <interpretation confidence="0.4">
313
281
  <input>I want to go to Stockholm</input>
314
- <model>
315
- <group name="airline">
316
- <string name="to_city"/>
317
- </group>
318
- </model>
319
282
  <instance>
320
283
  <airline>
321
284
  <to_city>Stockholm</to_city>
@@ -333,7 +296,7 @@ describe RubySpeech::NLSML do
333
296
  context "with a single interpretation with a nomatch input" do
334
297
  let :example_document do
335
298
  '''
336
- <result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
299
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
337
300
  <interpretation>
338
301
  <input>
339
302
  <nomatch/>
@@ -349,14 +312,9 @@ describe RubySpeech::NLSML do
349
312
  context "with multiple interpretations where one is a nomatch input" do
350
313
  let :example_document do
351
314
  '''
352
- <result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
353
- <interpretation confidence="60">
315
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
316
+ <interpretation confidence="0.6">
354
317
  <input mode="speech">I want to go to Pittsburgh</input>
355
- <model>
356
- <group name="airline">
357
- <string name="to_city"/>
358
- </group>
359
- </model>
360
318
  <instance>
361
319
  <airline>
362
320
  <to_city>Pittsburgh</to_city>
@@ -378,7 +336,7 @@ describe RubySpeech::NLSML do
378
336
  context "with a single interpretation with a noinput" do
379
337
  let :example_document do
380
338
  '''
381
- <result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
339
+ <result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
382
340
  <interpretation>
383
341
  <input>
384
342
  <noinput/>