Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[FEATURE] Handle NLSML nomatch/noinput

  • Loading branch information...
commit 2c088ba6a5d853635ba2d9ecd56ed3677e328a56 1 parent 0663df9
@benlangfeld authored
View
9 README.md
@@ -348,15 +348,6 @@ Check out the [YARD documentation](http://rdoc.info/github/benlangfeld/ruby_spee
* `<example/>`
* `<lexicon/>`
-### NLSML
-* `<result/>`
-* `<interpretation/>`
-* `<model/>`
-* `<instance/>`
-* `<input/>`
-* `<nomatch/>`
-* `<noinput/>`
-
## Links:
* [Source](https://github.com/benlangfeld/ruby_speech)
* [Documentation](http://rdoc.info/gems/ruby_speech/frames)
View
22 lib/ruby_speech/nlsml/document.rb
@@ -23,15 +23,35 @@ def best_interpretation
end
def match?
- interpretation_nodes.count > 0
+ interpretation_nodes.count > 0 && !nomatch? && !noinput?
end
def ==(other)
to_xml == other.to_xml
end
+ def noinput?
+ noinput_elements.any?
+ end
+
private
+ def nomatch?
+ nomatch_elements.count >= input_elements.count
+ end
+
+ def nomatch_elements
+ result.xpath 'ns:interpretation/ns:input/ns:nomatch|interpretation/input/nomatch', 'ns' => NLSML_NAMESPACE
+ end
+
+ def noinput_elements
+ result.xpath 'ns:interpretation/ns:input/ns:noinput|interpretation/input/noinput', 'ns' => NLSML_NAMESPACE
+ end
+
+ def input_elements
+ result.xpath 'ns:interpretation/ns:input|interpretation/input', 'ns' => NLSML_NAMESPACE
+ end
+
def input_hash_for_interpretation(interpretation)
input_element = interpretation.at_xpath '(ns:input|input)', 'ns' => NLSML_NAMESPACE
{ content: input_element.content }.tap do |h|
View
62 spec/ruby_speech/nlsml_spec.rb
@@ -323,5 +323,67 @@
its(:interpretations) { should == expected_interpretations }
its(:best_interpretation) { should == expected_best_interpretation }
end
+
+ context "with a single interpretation with a nomatch input" do
+ let :example_document do
+ '''
+<result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
+ <interpretation>
+ <input>
+ <nomatch/>
+ </input>
+ </interpretation>
+</result>
+ '''
+ end
+
+ it { should_not be_match }
+ end
+
+ context "with multiple interpretations where one is a nomatch input" do
+ let :example_document do
+ '''
+<result xmlns="http://www.w3c.org/2000/11/nlsml" 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>
+ <input>
+ <nomatch/>
+ </input>
+ </interpretation>
+</result>
+ '''
+ end
+
+ it { should be_match }
+ end
+
+ context "with a single interpretation with a noinput" do
+ let :example_document do
+ '''
+<result xmlns="http://www.w3c.org/2000/11/nlsml" grammar="http://flight">
+ <interpretation>
+ <input>
+ <noinput/>
+ </input>
+ </interpretation>
+</result>
+ '''
+ end
+
+ it { should_not be_match }
+ it { should be_noinput }
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.