Class: Opener::TreeTagger

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/tree_tagger.rb,
lib/opener/tree_tagger/cli.rb,
lib/opener/tree_tagger/server.rb,
lib/opener/tree_tagger/version.rb

Defined Under Namespace

Classes: CLI, Server

Constant Summary collapse

DEFAULT_OPTIONS =

Hash containing the default options to use.

Returns:

  • (Hash)
{
  :args => []
}.freeze
VERSION =
"3.2.3"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TreeTagger

Returns a new instance of TreeTagger.

Parameters:

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

Options Hash (options):

  • :args (Array)

    Collection of arbitrary arguments to pass to the underlying kernel.



26
27
28
29
# File 'lib/opener/tree_tagger.rb', line 26

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

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/opener/tree_tagger.rb', line 9

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/opener/tree_tagger.rb', line 9

def options
  @options
end

Instance Method Details

#capture(input) ⇒ Object



43
44
45
# File 'lib/opener/tree_tagger.rb', line 43

def capture(input)
  Open3.capture3(*command.split(" "), :stdin_data=>input)
end

#commandObject



47
48
49
# File 'lib/opener/tree_tagger.rb', line 47

def command
  "#{adjust_python_path} #{prepend_tree_tagger_path} python -E -OO #{kernel} #{args.join(' ')}"
end

#run(input) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/opener/tree_tagger.rb', line 31

def run(input)
  stdout, stderr, process = capture(input)

  if process.success?
    STDERR.puts(stderr) unless stderr.empty?
  else
    abort stderr
  end

  return stdout, stderr, process
end