Skip to content

Commit

Permalink
[BUGFIX] Currency grammar should match without decimals after a timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Sep 27, 2013
1 parent 70b8530 commit 7d8af86
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ext/ruby_speech/ruby_speech.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int is_match_end(pcre *compiled_regex, const char *input)
search_input[input_size] = *search++;
result = pcre_exec(compiled_regex, NULL, search_input, input_size + 1, 0, 0,
ovector, sizeof(ovector) / sizeof(ovector[0]));
if (result > 0) return 0;
if (result > -1) return 0;

This comment has been minimized.

Copy link
@benlangfeld

benlangfeld Sep 27, 2013

Author Member

@crienzo Does this look right to you?

}
return 1;
}
Expand Down
10 changes: 6 additions & 4 deletions lib/ruby_speech/grxml/builtins.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RubySpeech::GRXML::Builtins
#
# Create a grammar for interpreting a monetary value. Uses '*' as the decimal point.
# Matches any number of digits, followed by a '*' and exactly two more digits.
# Matches any number of digits, optionally followed by a '*' and up to two more digits.
#
# @return [RubySpeech::GRXML::Grammar] a grammar for interpreting a monetary value.
#
Expand All @@ -11,9 +11,11 @@ def self.currency
item repeat: '0-' do
ruleref uri: '#digit'
end
item { '*' }
item repeat: '2' do
ruleref uri: '#digit'
item repeat: '0-1' do
item { '*' }
item repeat: '0-2' do
ruleref uri: '#digit'
end
end
end

Expand Down
23 changes: 17 additions & 6 deletions spec/ruby_speech/grxml/builtins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
let(:grammar) { subject.currency }

{
"1*00" => "dtmf-1 dtmf-star dtmf-0 dtmf-0",
"01*00" => "dtmf-0 dtmf-1 dtmf-star dtmf-0 dtmf-0",
"100000000000*00" => "dtmf-1 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-star dtmf-0 dtmf-0",
'1*01' => 'dtmf-1 dtmf-star dtmf-0 dtmf-1',
'01*00' => 'dtmf-0 dtmf-1 dtmf-star dtmf-0 dtmf-0',
'100000000000*00' => 'dtmf-1 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-0 dtmf-star dtmf-0 dtmf-0',
'0*08' => 'dtmf-0 dtmf-star dtmf-0 dtmf-8',
'*59' => 'dtmf-star dtmf-5 dtmf-9',
}.each do |input, interpretation|
it "should max-match '#{input}'" do
matcher.match(input).should == RubySpeech::GRXML::MaxMatch.new(confidence: 1,
Expand All @@ -19,9 +21,18 @@
end
end

%w{1 111 1*0}.each do |input|
it "should potentially match '#{input}'" do
matcher.match(input).should == RubySpeech::GRXML::PotentialMatch.new
{
'0' => 'dtmf-0',
'0*0' => 'dtmf-0 dtmf-star dtmf-0',
'10*5' => 'dtmf-1 dtmf-0 dtmf-star dtmf-5',
'123' => 'dtmf-1 dtmf-2 dtmf-3',
'123*' => 'dtmf-1 dtmf-2 dtmf-3 dtmf-star',
}.each do |input, interpretation|
it "should match '#{input}'" do
matcher.match(input).should == RubySpeech::GRXML::Match.new(confidence: 1,
interpretation: interpretation,
mode: :dtmf,
utterance: input)
end
end

Expand Down

0 comments on commit 7d8af86

Please sign in to comment.