<commit_before># coding: utf-8
require 'set'
module I18n::Tasks::PluralKeys
  PLURAL_KEY_SUFFIXES = Set.new %w(zero one two few many other)
  PLURAL_KEY_RE = /\.(?:#{PLURAL_KEY_SUFFIXES.to_a * '|'})$/

  def collapse_plural_nodes!(tree)
    tree.leaves.map(&:parent).uniq.each do |node|
      children = node.children
      if children.present? && children.all? { |c| PLURAL_KEY_SUFFIXES.include?(c.key) }
        node.value    = children.to_hash
        node.data.merge!(children.first.data)
        node.children = nil
      end
    end
    tree
  end

  # @param [String] key i18n key
  # @param [String] locale to pull key data from
  # @return the base form if the key is a specific plural form (e.g. apple for apple.many), and the key as passed otherwise
  def depluralize_key(key, locale = base_locale)
    return key if key !~ PLURAL_KEY_RE
    parent_key = split_key(key)[0..-2] * '.'
    nodes = tree("#{locale}.#{parent_key}").presence || (locale != base_locale && tree("#{base_locale}.#{parent_key}"))
    if nodes && nodes.all? { |x| x.leaf? && ".#{x.key}" =~ PLURAL_KEY_RE }
      parent_key
    else
      key
    end
  end
end<commit_msg>Fix a possible nil exception in plural_keys.rb<commit_after># coding: utf-8
require 'set'
module I18n::Tasks::PluralKeys
  PLURAL_KEY_SUFFIXES = Set.new %w(zero one two few many other)
  PLURAL_KEY_RE = /\.(?:#{PLURAL_KEY_SUFFIXES.to_a * '|'})$/

  def collapse_plural_nodes!(tree)
    tree.leaves.map(&:parent).uniq.each do |node|
      children = node.nil? ? nil : node.children
      if children.present? && children.all? { |c| PLURAL_KEY_SUFFIXES.include?(c.key) }
        node.value    = children.to_hash
        node.data.merge!(children.first.data)
        node.children = nil
      end
    end
    tree
  end

  # @param [String] key i18n key
  # @param [String] locale to pull key data from
  # @return the base form if the key is a specific plural form (e.g. apple for apple.many), and the key as passed otherwise
  def depluralize_key(key, locale = base_locale)
    return key if key !~ PLURAL_KEY_RE
    parent_key = split_key(key)[0..-2] * '.'
    nodes = tree("#{locale}.#{parent_key}").presence || (locale != base_locale && tree("#{base_locale}.#{parent_key}"))
    if nodes && nodes.all? { |x| x.leaf? && ".#{x.key}" =~ PLURAL_KEY_RE }
      parent_key
    else
      key
    end
  end
end
{'fraction_non_alphanumeric': 0.14116150911403136, 'fraction_numerical': 0.005934718100890208, 'mean_word_length': 3.1476274165202107, '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': '7222581', 'n_tokens_mistral': 852, 'n_tokens_neox': 837, 'n_words': 211}