def analyze(transactions) # AnalysisResult
      frequencies = {} # {item_set: count}
      frequent_item_sets = {} # {item_set_size: FrequentItemSet[]}

      one_element_item_sets = to_one_element_item_sets(transactions) # string[][]
      one_c_item_sets = find_item_sets_min_support_satisfied(
          one_element_item_sets, transactions, min_support, frequencies) # FrequentItemSet[]

      current_l_item_sets = one_c_item_sets # FrequentItemSet[]
      item_set_size = 1
      while current_l_item_sets.length != 0
        frequent_item_sets[item_set_size] = current_l_item_sets
        joined_sets = to_fixed_size_joined_sets(current_l_item_sets.map { |_| _.item_set }, item_set_size + 1)
        current_l_item_sets = find_item_sets_min_support_satisfied(joined_sets, transactions, min_support, frequencies)
        item_set_size += 1
      end

      found_sub_sets = [] # string[][]
      association_rules = [] # AssociationRule[]
      frequent_item_sets.each do |item_set_size, item_sets|
        item_sets = item_sets.map { |_| _.item_set }
        next if item_sets.length == 0 || item_sets[0].length <= 1

        item_sets.each do |item_set|
          to_all_sub_sets(item_set).each do |subset_item_set|
            diff_item_set = ((item_set - subset_item_set) + (subset_item_set - item_set)).uniq
            if diff_item_set.length > 0
              item_support = calculate_support(item_set, frequencies, transactions)
              subset_support = calculate_support(subset_item_set, frequencies, transactions)
              confidence = item_support / subset_support
              if !is_the_rule_already_found(found_sub_sets, subset_item_set) && confidence >= min_confidence
                found_sub_sets << subset_item_set
                association_rules << Apriori::AssociationRule.new(subset_item_set, diff_item_set, confidence)
              end
            end
          end
        end
      end

      Apriori::AnalysisResult.new(frequent_item_sets, association_rules)
    end
def analyze(transactions) # AnalysisResult
      frequencies = {} # {item_set: count}
      frequent_item_sets = {} # {item_set_size: FrequentItemSet[]}

      one_element_item_sets = to_one_element_item_sets(transactions) # string[][]
      one_c_item_sets = find_item_sets_min_support_satisfied(
          one_element_item_sets, transactions, min_support, frequencies) # FrequentItemSet[]

      current_l_item_sets = one_c_item_sets # FrequentItemSet[]
      item_set_size = 1
      while current_l_item_sets.length != 0
        frequent_item_sets[item_set_size] = current_l_item_sets
        joined_sets = to_fixed_size_joined_sets(current_l_item_sets.map { |_| _.item_set }, item_set_size + 1)
        current_l_item_sets = find_item_sets_min_support_satisfied(joined_sets, transactions, min_support, frequencies)
        item_set_size += 1
      end

      found_sub_sets = [] # string[][]
      association_rules = [] # AssociationRule[]
      frequent_item_sets.each do |item_set_size, item_sets|
        item_sets = item_sets.map { |_| _.item_set }
        next if item_sets.length == 0 || item_sets[0].length <= 1

        item_sets.each do |item_set|
          to_all_sub_sets(item_set).each do |subset_item_set|
            diff_item_set = ((item_set - subset_item_set) + (subset_item_set - item_set)).uniq
            if diff_item_set.length > 0
              item_support = calculate_support(item_set, frequencies, transactions)
              subset_support = calculate_support(subset_item_set, frequencies, transactions)
              confidence = item_support / subset_support
              if !is_the_rule_already_found(found_sub_sets, subset_item_set) && confidence >= min_confidence
                found_sub_sets << subset_item_set
                association_rules << Apriori::AssociationRule.new(subset_item_set, diff_item_set, confidence)
              end
            end
          end
        end
      end

      Apriori::AnalysisResult.new(frequent_item_sets, association_rules)
    end
transactions: string[][]