<commit_before># frozen_string_literal: true

class CsvUtils
  def self.detect_separator(filename)
    %w( , ; ).each do |separator|
      return separator if separator_check(filename, separator)
    end

    raise "No separator found for #{filename}"
  end

  def self.separator_check(filename, separator)
    columns_counts = CSV.read(filename, col_sep: separator).map(&:size).uniq
    columns_counts.size == 1 && columns_counts.first > 1
  end
end<commit_msg>Ignore empty cells when parsing CSV<commit_after># frozen_string_literal: true

class CsvUtils
  def self.detect_separator(filename)
    %w( , ; ).each do |separator|
      return separator if separator_check(filename, separator)
    end

    raise "No separator found for #{filename}"
  end

  def self.separator_check(filename, separator)
    # Skip the first line just in case it contains a header
    # Does a compact, to remove empty cells
    columns_counts = CSV.read(filename, col_sep: separator)[1..-1].map(&:compact).map(&:size).uniq
    columns_counts.size == 1 && columns_counts.first > 1
  end
end
{'fraction_non_alphanumeric': 0.09981343283582089, 'fraction_numerical': 0.005597014925373134, 'mean_word_length': 4.061320754716981, 'pattern_counts': {'":': 0, '<': 3, '<?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': '199832', 'n_tokens_mistral': 350, 'n_tokens_neox': 318, 'n_words': 96}