<commit_before>module Calyx
  module Production
    class Choices
      def self.parse(productions, registry)
        choices = productions.map do |choice|
          if choice.is_a?(String)
            Concat.parse(choice, registry)
          elsif choice.is_a?(Fixnum)
            Terminal.new(choice.to_s)
          elsif choice.is_a?(Symbol)
            if choice[0] == Memo::SIGIL
              Memo.new(choice, registry)
            else
              NonTerminal.new(choice, registry)
            end
          end
        end
        self.new(choices)
      end

      def initialize(collection)
        @collection = collection
      end

      def evaluate
        [:choice, @collection.sample.evaluate]
      end
    end
  end
end<commit_msg>Add method comments to `Production::Choices` source<commit_after>module Calyx
  module Production
    class Choices
      # Parse a list of productions and return a choice node which is the head
      # of a syntax tree of child nodes.
      #
      # @param productions [Array]
      # @param registry [Calyx::Registry]
      def self.parse(productions, registry)
        choices = productions.map do |choice|
          if choice.is_a?(String)
            Concat.parse(choice, registry)
          elsif choice.is_a?(Fixnum)
            Terminal.new(choice.to_s)
          elsif choice.is_a?(Symbol)
            if choice[0] == Memo::SIGIL
              Memo.new(choice, registry)
            else
              NonTerminal.new(choice, registry)
            end
          end
        end
        self.new(choices)
      end

      # Initialize a new choice with a list of child nodes.
      #
      # @param collection [Array]
      def initialize(collection)
        @collection = collection
      end

      # Evaluate the choice by randomly picking one of its possible options.
      #
      # @return [Array]
      def evaluate
        [:choice, @collection.sample.evaluate]
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.07660878447395301, 'fraction_numerical': 0.0010214504596527069, 'mean_word_length': 1.7945791726105564, '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': '1532524', 'n_tokens_mistral': 545, 'n_tokens_neox': 535, 'n_words': 153}