Class: Opener::PropertyTagger

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/property_tagger.rb,
lib/opener/property_tagger/cli.rb,
lib/opener/property_tagger/server.rb,
lib/opener/property_tagger/version.rb,
lib/opener/property_tagger/processor.rb,
lib/opener/property_tagger/file_aspects_cache.rb,
lib/opener/property_tagger/remote_aspects_cache.rb

Overview

Ruby wrapper around the Python based polarity tagger.

Defined Under Namespace

Classes: CLI, FileAspectsCache, Processor, RemoteAspectsCache, Server

Constant Summary collapse

VERSION =
'3.4.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PropertyTagger

Returns a new instance of PropertyTagger.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :args (Array)

    Collection of arbitrary arguments to pass to the underlying kernel.

  • :no_time (TrueClass)

    Disables adding of timestamps.



40
41
42
43
# File 'lib/opener/property_tagger.rb', line 40

def initialize(options = {})
  @args    = options.delete(:args) || []
  @options = options
end

Instance Attribute Details

#argsArray (readonly)

Returns:

  • (Array)


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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/opener/property_tagger.rb', line 29

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

#optionsHash (readonly)

Returns:

  • (Hash)


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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/opener/property_tagger.rb', line 29

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

Instance Method Details

#pathString

Get the resource path for the lexicon files, defaults to an ENV variable

Returns:

  • (String)


50
51
52
53
54
55
56
57
58
# File 'lib/opener/property_tagger.rb', line 50

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

#remote_urlObject



60
61
62
# File 'lib/opener/property_tagger.rb', line 60

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

#run(input, params = {}) ⇒ String

Processes the input KAF document.

Parameters:

  • input (String)

Returns:

  • (String)


70
71
72
73
74
75
76
77
78
79
80
# File 'lib/opener/property_tagger.rb', line 70

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