ruby_speech 2.1.0-java

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.
Files changed (90) hide show
  1. data/.gitignore +12 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +17 -0
  4. data/CHANGELOG.md +144 -0
  5. data/Gemfile +3 -0
  6. data/Guardfile +9 -0
  7. data/LICENSE.md +20 -0
  8. data/README.md +314 -0
  9. data/Rakefile +34 -0
  10. data/assets/grammar-core.xsd +317 -0
  11. data/assets/grammar.xsd +37 -0
  12. data/assets/synthesis-core.xsd +445 -0
  13. data/assets/synthesis.xsd +63 -0
  14. data/assets/xml.xsd +287 -0
  15. data/ext/ruby_speech/RubySpeechGRXMLMatcher.java +64 -0
  16. data/ext/ruby_speech/RubySpeechService.java +23 -0
  17. data/ext/ruby_speech/extconf.rb +7 -0
  18. data/ext/ruby_speech/ruby_speech.c +97 -0
  19. data/lib/ruby_speech/generic_element.rb +169 -0
  20. data/lib/ruby_speech/grxml/element.rb +29 -0
  21. data/lib/ruby_speech/grxml/grammar.rb +189 -0
  22. data/lib/ruby_speech/grxml/item.rb +144 -0
  23. data/lib/ruby_speech/grxml/match.rb +16 -0
  24. data/lib/ruby_speech/grxml/matcher.rb +126 -0
  25. data/lib/ruby_speech/grxml/max_match.rb +6 -0
  26. data/lib/ruby_speech/grxml/no_match.rb +10 -0
  27. data/lib/ruby_speech/grxml/one_of.rb +31 -0
  28. data/lib/ruby_speech/grxml/potential_match.rb +10 -0
  29. data/lib/ruby_speech/grxml/rule.rb +73 -0
  30. data/lib/ruby_speech/grxml/ruleref.rb +69 -0
  31. data/lib/ruby_speech/grxml/tag.rb +29 -0
  32. data/lib/ruby_speech/grxml/token.rb +31 -0
  33. data/lib/ruby_speech/grxml.rb +39 -0
  34. data/lib/ruby_speech/nlsml/builder.rb +34 -0
  35. data/lib/ruby_speech/nlsml/document.rb +120 -0
  36. data/lib/ruby_speech/nlsml.rb +18 -0
  37. data/lib/ruby_speech/ruby_speech.jar +0 -0
  38. data/lib/ruby_speech/ssml/audio.rb +47 -0
  39. data/lib/ruby_speech/ssml/break.rb +62 -0
  40. data/lib/ruby_speech/ssml/desc.rb +24 -0
  41. data/lib/ruby_speech/ssml/element.rb +23 -0
  42. data/lib/ruby_speech/ssml/emphasis.rb +44 -0
  43. data/lib/ruby_speech/ssml/mark.rb +43 -0
  44. data/lib/ruby_speech/ssml/p.rb +25 -0
  45. data/lib/ruby_speech/ssml/phoneme.rb +72 -0
  46. data/lib/ruby_speech/ssml/prosody.rb +172 -0
  47. data/lib/ruby_speech/ssml/s.rb +25 -0
  48. data/lib/ruby_speech/ssml/say_as.rb +100 -0
  49. data/lib/ruby_speech/ssml/speak.rb +27 -0
  50. data/lib/ruby_speech/ssml/sub.rb +42 -0
  51. data/lib/ruby_speech/ssml/voice.rb +108 -0
  52. data/lib/ruby_speech/ssml.rb +39 -0
  53. data/lib/ruby_speech/version.rb +3 -0
  54. data/lib/ruby_speech/xml/language.rb +13 -0
  55. data/lib/ruby_speech/xml.rb +11 -0
  56. data/lib/ruby_speech.rb +36 -0
  57. data/ruby_speech.gemspec +42 -0
  58. data/spec/ruby_speech/grxml/grammar_spec.rb +341 -0
  59. data/spec/ruby_speech/grxml/item_spec.rb +192 -0
  60. data/spec/ruby_speech/grxml/match_spec.rb +15 -0
  61. data/spec/ruby_speech/grxml/matcher_spec.rb +688 -0
  62. data/spec/ruby_speech/grxml/max_match_spec.rb +17 -0
  63. data/spec/ruby_speech/grxml/no_match_spec.rb +17 -0
  64. data/spec/ruby_speech/grxml/one_of_spec.rb +49 -0
  65. data/spec/ruby_speech/grxml/potential_match_spec.rb +17 -0
  66. data/spec/ruby_speech/grxml/rule_spec.rb +125 -0
  67. data/spec/ruby_speech/grxml/ruleref_spec.rb +55 -0
  68. data/spec/ruby_speech/grxml/tag_spec.rb +41 -0
  69. data/spec/ruby_speech/grxml/token_spec.rb +62 -0
  70. data/spec/ruby_speech/grxml_spec.rb +339 -0
  71. data/spec/ruby_speech/nlsml_spec.rb +353 -0
  72. data/spec/ruby_speech/ssml/audio_spec.rb +121 -0
  73. data/spec/ruby_speech/ssml/break_spec.rb +100 -0
  74. data/spec/ruby_speech/ssml/desc_spec.rb +57 -0
  75. data/spec/ruby_speech/ssml/emphasis_spec.rb +110 -0
  76. data/spec/ruby_speech/ssml/mark_spec.rb +53 -0
  77. data/spec/ruby_speech/ssml/p_spec.rb +96 -0
  78. data/spec/ruby_speech/ssml/phoneme_spec.rb +65 -0
  79. data/spec/ruby_speech/ssml/prosody_spec.rb +309 -0
  80. data/spec/ruby_speech/ssml/s_spec.rb +92 -0
  81. data/spec/ruby_speech/ssml/say_as_spec.rb +71 -0
  82. data/spec/ruby_speech/ssml/speak_spec.rb +166 -0
  83. data/spec/ruby_speech/ssml/sub_spec.rb +57 -0
  84. data/spec/ruby_speech/ssml/voice_spec.rb +200 -0
  85. data/spec/ruby_speech/ssml_spec.rb +285 -0
  86. data/spec/ruby_speech_spec.rb +124 -0
  87. data/spec/spec_helper.rb +21 -0
  88. data/spec/support/match_examples.rb +43 -0
  89. data/spec/support/matchers.rb +46 -0
  90. metadata +405 -0
@@ -0,0 +1,688 @@
1
+ require 'spec_helper'
2
+
3
+ module RubySpeech
4
+ module GRXML
5
+ describe Matcher do
6
+ let(:grammar) { nil }
7
+
8
+ subject { described_class.new grammar }
9
+
10
+ describe "matching against an input string" do
11
+ context "with a grammar that takes a single specific digit" do
12
+ let(:grammar) do
13
+ GRXML.draw :mode => :dtmf, :root => 'digit' do
14
+ rule :id => 'digit' do
15
+ '6'
16
+ end
17
+ end
18
+ end
19
+
20
+ it "should max-match '6'" do
21
+ input = '6'
22
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
23
+ :confidence => 1,
24
+ :utterance => '6',
25
+ :interpretation => 'dtmf-6'
26
+ subject.match(input).should == expected_match
27
+ input.should == '6'
28
+ end
29
+
30
+ %w{1 2 3 4 5 7 8 9 10 66 26 61}.each do |input|
31
+ it "should not match '#{input}'" do
32
+ subject.match(input).should == GRXML::NoMatch.new
33
+ end
34
+ end
35
+ end
36
+
37
+ context "with a grammar with SISR tags" do
38
+ let :grammar do
39
+ RubySpeech::GRXML.draw mode: 'dtmf', root: 'options', tag_format: 'semantics/1.0-literals' do
40
+ rule id: 'options', scope: 'public' do
41
+ item do
42
+ one_of do
43
+ item do
44
+ tag { 'foo' }
45
+ '1'
46
+ end
47
+ item do
48
+ tag { 'bar' }
49
+ '2'
50
+ end
51
+ item do
52
+ tag { 'baz' }
53
+ '3'
54
+ end
55
+ item do
56
+ tag { 'lala' }
57
+ '4'
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ it "should return the literal tag interpretation" do
66
+ expected_match = GRXML::MaxMatch.new mode: :dtmf, confidence: 1,
67
+ utterance: '2', interpretation: 'bar'
68
+ subject.match('2').should == expected_match
69
+ end
70
+ end
71
+
72
+ context "with a grammar that takes two specific digits" do
73
+ let(:grammar) do
74
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
75
+ rule :id => 'digits' do
76
+ '5 6'
77
+ end
78
+ end
79
+ end
80
+
81
+ it "should maximally match '56'" do
82
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
83
+ :confidence => 1,
84
+ :utterance => '56',
85
+ :interpretation => 'dtmf-5 dtmf-6'
86
+ subject.match('56').should == expected_match
87
+ end
88
+
89
+ it "should potentially match '5'" do
90
+ input = '5'
91
+ subject.match(input).should == GRXML::PotentialMatch.new
92
+ input.should == '5'
93
+ end
94
+
95
+ %w{* *7 #6 6* 1 2 3 4 6 7 8 9 10 65 57 46 26 61}.each do |input|
96
+ it "should not match '#{input}'" do
97
+ subject.match(input).should == GRXML::NoMatch.new
98
+ end
99
+ end
100
+ end
101
+
102
+ context "with a grammar that takes star and a digit" do
103
+ let(:grammar) do
104
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
105
+ rule :id => 'digits' do
106
+ '* 6'
107
+ end
108
+ end
109
+ end
110
+
111
+ it "should maximally match '*6'" do
112
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
113
+ :confidence => 1,
114
+ :utterance => '*6',
115
+ :interpretation => 'dtmf-star dtmf-6'
116
+ subject.match('*6').should == expected_match
117
+ end
118
+
119
+ it "should potentially match '*'" do
120
+ subject.match('*').should == GRXML::PotentialMatch.new
121
+ end
122
+
123
+ %w{*7 #6 6* 1 2 3 4 5 6 7 8 9 10 66 26 61}.each do |input|
124
+ it "should not match '#{input}'" do
125
+ subject.match(input).should == GRXML::NoMatch.new
126
+ end
127
+ end
128
+ end
129
+
130
+ context "with a grammar that takes hash and a digit" do
131
+ let(:grammar) do
132
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
133
+ rule :id => 'digits' do
134
+ '# 6'
135
+ end
136
+ end
137
+ end
138
+
139
+ it "should maximally match '#6'" do
140
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
141
+ :confidence => 1,
142
+ :utterance => '#6',
143
+ :interpretation => 'dtmf-pound dtmf-6'
144
+ subject.match('#6').should == expected_match
145
+ end
146
+
147
+ it "should potentially match '#'" do
148
+ subject.match('#').should == GRXML::PotentialMatch.new
149
+ end
150
+
151
+ %w{* *6 #7 6* 1 2 3 4 5 6 7 8 9 10 66 26 61}.each do |input|
152
+ it "should not match '#{input}'" do
153
+ subject.match(input).should == GRXML::NoMatch.new
154
+ end
155
+ end
156
+ end
157
+
158
+ context "with a grammar that takes two specific digits, via a ruleref, and whitespace normalization" do
159
+ let(:grammar) do
160
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
161
+ rule :id => 'digits' do
162
+ ruleref :uri => '#star'
163
+ '" 6 "'
164
+ end
165
+
166
+ rule :id => 'star' do
167
+ '" * "'
168
+ end
169
+ end
170
+ end
171
+
172
+ it "should maximally match '*6'" do
173
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
174
+ :confidence => 1,
175
+ :utterance => '*6',
176
+ :interpretation => 'dtmf-star dtmf-6'
177
+ subject.match('*6').should == expected_match
178
+ end
179
+
180
+ it "should potentially match '*'" do
181
+ subject.match('*').should == GRXML::PotentialMatch.new
182
+ end
183
+
184
+ %w{*7 #6 6* 1 2 3 4 5 6 7 8 9 10 66 26 61}.each do |input|
185
+ it "should not match '#{input}'" do
186
+ subject.match(input).should == GRXML::NoMatch.new
187
+ end
188
+ end
189
+ end
190
+
191
+ context "with a grammar that takes a single digit alternative" do
192
+ let(:grammar) do
193
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
194
+ rule :id => 'digits' do
195
+ one_of do
196
+ item { '6' }
197
+ item { '7' }
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ it "should maximally match '6'" do
204
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
205
+ :confidence => 1,
206
+ :utterance => '6',
207
+ :interpretation => 'dtmf-6'
208
+ subject.match('6').should == expected_match
209
+ end
210
+
211
+ it "should maximally match '7'" do
212
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
213
+ :confidence => 1,
214
+ :utterance => '7',
215
+ :interpretation => 'dtmf-7'
216
+ subject.match('7').should == expected_match
217
+ end
218
+
219
+ %w{* # 1 2 3 4 5 8 9 10 66 26 61}.each do |input|
220
+ it "should not match '#{input}'" do
221
+ subject.match(input).should == GRXML::NoMatch.new
222
+ end
223
+ end
224
+ end
225
+
226
+ context "with a grammar that takes a double digit alternative" do
227
+ let(:grammar) do
228
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
229
+ rule :id => 'digits' do
230
+ one_of do
231
+ item do
232
+ token { '6' }
233
+ token { '5' }
234
+ end
235
+ item do
236
+ token { '7' }
237
+ token { '2' }
238
+ end
239
+ end
240
+ end
241
+ end
242
+ end
243
+
244
+ it "should maximally match '65'" do
245
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
246
+ :confidence => 1,
247
+ :utterance => '65',
248
+ :interpretation => 'dtmf-6 dtmf-5'
249
+ subject.match('65').should == expected_match
250
+ end
251
+
252
+ it "should maximally match '72'" do
253
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
254
+ :confidence => 1,
255
+ :utterance => '72',
256
+ :interpretation => 'dtmf-7 dtmf-2'
257
+ subject.match('72').should == expected_match
258
+ end
259
+
260
+ %w{6 7}.each do |input|
261
+ it "should potentially match '#{input}'" do
262
+ subject.match(input).should == GRXML::PotentialMatch.new
263
+ end
264
+ end
265
+
266
+ %w{* # 1 2 3 4 5 8 9 10 66 26 61 75}.each do |input|
267
+ it "should not match '#{input}'" do
268
+ subject.match(input).should == GRXML::NoMatch.new
269
+ end
270
+ end
271
+ end
272
+
273
+ context "with a grammar that takes a triple digit alternative" do
274
+ let(:grammar) do
275
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
276
+ rule :id => 'digits' do
277
+ one_of do
278
+ item do
279
+ token { '6' }
280
+ token { '5' }
281
+ token { '2' }
282
+ end
283
+ item do
284
+ token { '7' }
285
+ token { '2' }
286
+ token { '8' }
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ it "should maximally match '652'" do
294
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
295
+ :confidence => 1,
296
+ :utterance => '652',
297
+ :interpretation => 'dtmf-6 dtmf-5 dtmf-2'
298
+ subject.match('652').should == expected_match
299
+ end
300
+
301
+ it "should maximally match '728'" do
302
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
303
+ :confidence => 1,
304
+ :utterance => '728',
305
+ :interpretation => 'dtmf-7 dtmf-2 dtmf-8'
306
+ subject.match('728').should == expected_match
307
+ end
308
+
309
+ %w{6 65 7 72}.each do |input|
310
+ it "should potentially match '#{input}'" do
311
+ subject.match(input).should == GRXML::PotentialMatch.new
312
+ end
313
+ end
314
+
315
+ %w{* # 1 2 3 4 5 8 9 10 66 26 61 75 729 654}.each do |input|
316
+ it "should not match '#{input}'" do
317
+ subject.match(input).should == GRXML::NoMatch.new
318
+ end
319
+ end
320
+ end
321
+
322
+ context "with a grammar that takes two specific digits with the second being an alternative" do
323
+ let(:grammar) do
324
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
325
+ rule :id => 'digits' do
326
+ string '*'
327
+ one_of do
328
+ item { '6' }
329
+ item { '7' }
330
+ end
331
+ end
332
+ end
333
+ end
334
+
335
+ it "should maximally match '*6'" do
336
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
337
+ :confidence => 1,
338
+ :utterance => '*6',
339
+ :interpretation => 'dtmf-star dtmf-6'
340
+ subject.match('*6').should == expected_match
341
+ end
342
+
343
+ it "should maximally match '*7'" do
344
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
345
+ :confidence => 1,
346
+ :utterance => '*7',
347
+ :interpretation => 'dtmf-star dtmf-7'
348
+ subject.match('*7').should == expected_match
349
+ end
350
+
351
+ it "should potentially match '*'" do
352
+ subject.match('*').should == GRXML::PotentialMatch.new
353
+ end
354
+
355
+ %w{*8 #6 6* 1 2 3 4 5 6 7 8 9 10 66 26 61}.each do |input|
356
+ it "should not match '#{input}'" do
357
+ subject.match(input).should == GRXML::NoMatch.new
358
+ end
359
+ end
360
+ end
361
+
362
+ context "with a grammar that takes two specific digits with the first being an alternative" do
363
+ let(:grammar) do
364
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
365
+ rule :id => 'digits' do
366
+ one_of do
367
+ item { '6' }
368
+ item { '7' }
369
+ end
370
+ string '*'
371
+ end
372
+ end
373
+ end
374
+
375
+ it "should maximally match '6*'" do
376
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
377
+ :confidence => 1,
378
+ :utterance => '6*',
379
+ :interpretation => 'dtmf-6 dtmf-star'
380
+ subject.match('6*').should == expected_match
381
+ end
382
+
383
+ it "should maximally match '7*'" do
384
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
385
+ :confidence => 1,
386
+ :utterance => '7*',
387
+ :interpretation => 'dtmf-7 dtmf-star'
388
+ subject.match('7*').should == expected_match
389
+ end
390
+
391
+ %w{6 7}.each do |input|
392
+ it "should potentially match '#{input}'" do
393
+ subject.match(input).should == GRXML::PotentialMatch.new
394
+ end
395
+ end
396
+
397
+ it "should potentially match '7'" do
398
+ subject.match('7').should == GRXML::PotentialMatch.new
399
+ end
400
+
401
+ %w{8* 6# *6 *7 1 2 3 4 5 8 9 10 66 26 61}.each do |input|
402
+ it "should not match '#{input}'" do
403
+ subject.match(input).should == GRXML::NoMatch.new
404
+ end
405
+ end
406
+ end
407
+
408
+ context "with a grammar that takes a specific digit, followed by a specific digit repeated an exact number of times" do
409
+ let(:grammar) do
410
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
411
+ rule :id => 'digits' do
412
+ string '1'
413
+ item :repeat => 2 do
414
+ '6'
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ it "should maximally match '166'" do
421
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
422
+ :confidence => 1,
423
+ :utterance => '166',
424
+ :interpretation => 'dtmf-1 dtmf-6 dtmf-6'
425
+ subject.match('166').should == expected_match
426
+ end
427
+
428
+ %w{1 16}.each do |input|
429
+ it "should potentially match '#{input}'" do
430
+ subject.match(input).should == GRXML::PotentialMatch.new
431
+ end
432
+ end
433
+
434
+ %w{1666 16666 17}.each do |input|
435
+ it "should not match '#{input}'" do
436
+ subject.match(input).should == GRXML::NoMatch.new
437
+ end
438
+ end
439
+ end
440
+
441
+ context "with a grammar that takes a specific digit repeated an exact number of times, followed by a specific digit" do
442
+ let(:grammar) do
443
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
444
+ rule :id => 'digits' do
445
+ item :repeat => 2 do
446
+ '6'
447
+ end
448
+ string '1'
449
+ end
450
+ end
451
+ end
452
+
453
+ it "should maximally match '661'" do
454
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
455
+ :confidence => 1,
456
+ :utterance => '661',
457
+ :interpretation => 'dtmf-6 dtmf-6 dtmf-1'
458
+ subject.match('661').should == expected_match
459
+ end
460
+
461
+ %w{6 66}.each do |input|
462
+ it "should potentially match '#{input}'" do
463
+ subject.match(input).should == GRXML::PotentialMatch.new
464
+ end
465
+ end
466
+
467
+ %w{61 6661 66661 71 771}.each do |input|
468
+ it "should not match '#{input}'" do
469
+ subject.match(input).should == GRXML::NoMatch.new
470
+ end
471
+ end
472
+ end
473
+
474
+ context "with a grammar that takes a specific digit, followed by a specific digit repeated within a range" do
475
+ let(:grammar) do
476
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
477
+ rule :id => 'digits' do
478
+ string '1'
479
+ item :repeat => 0..3 do
480
+ '6'
481
+ end
482
+ end
483
+ end
484
+ end
485
+
486
+ it "should maximally match '1666'" do
487
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
488
+ :confidence => 1,
489
+ :utterance => '1666',
490
+ :interpretation => 'dtmf-1 dtmf-6 dtmf-6 dtmf-6'
491
+ subject.match('1666').should == expected_match
492
+ end
493
+
494
+ {
495
+ '1' => 'dtmf-1',
496
+ '16' => 'dtmf-1 dtmf-6',
497
+ '166' => 'dtmf-1 dtmf-6 dtmf-6',
498
+ }.each_pair do |input, interpretation|
499
+ it "should match '#{input}'" do
500
+ expected_match = GRXML::Match.new :mode => :dtmf,
501
+ :confidence => 1,
502
+ :utterance => input,
503
+ :interpretation => interpretation
504
+ subject.match(input).should == expected_match
505
+ end
506
+ end
507
+
508
+ %w{6 16666 17}.each do |input|
509
+ it "should not match '#{input}'" do
510
+ subject.match(input).should == GRXML::NoMatch.new
511
+ end
512
+ end
513
+ end
514
+
515
+ context "with a grammar that takes a a specific digit repeated within a range, followed by specific digit" do
516
+ let(:grammar) do
517
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
518
+ rule :id => 'digits' do
519
+ item :repeat => 0..3 do
520
+ '6'
521
+ end
522
+ string '1'
523
+ end
524
+ end
525
+ end
526
+
527
+ {
528
+ '1' => 'dtmf-1',
529
+ '61' => 'dtmf-6 dtmf-1',
530
+ '661' => 'dtmf-6 dtmf-6 dtmf-1',
531
+ '6661' => 'dtmf-6 dtmf-6 dtmf-6 dtmf-1'
532
+ }.each_pair do |input, interpretation|
533
+ it "should maximally match '#{input}'" do
534
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
535
+ :confidence => 1,
536
+ :utterance => input,
537
+ :interpretation => interpretation
538
+ subject.match(input).should == expected_match
539
+ end
540
+ end
541
+
542
+ %w{6 66 666}.each do |input|
543
+ it "should potentially match '#{input}'" do
544
+ subject.match(input).should == GRXML::PotentialMatch.new
545
+ end
546
+ end
547
+
548
+ %w{66661 71}.each do |input|
549
+ it "should not match '#{input}'" do
550
+ subject.match(input).should == GRXML::NoMatch.new
551
+ end
552
+ end
553
+ end
554
+
555
+ context "with a grammar that takes a specific digit, followed by a specific digit repeated a minimum number of times" do
556
+ let(:grammar) do
557
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
558
+ rule :id => 'digits' do
559
+ string '1'
560
+ item :repeat => '2-' do
561
+ '6'
562
+ end
563
+ end
564
+ end
565
+ end
566
+
567
+ {
568
+ '166' => 'dtmf-1 dtmf-6 dtmf-6',
569
+ '1666' => 'dtmf-1 dtmf-6 dtmf-6 dtmf-6',
570
+ '16666' => 'dtmf-1 dtmf-6 dtmf-6 dtmf-6 dtmf-6'
571
+ }.each_pair do |input, interpretation|
572
+ it "should match '#{input}'" do
573
+ expected_match = GRXML::Match.new :mode => :dtmf,
574
+ :confidence => 1,
575
+ :utterance => input,
576
+ :interpretation => interpretation
577
+ subject.match(input).should == expected_match
578
+ end
579
+ end
580
+
581
+ %w{1 16}.each do |input|
582
+ it "should potentially match '#{input}'" do
583
+ subject.match(input).should == GRXML::PotentialMatch.new
584
+ end
585
+ end
586
+
587
+ %w{7 17}.each do |input|
588
+ it "should not match '#{input}'" do
589
+ subject.match(input).should == GRXML::NoMatch.new
590
+ end
591
+ end
592
+ end
593
+
594
+ context "with a grammar that takes a specific digit repeated a minimum number of times, followed by a specific digit" do
595
+ let(:grammar) do
596
+ GRXML.draw :mode => :dtmf, :root => 'digits' do
597
+ rule :id => 'digits' do
598
+ item :repeat => '2-' do
599
+ '6'
600
+ end
601
+ string '1'
602
+ end
603
+ end
604
+ end
605
+
606
+ {
607
+ '661' => 'dtmf-6 dtmf-6 dtmf-1',
608
+ '6661' => 'dtmf-6 dtmf-6 dtmf-6 dtmf-1',
609
+ '66661' => 'dtmf-6 dtmf-6 dtmf-6 dtmf-6 dtmf-1'
610
+ }.each_pair do |input, interpretation|
611
+ it "should maximally match '#{input}'" do
612
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
613
+ :confidence => 1,
614
+ :utterance => input,
615
+ :interpretation => interpretation
616
+ subject.match(input).should == expected_match
617
+ end
618
+ end
619
+
620
+ %w{6 66}.each do |input|
621
+ it "should potentially match '#{input}'" do
622
+ subject.match(input).should == GRXML::PotentialMatch.new
623
+ end
624
+ end
625
+
626
+ %w{7 71 61}.each do |input|
627
+ it "should not match '#{input}'" do
628
+ subject.match(input).should == GRXML::NoMatch.new
629
+ end
630
+ end
631
+ end
632
+
633
+ context "with a grammar that takes a 4 digit pin terminated by hash, or the *9 escape sequence" do
634
+ let(:grammar) do
635
+ RubySpeech::GRXML.draw :mode => :dtmf, :root => 'pin' do
636
+ rule :id => 'digit' do
637
+ one_of do
638
+ ('0'..'9').map { |d| item { d } }
639
+ end
640
+ end
641
+
642
+ rule :id => 'pin', :scope => 'public' do
643
+ one_of do
644
+ item do
645
+ item :repeat => '4' do
646
+ ruleref :uri => '#digit'
647
+ end
648
+ "#"
649
+ end
650
+ item do
651
+ "\* 9"
652
+ end
653
+ end
654
+ end
655
+ end
656
+ end
657
+
658
+ {
659
+ '*9' => 'dtmf-star dtmf-9',
660
+ '1234#' => 'dtmf-1 dtmf-2 dtmf-3 dtmf-4 dtmf-pound',
661
+ '5678#' => 'dtmf-5 dtmf-6 dtmf-7 dtmf-8 dtmf-pound',
662
+ '1111#' => 'dtmf-1 dtmf-1 dtmf-1 dtmf-1 dtmf-pound'
663
+ }.each_pair do |input, interpretation|
664
+ it "should maximally match '#{input}'" do
665
+ expected_match = GRXML::MaxMatch.new :mode => :dtmf,
666
+ :confidence => 1,
667
+ :utterance => input,
668
+ :interpretation => interpretation
669
+ subject.match(input).should == expected_match
670
+ end
671
+ end
672
+
673
+ %w{* 1 12 123 1234}.each do |input|
674
+ it "should potentially match '#{input}'" do
675
+ subject.match(input).should == GRXML::PotentialMatch.new
676
+ end
677
+ end
678
+
679
+ %w{11111 #1111 *7}.each do |input|
680
+ it "should not match '#{input}'" do
681
+ subject.match(input).should == GRXML::NoMatch.new
682
+ end
683
+ end
684
+ end
685
+ end
686
+ end # Grammar
687
+ end # GRXML
688
+ end # RubySpeech