Sha256: 8ba0845995a36eec5646ea485ad62739ae57aaeb3ff5c05c27ade513a36bea8f

Contents?: true

Size: 1.38 KB

Versions: 23

Compression:

Stored size: 1.38 KB

Contents

module Opener
  class LanguageIdentifier
    ##
    # 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]
    #
    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 # KafBuilder
  end # LanguageIdentifier
end # Opener

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opener-language-identifier-4.4.3 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.4.1 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.4.0 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.3.2 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.3.1 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.3.0 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.2.2 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.2.1 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.2.0 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-4.1.0 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.7 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.6 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.5 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.4 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.3 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.2 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.1 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.1.0 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.0.4 lib/opener/language_identifier/kaf_builder.rb
opener-language-identifier-3.0.3 lib/opener/language_identifier/kaf_builder.rb