Class: RubySpeech::NLSML::Document
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- RubySpeech::NLSML::Document
- Defined in:
- lib/ruby_speech/nlsml/document.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #best_interpretation ⇒ Object
- #grammar ⇒ Object
-
#initialize(xml) ⇒ Document
constructor
A new instance of Document.
- #interpretations ⇒ Object
- #match? ⇒ Boolean
- #noinput? ⇒ Boolean
- #to_xml ⇒ Object
Constructor Details
#initialize(xml) ⇒ Document
Returns a new instance of Document.
6 7 8 9 10 11 12 13 |
# File 'lib/ruby_speech/nlsml/document.rb', line 6 def initialize(xml) 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 result end |
Instance Method Details
#==(other) ⇒ Object
33 34 35 |
# File 'lib/ruby_speech/nlsml/document.rb', line 33 def ==(other) to_xml == other.to_xml end |
#best_interpretation ⇒ Object
25 26 27 |
# File 'lib/ruby_speech/nlsml/document.rb', line 25 def best_interpretation interpretation_hash_for_interpretation interpretation_nodes.first end |
#grammar ⇒ Object
15 16 17 |
# File 'lib/ruby_speech/nlsml/document.rb', line 15 def grammar self['grammar'] end |
#interpretations ⇒ Object
19 20 21 22 23 |
# File 'lib/ruby_speech/nlsml/document.rb', line 19 def interpretations interpretation_nodes.map do |interpretation| interpretation_hash_for_interpretation interpretation end end |
#match? ⇒ Boolean
29 30 31 |
# File 'lib/ruby_speech/nlsml/document.rb', line 29 def match? interpretation_nodes.count > 0 && !nomatch? && !noinput? end |
#noinput? ⇒ Boolean
37 38 39 |
# File 'lib/ruby_speech/nlsml/document.rb', line 37 def noinput? noinput_elements.any? end |
#to_xml ⇒ Object
41 42 43 |
# File 'lib/ruby_speech/nlsml/document.rb', line 41 def to_xml document.to_xml end |