Class: Opener::LanguageIdentifier::KafBuilder
- Inherits:
-
Object
- Object
- Opener::LanguageIdentifier::KafBuilder
- Defined in:
- lib/opener/language_identifier/kaf_builder.rb
Overview
Class for building basic KAF documents that contain the correct language tag and the raw input that was anaylzed.
Instance Attribute Summary collapse
- #language ⇒ String readonly
- #original_text ⇒ String readonly
- #xml ⇒ Builder::XmlMarkup readonly
Instance Method Summary collapse
-
#build ⇒ Object
Builds the KAF document.
-
#initialize(text, language) ⇒ KafBuilder
constructor
A new instance of KafBuilder.
-
#to_s ⇒ String
Returns the XML document as a String.
- #version ⇒ String
Constructor Details
#initialize(text, language) ⇒ KafBuilder
Returns a new instance of KafBuilder.
23 24 25 26 27 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 23 def initialize(text, language) @xml = Builder::XmlMarkup.new(:indent => 2) @language = language.strip @original_text = text end |
Instance Attribute Details
#language ⇒ String (readonly)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 16 class KafBuilder attr_reader :xml, :original_text, :language ## # @param [String] text The input text that was analyzed. # @param [String] language The language of the text. # def initialize(text, language) @xml = Builder::XmlMarkup.new(:indent => 2) @language = language.strip @original_text = text end ## # Builds the KAF document. # def build xml.instruct!( :xml, :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes' ) xml.KAF('xml:lang' => language, 'version' => version) do |node| node.raw(original_text) end end ## # Returns the XML document as a String. # # @return [String] # def to_s return xml.target! end ## # @return [String] # def version return "2.1" end end |
#original_text ⇒ String (readonly)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 16 class KafBuilder attr_reader :xml, :original_text, :language ## # @param [String] text The input text that was analyzed. # @param [String] language The language of the text. # def initialize(text, language) @xml = Builder::XmlMarkup.new(:indent => 2) @language = language.strip @original_text = text end ## # Builds the KAF document. # def build xml.instruct!( :xml, :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes' ) xml.KAF('xml:lang' => language, 'version' => version) do |node| node.raw(original_text) end end ## # Returns the XML document as a String. # # @return [String] # def to_s return xml.target! end ## # @return [String] # def version return "2.1" end end |
#xml ⇒ Builder::XmlMarkup (readonly)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 16 class KafBuilder attr_reader :xml, :original_text, :language ## # @param [String] text The input text that was analyzed. # @param [String] language The language of the text. # def initialize(text, language) @xml = Builder::XmlMarkup.new(:indent => 2) @language = language.strip @original_text = text end ## # Builds the KAF document. # def build xml.instruct!( :xml, :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes' ) xml.KAF('xml:lang' => language, 'version' => version) do |node| node.raw(original_text) end end ## # Returns the XML document as a String. # # @return [String] # def to_s return xml.target! end ## # @return [String] # def version return "2.1" end end |
Instance Method Details
#build ⇒ Object
Builds the KAF document.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 32 def build xml.instruct!( :xml, :version => '1.0', :encoding => 'UTF-8', :standalone => 'yes' ) xml.KAF('xml:lang' => language, 'version' => version) do |node| node.raw(original_text) end end |
#to_s ⇒ String
Returns the XML document as a String.
50 51 52 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 50 def to_s return xml.target! end |
#version ⇒ String
57 58 59 |
# File 'lib/opener/language_identifier/kaf_builder.rb', line 57 def version return "2.1" end |