<commit_before>module Language

module English

  # = English Nouns Number Inflection.
  #
  # This module provides english singular <-> plural noun inflections.
  module Inflect

    @singular_of = {}
    @plural_of = {}

    @singular_rules = []
    @plural_rules = []

    class << self
      # Defines a general inflection exception case.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      #
      # ==== Examples
      #
      # Here we define erratum/errata exception case:
      #
      # Language::English::Inflector.word "erratum", "errata"
      #
      # In case singular and plural forms are the same omit
      # second argument on call:
      #
      # Language::English::Inflector.word 'information'
      def word(singular, plural=nil)
        plural = singular unless plural
        singular_word(singular, plural)
        plural_word(singular, plural)
      end

      def clear(type = :all)
        if type == :singular || type == :all
          @singular_of = {}
          @singular_rules = []
          @singularization_rules, @singularization_regex = nil, nil
        end
        if type == :plural || type == :all
          @singular_of = {}
          @singular_rules = []
          @singularization_rules, @singularization_regex = nil, nil
        end
      end


      # Define a singularization exception.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      def singular_word(singular, plural)
        @singular_of[plural] = singular
        @singular_of[plural.capitalize] = singular.capitalize
      end

      # Define a pluralization exception.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      def plural_word(singular, plural)
        @plural_of[singular] = plural
        @plural_of[singular.capitalize] = plural.capitalize
      end

      # Define a general rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      # whole_word<Boolean>::
      #   for capitalization, since words can be
      #   capitalized (Man => Men)      #
      # ==== Examples
      # Once the following rule is defined:
      # Language::English::Inflector.rule 'y', 'ies'
      #
      # You can see the following results:
      # irb> "fly".plural
      # => flies
      # irb> "cry".plural
      # => cries
      # Define a general rule.

      def rule(singular, plural, whole_word = false)
        singular_rule(singular, plural)
        plural_rule(singular, plural)
        word(singular, plural) if whole_word
      end

      # Define a singularization rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      #
      # ==== Examples
      # Once the following rule is defined:
      # Language::English::Inflector.singular_rule 'o', 'oes'
      #
      # You can see the following results:
      # irb> "heroes".singular
      # => hero
      def singular_rule(singular, plural)
        @singular_rules << [singular, plural]
      end

      # Define a plurualization rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      #
      # ==== Examples
      # Once the following rule is defined:
      # Language::English::Inflector.singular_rule 'fe', 'ves'
      #
      # You can see the following results:
      # irb> "wife".plural
      # => wives
      def plural_rule(singular, plural)
        @plural_rules << [singular, plural]
      end

      # Read prepared singularization rules.
      def singularization_rules
        if defined?(@singularization_regex) && @singularization_regex
          return [@singularization_regex, @singularization_hash]
        end
        # No sorting needed: Regexen match on longest string
        @singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i")
        @singularization_hash  = Hash[*@singular_rules.flatten].invert<commit_msg>Language::English::Inflect => English::Inflect name changes<commit_after>module Language

module English

  # = English Nouns Number Inflection.
  #
  # This module provides english singular <-> plural noun inflections.
  module Inflect

    @singular_of = {}
    @plural_of = {}

    @singular_rules = []
    @plural_rules = []

    class << self
      # Defines a general inflection exception case.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      #
      # ==== Examples
      #
      # Here we define erratum/errata exception case:
      #
      # English::Inflect.word "erratum", "errata"
      #
      # In case singular and plural forms are the same omit
      # second argument on call:
      #
      # English::Inflect.word 'information'
      def word(singular, plural=nil)
        plural = singular unless plural
        singular_word(singular, plural)
        plural_word(singular, plural)
      end

      def clear(type = :all)
        if type == :singular || type == :all
          @singular_of = {}
          @singular_rules = []
          @singularization_rules, @singularization_regex = nil, nil
        end
        if type == :plural || type == :all
          @singular_of = {}
          @singular_rules = []
          @singularization_rules, @singularization_regex = nil, nil
        end
      end


      # Define a singularization exception.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      def singular_word(singular, plural)
        @singular_of[plural] = singular
        @singular_of[plural.capitalize] = singular.capitalize
      end

      # Define a pluralization exception.
      #
      # ==== Parameters
      # singular<String>::
      #   singular form of the word
      # plural<String>::
      #   plural form of the word
      def plural_word(singular, plural)
        @plural_of[singular] = plural
        @plural_of[singular.capitalize] = plural.capitalize
      end

      # Define a general rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      # whole_word<Boolean>::
      #   for capitalization, since words can be
      #   capitalized (Man => Men)      #
      # ==== Examples
      # Once the following rule is defined:
      # English::Inflect.rule 'y', 'ies'
      #
      # You can see the following results:
      # irb> "fly".plural
      # => flies
      # irb> "cry".plural
      # => cries
      # Define a general rule.

      def rule(singular, plural, whole_word = false)
        singular_rule(singular, plural)
        plural_rule(singular, plural)
        word(singular, plural) if whole_word
      end

      # Define a singularization rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      #
      # ==== Examples
      # Once the following rule is defined:
      # English::Inflect.singular_rule 'o', 'oes'
      #
      # You can see the following results:
      # irb> "heroes".singular
      # => hero
      def singular_rule(singular, plural)
        @singular_rules << [singular, plural]
      end

      # Define a plurualization rule.
      #
      # ==== Parameters
      # singular<String>::
      #   ending of the word in singular form
      # plural<String>::
      #   ending of the word in plural form
      #
      # ==== Examples
      # Once the following rule is defined:
      # English::Inflect.singular_rule 'fe', 'ves'
      #
      # You can see the following results:
      # irb> "wife".plural
      # => wives
      def plural_rule(singular, plural)
        @plural_rules << [singular, plural]
      end

      # Read prepared singularization rules.
      def singularization_rules
        if defined?(@singularization_regex) && @singularization_regex
          return [@singularization_regex, @singularization_hash]
        end
        # No sorting needed: Regexen match on longest string
        @singularization_regex = Regexp.new("(" + @singular_rules.map {|s,p| p}.join("|") + ")$", "i")
        @singularization_hash  = Hash[*@singular_rules.flatten].invert
{'fraction_non_alphanumeric': 0.10463546354635464, 'fraction_numerical': 0.0, 'mean_word_length': 2.1047851903597623, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 50, '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': '5699992', 'n_tokens_mistral': 2571, 'n_tokens_neox': 2449, 'n_words': 708}