<commit_before>require 'rubygems'
require 'celerity'


module Culerity
  class CelerityServer
    
    def initialize(_in, _out)
      @proxies = {}
      @browser_options = {}
      
      while(true)
        call = eval _in.gets.to_s.strip
        return  if call == ["_exit_"]
        unless call.nil?
          begin
            result = target(call.first).send call[1], *call[2..-1]
            _out << "[:return, #{proxify result}]\n"
          rescue => e
            _out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
          end
        end
      end
      
    end
    
    private
    
    def configure_browser(options)
      @browser_options = options
    end
    
    def browser
      @browser ||= Celerity::Browser.new @browser_options || {}
    end
    
    def target(object_id)
      if object_id == 'browser'
        browser
      elsif object_id == 'celerity'
        self
      else
        @proxies[object_id]
      end
    end
    
    def proxify(result)
      if [String, TrueClass, FalseClass, Fixnum, Float, NilClass].include?(result.class)<commit_msg>Making Culerity return actual Array objects rather than a RemoteProxy object.<commit_after>require 'rubygems'
require 'celerity'


module Culerity
  class CelerityServer
    
    def initialize(_in, _out)
      @proxies = {}
      @browser_options = {}
      
      while(true)
        call = eval _in.gets.to_s.strip
        return  if call == ["_exit_"]
        unless call.nil?
          begin
            result = target(call.first).send call[1], *call[2..-1]
            _out << "[:return, #{proxify result}]\n"
          rescue => e
            _out << "[:exception, \"#{e.class.name}\", #{e.message.inspect}, #{e.backtrace.inspect}]\n"
          end
        end
      end
      
    end
    
    private
    
    def configure_browser(options)
      @browser_options = options
    end
    
    def browser
      @browser ||= Celerity::Browser.new @browser_options || {}
    end
    
    def target(object_id)
      if object_id == 'browser'
        browser
      elsif object_id == 'celerity'
        self
      else
        @proxies[object_id]
      end
    end
    
    def proxify(result)
      if [String, TrueClass, FalseClass, Fixnum, Float, NilClass, Array].include?(result.class)
{'fraction_non_alphanumeric': 0.11566681053085887, 'fraction_numerical': 0.002589555459646094, 'mean_word_length': 1.9084065244667503, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5876774', 'n_tokens_mistral': 735, 'n_tokens_neox': 732, 'n_words': 166}