Sha256: 1036413f001977f65725a33e2e7e3467c2c3e5776e630ad4633ee8c5167da1f2

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

require 'open3'
require 'slop'
require 'oga'
require 'monitor'
require 'httpclient'
require 'hashie'
require 'json'
require 'active_support/all'

require 'rexml/document'
require 'rexml/formatters/pretty'

require_relative 'property_tagger/version'
require_relative 'property_tagger/cli'
require_relative 'property_tagger/remote_aspects_cache'
require_relative 'property_tagger/file_aspects_cache'
require_relative 'property_tagger/processor'

module Opener
  ##
  # Ruby wrapper around the Python based polarity tagger.
  #
  # @!attribute [r] options
  #  @return [Hash]
  #
  # @!attribute [r] args
  #  @return [Array]
  #
  class PropertyTagger
    attr_reader :options, :args

    ##
    # @param [Hash] options
    #
    # @option options [Array] :args Collection of arbitrary arguments to pass
    #  to the underlying kernel.
    #
    # @option options [TrueClass] :no_time Disables adding of timestamps.
    #
    def initialize(options = {})
      @args    = options.delete(:args) || []
      @options = options
    end

    ##
    # Get the resource path for the lexicon files, defaults to an ENV variable
    #
    # @return [String]
    #
    def path
      return @path if @path

      @path = options[:resource_path] || ENV['RESOURCE_PATH'] ||
        ENV['PROPERTY_TAGGER_LEXICONS_PATH']
      return unless @path

      @path = File.expand_path @path
    end

    def remote_url
      @remote_url ||= ENV['PROPERTY_TAGGER_LEXICONS_URL']
    end

    ##
    # Processes the input KAF document.
    #
    # @param [String] input
    # @return [String]
    #
    def run input, params = {}
      timestamp = !options[:no_time]

      Processor.new(input,
        params:    params,
        url:       remote_url,
        path:      path,
        timestamp: timestamp,
        pretty:    options[:pretty],
      ).process
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opener-property-tagger-3.3.3 lib/opener/property_tagger.rb
opener-property-tagger-3.3.2 lib/opener/property_tagger.rb
opener-property-tagger-3.3.1 lib/opener/property_tagger.rb