Sha256: 02718970a6b8afd114405bff1a4cf8d42babf611359cf512986b11dd1f826e7d

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

require 'open3'
require 'slop'
require 'nokogiri'

require_relative 'tree_tagger/version'
require_relative 'tree_tagger/cli'

module Opener
  class TreeTagger
    attr_reader :options, :args

    ##
    # Hash containing the default options to use.
    #
    # @return [Hash]
    #
    DEFAULT_OPTIONS = {
      :args => []
    }.freeze

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

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

      raise stderr unless process.success?

      return stdout
    end

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

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

    protected

    def core_dir
      File.expand_path("../../core", File.dirname(__FILE__))
    end

    def kernel
      File.join(core_dir,'/tt_from_kaf_to_kaf.py')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opener-tree-tagger-4.1.1 lib/opener/tree_tagger.rb
opener-tree-tagger-4.1.0 lib/opener/tree_tagger.rb