<commit_before>module Hets
  class ParseCaller < Caller
    # Server-Instances should be started with the following
    # arguments: `hets +RTS -K1G -RTS -a none`
    MODE_ARGUMENTS = {
      fast_run: %w(just-structured),
      default: %w(full-signatures full-theories auto),
    }

    CMD = 'dg'
    METHOD = :get

    attr_accessor :url_catalog

    def initialize(hets_instance, url_catalog = [])
      self.url_catalog = url_catalog
      msg = "<#{hets_instance}> not up."
      raise Hets::InactiveInstanceError, msg unless hets_instance.up?
      super(hets_instance)
    end

    def call(iri, with_mode: :default)
      escaped_iri = Rack::Utils.escape_path(iri)
      arguments = [escaped_iri, *MODE_ARGUMENTS[with_mode]]
      api_uri = build_api_uri(CMD, arguments, build_query_string)
      perform(api_uri, METHOD)
    rescue UnfollowableResponseError => error
      handle_possible_hets_error(error)
    end

    def build_query_string
      query_hash = {}
      query_hash[:"url-catalog"] = url_catalog.join(',') if url_catalog.present?
      query_hash
    end

    def handle_possible_hets_error(error)
      HetsErrorProcess.new(error).handle
    rescue Hets::NotAHetsError
      raise error
    end<commit_msg>also throw HetsInactiveInstance when instance nil.<commit_after>module Hets
  class ParseCaller < Caller
    # Server-Instances should be started with the following
    # arguments: `hets +RTS -K1G -RTS -a none`
    MODE_ARGUMENTS = {
      fast_run: %w(just-structured),
      default: %w(full-signatures full-theories auto),
    }

    CMD = 'dg'
    METHOD = :get

    attr_accessor :url_catalog

    def initialize(hets_instance, url_catalog = [])
      self.url_catalog = url_catalog
      msg = "<#{hets_instance}> not up."
      raise Hets::InactiveInstanceError, msg unless hets_instance.try(:up?)
      super(hets_instance)
    end

    def call(iri, with_mode: :default)
      escaped_iri = Rack::Utils.escape_path(iri)
      arguments = [escaped_iri, *MODE_ARGUMENTS[with_mode]]
      api_uri = build_api_uri(CMD, arguments, build_query_string)
      perform(api_uri, METHOD)
    rescue UnfollowableResponseError => error
      handle_possible_hets_error(error)
    end

    def build_query_string
      query_hash = {}
      query_hash[:"url-catalog"] = url_catalog.join(',') if url_catalog.present?
      query_hash
    end

    def handle_possible_hets_error(error)
      HetsErrorProcess.new(error).handle
    rescue Hets::NotAHetsError
      raise error
    end
{'fraction_non_alphanumeric': 0.09398645957785742, 'fraction_numerical': 0.0007964954201513341, 'mean_word_length': 3.264855687606112, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5797551', 'n_tokens_mistral': 834, 'n_tokens_neox': 811, 'n_words': 174}