Permalink
Browse files

NLSML documents should have a namespace

  • Loading branch information...
benlangfeld committed Oct 12, 2012
1 parent 316551b commit 14f5e9a441a93c13c5d6c09669a27d1e2d74b121
View
@@ -2,6 +2,8 @@ module RubySpeech
module NLSML
extend ActiveSupport::Autoload
+ NLSML_NAMESPACE = 'http://www.w3c.org/2000/11/nlsml'
+
eager_autoload do
autoload :Builder
autoload :Document
@@ -4,8 +4,9 @@ class Builder
attr_reader :document
def initialize(options = {}, &block)
+ options = {"xmlns" => 'http://www.w3c.org/2000/11/nlsml', "xmlns:xf" => "http://www.w3.org/2000/xforms"}.merge(options)
@document = Nokogiri::XML::Builder.new do |builder|
- builder.result options.merge("xmlns:xf" => "http://www.w3.org/2000/xforms") do |r|
+ builder.result options do |r|
apply_block r, &block
end
end.doc
@@ -33,7 +33,7 @@ def ==(other)
private
def input_hash_for_interpretation(interpretation)
- input_element = interpretation.at_xpath 'input'
+ input_element = interpretation.at_xpath 'ns:input', 'ns' => NLSML_NAMESPACE
{ content: input_element.content }.tap do |h|
h[:mode] = input_element['mode'].to_sym if input_element['mode']
end
@@ -76,7 +76,7 @@ def result
end
def interpretation_nodes
- result.xpath('interpretation').sort_by { |int| -int[:confidence].to_i }
+ result.xpath('ns:interpretation', 'ns' => NLSML_NAMESPACE).sort_by { |int| -int[:confidence].to_i }
end
end
end
@@ -3,7 +3,7 @@
describe RubySpeech::NLSML do
let :example_document do
'''
-<result xmlns:myApp="foo" xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
+<result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:xf="http://www.w3.org/2000/xforms" xmlns:myApp="foo" grammar="http://flight">
<interpretation confidence="60">
<input mode="speech">I want to go to Pittsburgh</input>
<xf:model>
@@ -83,7 +83,7 @@
RubySpeech.parse example_document
end
- let(:empty_result) { '<result xmlns:xf="http://www.w3.org/2000/xforms"/>' }
+ let(:empty_result) { '<result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:xf="http://www.w3.org/2000/xforms"/>' }
its(:grammar) { should == 'http://flight' }
@@ -122,7 +122,7 @@
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">
+<result xmlns="http://www.w3c.org/2000/11/nlsml" 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>
@@ -167,7 +167,7 @@
context "with interpretations out of confidence order" do
let :example_document do
'''
-<result xmlns:myApp="foo" xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
+<result xmlns="http://www.w3c.org/2000/11/nlsml" xmlns:myApp="foo" xmlns:xf="http://www.w3.org/2000/xforms" grammar="http://flight">
<interpretation confidence="40">
<input>I want to go to Stockholm</input>
<xf:model>

0 comments on commit 14f5e9a

Please sign in to comment.