Permalink
Browse files

Cope with parsing NLSML documents with no namespaces

Many ASR vendors think this is acceptable. I'm too tired to educate them.
  • Loading branch information...
1 parent 2392871 commit 1fbd7cfd46122d38a8d80cd7918fe55ac2fd9a25 @benlangfeld benlangfeld committed Nov 22, 2012
Showing with 43 additions and 1 deletion.
  1. +5 −1 lib/ruby_speech/nlsml/document.rb
  2. +38 −0 spec/ruby_speech/nlsml_spec.rb
@@ -34,13 +34,15 @@ def ==(other)
def input_hash_for_interpretation(interpretation)
input_element = interpretation.at_xpath 'ns:input', 'ns' => NLSML_NAMESPACE
+ input_element ||= interpretation.at_xpath 'input'
{ content: input_element.content }.tap do |h|
h[:mode] = input_element['mode'].to_sym if input_element['mode']
end
end
def instance_hash_for_interpretation(interpretation)
instance_element = interpretation.at_xpath 'xf:instance', 'xf' => XFORMS_NAMESPACE
+ instance_element ||= interpretation.at_xpath 'instance'
return unless instance_element
element_children_key_value instance_element
end
@@ -76,7 +78,9 @@ def result
end
def interpretation_nodes
- result.xpath('ns:interpretation', 'ns' => NLSML_NAMESPACE).sort_by { |int| -int[:confidence].to_i }
+ nodes = result.xpath 'ns:interpretation', 'ns' => NLSML_NAMESPACE
+ nodes += result.xpath 'interpretation'
+ nodes.sort_by { |int| -int[:confidence].to_i }
end
end
end
@@ -201,5 +201,43 @@
its(:interpretations) { should == expected_interpretations }
its(:best_interpretation) { should == expected_best_interpretation }
end
+
+ context "with no namespaces (because some vendors think this is ok" do
+ let :example_document do
+ '''
+<result grammar="http://flight">
+ <interpretation confidence="60">
+ <input mode="speech">I want to go to Pittsburgh</input>
+ <model>
+ <group name="airline">
+ <string name="to_city"/>
+ </group>
+ </model>
+ <instance>
+ <airline>
+ <to_city>Pittsburgh</to_city>
+ </airline>
+ </instance>
+ </interpretation>
+ <interpretation confidence="40">
+ <input>I want to go to Stockholm</input>
+ <model>
+ <group name="airline">
+ <string name="to_city"/>
+ </group>
+ </model>
+ <instance>
+ <airline>
+ <to_city>Stockholm</to_city>
+ </airline>
+ </instance>
+ </interpretation>
+</result>
+ '''
+ end
+
+ its(:interpretations) { should == expected_interpretations }
+ its(:best_interpretation) { should == expected_best_interpretation }
+ end
end
end

0 comments on commit 1fbd7cf

Please sign in to comment.