class Opener::LanguageIdentifier::KafBuilder

Class for building basic KAF documents that contain the correct language tag and the raw input that was anaylzed.

@!attribute [r] xml

@return [Builder::XmlMarkup]

@!attribute [r] original_text

@return [String]

@!attribute [r] language

@return [String]

Attributes

language[R]
original_text[R]
xml[R]

Public Class Methods

new(text, language) click to toggle source

@param [String] text The input text that was analyzed. @param [String] language The language of the text.

# 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

Public Instance Methods

build() click to toggle source

Builds the KAF document.

# 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() click to toggle source

Returns the XML document as a String.

@return [String]

# File lib/opener/language_identifier/kaf_builder.rb, line 50
def to_s
  return xml.target!
end
version() click to toggle source

@return [String]

# File lib/opener/language_identifier/kaf_builder.rb, line 57
def version
  return "2.1"
end