Sha256: 75d40bed19c23f6c56f3122410e785c65657c84862c525966c132880fc17975d

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

require_relative 'term'

module Opener
  module KAF
    class Document

      attr_reader :document
      attr_reader :lexicons

      attr_accessor :map

      def initialize xml
        @document = xml
      end

      def self.from_xml xml
        new Nokogiri::XML xml
      end

      def language
        @language ||= @document.at_xpath('KAF').attr 'xml:lang'
      end

      def terms
        @terms ||= collection 'KAF/terms/term', Term
      end

      def add_linguistic_processor name, version, layer, timestamp: false
        header  = @document.at('kafHeader') || @document.root.add_child('<kafHeader/>').first
        procs   = header.css('linguisticProcessors').find{ |l| l.attr(:layer) == layer }
        procs ||= header.add_child("<linguisticProcessors layer='#{layer}'/>").first
        lp      = procs.add_child('<lp/>')
        lp.attr(
          timestamp: if timestamp then Time.now.iso8601 else '*' end,
          version:   version,
          name:      name,
        )
        lp
      end

      def to_xml
        @document.to_xml indent: 2
      end

      protected

      def collection query, wrapper
        @document.xpath(query).map{ |node| wrapper.new self, node }
      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
opener-polarity-tagger-3.5.5 lib/opener/kaf/document.rb
opener-polarity-tagger-3.5.4 lib/opener/kaf/document.rb
opener-polarity-tagger-3.5.3 lib/opener/kaf/document.rb
opener-polarity-tagger-3.5.2 lib/opener/kaf/document.rb
opener-polarity-tagger-3.5.1 lib/opener/kaf/document.rb
opener-polarity-tagger-3.5.0 lib/opener/kaf/document.rb
opener-polarity-tagger-3.4.0 lib/opener/kaf/document.rb
opener-polarity-tagger-3.3.0 lib/opener/kaf/document.rb
opener-polarity-tagger-3.2.7 lib/opener/kaf/document.rb
opener-polarity-tagger-3.2.6 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.2.5 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.2.4 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.2.3 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.2.2 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.2.1 lib/opener/polarity_tagger/kaf/document.rb
opener-polarity-tagger-3.1.3 lib/opener/polarity_tagger/kaf/document.rb