lib/opener/opinion_detectors/base.rb in opener-opinion-detector-base-2.0.1 vs lib/opener/opinion_detectors/base.rb in opener-opinion-detector-base-2.1.2

- old
+ new

@@ -5,10 +5,12 @@ require_relative 'configuration_creator' require_relative 'en' require_relative 'nl' require_relative 'de' require_relative 'it' +require_relative 'fr' +require_relative 'es' module Opener module OpinionDetectors class ModelsMissing < StandardError; end @@ -20,12 +22,12 @@ # # @!attribute [r] options # @return [Hash] # class Base - attr_reader :args, :options, :conf_file, :models_path - + attr_reader :args, :options + ## # Hash containing the default options to use. # # @return [Hash] # @@ -37,21 +39,21 @@ # @param [Hash] options # # @option options [Array] :args Extra commandline arguments to use. # def initialize(options = {}) - @args = options.delete(:args) || [] - @options = DEFAULT_OPTIONS.merge(options) + @args = options.delete(:args) || [] + @options = DEFAULT_OPTIONS.merge(options) end ## # Builds the command used to execute the kernel. # # @param [Array] args Commandline arguments passed to the command. # - def command - return "#{adjust_python_path} python -E -OO #{kernel} -m #{conf_file.path} #{args.join(' ')}" + def command(config_file) + return "#{adjust_python_path} python -OO #{kernel} -m #{config_file} #{args.join(' ')}" end ## # Runs the command and returns the output of STDOUT, STDERR and the # process information. @@ -59,33 +61,35 @@ # @param [String] input The input to tag. # @return [Array] # def run(input) language = language(input) - conf = ConfigurationCreator.new(language, options[:domain]) - @conf_file = conf.config_file_path - @models_path = conf.models_path + conf = ConfigurationCreator.new( + language, + options[:domain], + options[:resource_path] + ) - return capture(input) + return capture(conf.config_file_path, input) end protected ## # @return [String] # def adjust_python_path - site_packages = File.join(core_dir, 'site-packages') + site_packages = File.join(core_dir, 'site-packages/pre_install') return "env PYTHONPATH=#{site_packages}:$PYTHONPATH" end ## - # capture3 method doesn't work properly with Jruby, so - # this is a workaround + # capture3 method doesn't work properly with Jruby, so this is a + # workaround # - def capture(input) - return Open3.popen3(*command.split(" ")) {|i, o, e, t| + def capture(config_file, input) + return Open3.popen3(*command(config_file).split(" ")) {|i, o, e, t| out_reader = Thread.new { o.read } err_reader = Thread.new { e.read } i.write input i.close [out_reader.value, err_reader.value, t.value]