Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[BUGFIX] Handle parsing NLSML documents with no model/instances

  • Loading branch information...
commit 316551bb5d2370e2d515728e4d438ce0546eaa1d 1 parent 0c2c7e0
@benlangfeld authored
View
1  lib/ruby_speech/nlsml/document.rb
@@ -41,6 +41,7 @@ def input_hash_for_interpretation(interpretation)
def instance_hash_for_interpretation(interpretation)
instance_element = interpretation.at_xpath 'xf:instance'
+ return unless instance_element
element_children_key_value instance_element
end
View
37 spec/ruby_speech/nlsml_spec.rb
@@ -119,6 +119,43 @@
subject.should_not be == RubySpeech.parse(empty_result)
end
+ context "with an interpretation that has no model/instance" do
+ let :example_document do
+ '''
+<result xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
+ <interpretation confidence="60">
+ <input mode="speech">I want to go to Pittsburgh</input>
+ </interpretation>
+ <interpretation confidence="40">
+ <input>I want to go to Stockholm</input>
+ </interpretation>
+</result>
+ '''
+ end
+
+ let(:expected_best_interpretation) do
+ {
+ confidence: 0.6,
+ input: { mode: :speech, content: 'I want to go to Pittsburgh' },
+ instance: nil
+ }
+ end
+
+ let(:expected_interpretations) do
+ [
+ expected_best_interpretation,
+ {
+ confidence: 0.4,
+ input: { content: 'I want to go to Stockholm' },
+ instance: nil
+ }
+ ]
+ end
+
+ its(:interpretations) { should == expected_interpretations }
+ its(:best_interpretation) { should == expected_best_interpretation }
+ end
+
context "without any interpretations" do
subject do
RubySpeech.parse empty_result
Please sign in to comment.
Something went wrong with that request. Please try again.