ruby_speech 2.0.2 → 2.1.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: de37299d09f7a9dc63c8c5944db79f80594bfffc
4
- data.tar.gz: c01558ff39e76c034f1b18df7288c27d04ec84b1
3
+ metadata.gz: 412147ee2efc1f9e8db108476c6939cc8723a68b
4
+ data.tar.gz: c73dbaad254dd7e90d1f08520a147bb9ebcbe20a
5
5
  SHA512:
6
- metadata.gz: a2dc9ae2659cc93d40f7f0d55a2d6b4344accf12f7b1d7cf130aba09c4949a868bc47e2c641183aecad8bd42b0312a50d3a14d27eb9b933664fbaaa15de60cdc
7
- data.tar.gz: 3df44bf14ab55473bd2dab097e2e972493744d299390085506e90ff437eb82441f535a3b29b1a45ac73d22c1770d0f4e4de9dbbb954d3d3c7c6983f12a741b75
6
+ metadata.gz: 4a4be1f240f91097e810e8394619c6efd9a7b4e2bf0ef817d0af65f313fcfe19d992c5e1d1ca29a06b355fd931fc8c70d4febe58221499a531c440c17b24b6eb
7
+ data.tar.gz: f734ad2b4103ed7c21a9d15e0abe7141a4ed4edcc1ba8b6c830e4fc37254fc466c1c95cd61c15dc6002437ea6a83abb2dbe95fef8ee012cb404154de0437099a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # [develop](https://github.com/benlangfeld/ruby_speech)
2
2
 
3
+ # [2.1.0](https://github.com/benlangfeld/ruby_speech/compare/v2.0.2...v2.1.0) - [2013-05-07](https://rubygems.org/gems/ruby_speech/versions/2.1.0)
4
+ * Feature: Support for SISR literal syntax
5
+
3
6
  # [2.0.2](https://github.com/benlangfeld/ruby_speech/compare/v2.0.1...v2.0.2) - [2013-05-01](https://rubygems.org/gems/ruby_speech/versions/2.0.2)
4
7
  * Bugfix: Differentiate between GRXML match cases with are and are not maximal
5
8
  * A Match can accept further input while still matching, while a a MaxMatch cannot.
@@ -22,7 +22,7 @@ module RubySpeech
22
22
  include GenericElement
23
23
 
24
24
  def regexp_content # :nodoc:
25
- children.map(&:regexp_content).join
25
+ "(#{children.map(&:regexp_content).join})"
26
26
  end
27
27
  end # Element
28
28
  end # GRXML
@@ -123,7 +123,8 @@ module RubySpeech
123
123
  traverse do |element|
124
124
  next unless element.is_a? Nokogiri::XML::Text
125
125
 
126
- next if self.class.import(element.parent).is_a? Token
126
+ element_type = self.class.import(element.parent).class
127
+ next if [Token, Tag].include?(element_type)
127
128
 
128
129
  tokens = split_tokens(element).map do |string|
129
130
  Token.new.tap { |token| token << string }
@@ -8,6 +8,10 @@ end
8
8
  module RubySpeech
9
9
  module GRXML
10
10
  class Matcher
11
+ UTTERANCE_CONVERTER = Hash.new { |hash, key| hash[key] = key }
12
+ UTTERANCE_CONVERTER['*'] = 'star'
13
+ UTTERANCE_CONVERTER['#'] = 'pound'
14
+
11
15
  attr_reader :grammar
12
16
 
13
17
  def initialize(grammar)
@@ -106,13 +110,16 @@ module RubySpeech
106
110
  end
107
111
 
108
112
  def interpret_utterance(utterance)
109
- conversion = Hash.new { |hash, key| hash[key] = key }
110
- conversion['*'] = 'star'
111
- conversion['#'] = 'pound'
113
+ find_tag(utterance) || utterance.chars.inject([]) do |array, digit|
114
+ array << "dtmf-#{UTTERANCE_CONVERTER[digit]}"
115
+ end.join(' ')
116
+ end
112
117
 
113
- utterance.chars.inject [] do |array, digit|
114
- array << "dtmf-#{conversion[digit]}"
115
- end.join ' '
118
+ def find_tag(utterance)
119
+ match = /#{regexp_content}/.match(utterance)
120
+ return if match.captures.all?(&:nil?)
121
+ last_capture_index = match.captures.size - 1 - match.captures.reverse.find_index { |item| !item.nil? }
122
+ match.names[last_capture_index]
116
123
  end
117
124
  end
118
125
  end
@@ -20,6 +20,10 @@ module RubySpeech
20
20
  raise InvalidChildError, "A Tag can only accept Strings as children" unless VALID_CHILD_TYPES.include? arg.class
21
21
  super
22
22
  end
23
+
24
+ def regexp_content # :nodoc:
25
+ "?<#{content}>"
26
+ end
23
27
  end # Tag
24
28
  end # GRXML
25
29
  end # RubySpeech
@@ -1,3 +1,3 @@
1
1
  module RubySpeech
2
- VERSION = "2.0.2"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -34,6 +34,41 @@ module RubySpeech
34
34
  end
35
35
  end
36
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
+
37
72
  context "with a grammar that takes two specific digits" do
38
73
  let(:grammar) do
39
74
  GRXML.draw :mode => :dtmf, :root => 'digits' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_speech
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Langfeld
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-01 00:00:00.000000000 Z
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceogiri