Class: Opener::LanguageIdentifier::KafBuilder

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(text, language) ⇒ 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

#languageString (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_textString (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

#xmlBuilder::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

#buildObject

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_sString

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

#versionString



57
58
59
# File 'lib/opener/language_identifier/kaf_builder.rb', line 57

def version
  return "2.1"
end