Skip to content

Commit

Permalink
Merge branch 'release/2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
benlangfeld committed Jun 5, 2013
2 parents c3ddb94 + bdfbf49 commit 5f291a2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
# [develop](https://github.com/benlangfeld/ruby_speech)

# [2.1.2](https://github.com/benlangfeld/ruby_speech/compare/v2.1.1...v2.1.2) - [2013-06-05](https://rubygems.org/gems/ruby_speech/versions/2.1.2)
* Bugfix: Allow wrapping a pre-parsed XML node nested arbitrary deeply as an NLSML document

# [2.1.1](https://github.com/benlangfeld/ruby_speech/compare/v2.1.0...v2.1.1) - [2013-05-09](https://rubygems.org/gems/ruby_speech/versions/2.1.1)
* Bugfix: Support numeric SISR literal tags

Expand Down
23 changes: 10 additions & 13 deletions lib/ruby_speech/nlsml/document.rb
Expand Up @@ -4,15 +4,16 @@ module RubySpeech
module NLSML
class Document < SimpleDelegator
def initialize(xml)
unless xml.root.namespace
xml.root.default_namespace = NLSML_NAMESPACE
xml = Nokogiri::XML.parse xml.to_xml, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS
result = xml.respond_to?(:root) ? xml.root : xml
unless result.namespace
result.default_namespace = NLSML_NAMESPACE
result = Nokogiri::XML.parse(xml.to_xml, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).root
end
super
super result
end

def grammar
result['grammar']
self['grammar']
end

def interpretations
Expand Down Expand Up @@ -44,15 +45,15 @@ def nomatch?
end

def nomatch_elements
result.xpath 'ns:interpretation/ns:input/ns:nomatch', 'ns' => NLSML_NAMESPACE
xpath 'ns:interpretation/ns:input/ns:nomatch', 'ns' => NLSML_NAMESPACE
end

def noinput_elements
result.xpath 'ns:interpretation/ns:input/ns:noinput', 'ns' => NLSML_NAMESPACE
xpath 'ns:interpretation/ns:input/ns:noinput', 'ns' => NLSML_NAMESPACE
end

def input_elements
result.xpath 'ns:interpretation/ns:input', 'ns' => NLSML_NAMESPACE
xpath 'ns:interpretation/ns:input', 'ns' => NLSML_NAMESPACE
end

def input_hash_for_interpretation(interpretation)
Expand Down Expand Up @@ -107,12 +108,8 @@ def interpretation_hash_for_interpretation(interpretation)
}
end

def result
root
end

def interpretation_nodes
nodes = result.xpath 'ns:interpretation', 'ns' => NLSML_NAMESPACE
nodes = xpath 'ns:interpretation', 'ns' => NLSML_NAMESPACE
nodes.sort_by { |int| -int[:confidence].to_f }
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_speech/version.rb
@@ -1,3 +1,3 @@
module RubySpeech
VERSION = "2.1.1"
VERSION = "2.1.2"
end
35 changes: 35 additions & 0 deletions spec/ruby_speech/nlsml_spec.rb
Expand Up @@ -124,6 +124,41 @@
subject.should_not be == RubySpeech.parse(empty_result)
end

context "when the XML is already parsed and is not the root of a document" do
let :example_document do
'''
<foo>
<result xmlns="http://www.ietf.org/xml/ns/mrcpv2" grammar="http://flight">
<interpretation confidence="0.6">
<input mode="speech">I want to go to Pittsburgh</input>
<instance>
<airline>
<to_city>Pittsburgh</to_city>
</airline>
</instance>
</interpretation>
<interpretation confidence="0.4">
<input>I want to go to Stockholm</input>
<instance>
<airline>
<to_city>Stockholm</to_city>
</airline>
</instance>
</interpretation>
</result>
</foo>
'''
end

let(:node) { Nokogiri::XML(example_document).at_xpath('//mrcp:result', mrcp: "http://www.ietf.org/xml/ns/mrcpv2") }

subject do
RubySpeech::NLSML::Document.new node
end

its(:grammar) { should == 'http://flight' }
end

context "with an interpretation that has no instance" do
let :example_document do
'''
Expand Down

0 comments on commit 5f291a2

Please sign in to comment.