<commit_before>module Runivedo
  class Connection
    include Protocol

    attr_accessor :stream

    def initialize(url, args = {})
      @remote_objects = {}
      @stream = Stream.new(self)
      @stream.onmessage = method(:onmessage)
      @stream.onclose = method(:onclose)
      @stream.connect(url)
      urologin = RemoteObject.new(connection: self, id: 0)
      @session_remote = urologin.call_rom('getSession', args)
    end

    def get_perspective(name)
      @session_remote.call_rom('getPerspective', name)
    end

    def close
      @stream.close
    end

    private

    def register_ro_instance(id, obj)
      @remote_objects[id] = obj
    end

    def onmessage(message)
      ro_id = message.read
      raise "ro_id invalid" unless @remote_objects.has_key?(ro_id)
      @remote_objects[ro_id].send(:receive, message)
    end

    def onclose(reason)
      @remote_objects.each do |id, ro|
        puts "closing ro #{id}"
        ro.send(:close, reason)
      end
    end<commit_msg>added set_perspective<commit_after>module Runivedo
  class Connection
    include Protocol

    attr_accessor :stream

    def initialize(url, args = {})
      @remote_objects = {}
      @stream = Stream.new(self)
      @stream.onmessage = method(:onmessage)
      @stream.onclose = method(:onclose)
      @stream.connect(url)
      urologin = RemoteObject.new(connection: self, id: 0)
      @session_remote = urologin.call_rom('getSession', args)
    end

    def get_perspective(name)
      @session_remote.call_rom('getPerspective', name)
    end

    def set_perspective(name)
      @session_remote.call_rom('setPerspective', name)
    end

    def close
      @stream.close
    end

    private

    def register_ro_instance(id, obj)
      @remote_objects[id] = obj
    end

    def onmessage(message)
      ro_id = message.read
      raise "ro_id invalid" unless @remote_objects.has_key?(ro_id)
      @remote_objects[ro_id].send(:receive, message)
    end

    def onclose(reason)
      @remote_objects.each do |id, ro|
        puts "closing ro #{id}"
        ro.send(:close, reason)
      end
    end
{'fraction_non_alphanumeric': 0.10274621212121213, 'fraction_numerical': 0.000946969696969697, 'mean_word_length': 2.766488413547237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7558180', 'n_tokens_mistral': 686, 'n_tokens_neox': 668, 'n_words': 145}