<commit_before>module GQL
  class MapReduce

    def self.overview input
      input.map { |a| a['name'] }
    end

    def self.uri input
      input.map { |a| a['uri'] }
    end

    def self.find_feature input, feature_to_find
      feature_found = nil
      input.each do |feature|
        if feature['name'] == feature_to_find
          feature_found = feature
        end
      end
      feature_found
    end

    def self.filter_features_by_tag input, *tags_to_find
      features = []
      input.each do |feature|
          if (feature['tags'] != nil  and has_tags(feature['tags'], tags_to_find.flatten))
            features.push feature
          end
      end
      features
    end

    def self.scenario_by_feature_and_tag input, feature_to_find, condition, *tags_to_find
      scenarios = []
      input.each do |feature|
        if feature['name'] == feature_to_find
          feature['elements'].each do |element|
            if (element['name'] != "") and element['type'] == "scenario" and has_tags(element['tags'], tags_to_find) == condition
              scenarios.push element['name']
            end
          end
        end
      end
      scenarios
    end

    def self.scenario input, feature_to_find, scenario_to_find
      input = find_feature input, feature_to_find
      scenario = nil
      input['elements'].each { |element| scenario = element if element['name'] == scenario_to_find }
      scenario
    end

    def self.all input, args
      scenarios = []
      input = [find_feature(input, args['feature'])] if args.has_key?('feature')
      input.each do |feature|
        feature['elements'].each do |element|
          scenarios.push element['name'] if (element['name'] != "") and element['type'] == args['what']
        end
      end
      scenarios
    end

    def self.tags input
      tags = Set.new
      input.each do |feature|
        feature['elements'].each do |element|
          if element['tags'] != nil
            element['tags'].each do |tag|
              tags.add tag['name']
            end
          end
        end
      end
      tags.to_a
    end

    def self.has_tags tags_given, tags_for_search
      return false if tags_given == nil
      tags_given = tags_given.map { |t| t["name"] }
      found = 0
      tags_for_search.each do |tag_for_search|
        found = found + 1 if tags_given.include?(tag_for_search)
      end
      found == tags_for_search.size
    end

  end
end<commit_msg>Used core ruby array functions<commit_after>module GQL
  class MapReduce

    def self.overview input
      input.map{|a| a['name'] }
    end

    def self.uri input
      input.map{|a| a['uri'] }
    end

    def self.find_feature input, feature_to_find
      input.find{|feature| feature['name'] == feature_to_find }
    end

    def self.filter_features_by_tag input, *tags_to_find
      input.find_all{|feature| has_tags feature['tags'], tags_to_find.flatten }
    end

    def self.scenario_by_feature_and_tag input, feature_to_find, condition, *tags_to_find
      scenarios = []
      input.each do |feature|
        if feature['name'] == feature_to_find
          feature['elements'].each do |element|
            if element['type'] == "scenario" and has_tags(element['tags'], tags_to_find) == condition
              scenarios.push element['name']
            end
          end
        end
      end
      scenarios
    end

    def self.scenario input, feature_to_find, scenario_to_find
      input = find_feature input, feature_to_find
      scenario = nil
      input['elements'].each { |element| scenario = element if element['name'] == scenario_to_find }
      scenario
    end

    def self.all input, args
      results = []
      input = [find_feature(input, args['feature'])] if args.has_key?('feature')
      input.each do |feature|
        feature['elements'].each do |element|
          results.push element['name'] if element['type'] == args['what']
        end
      end
      results
    end

    def self.tags input
      tags = Set.new
      input.each do |feature|
        feature['elements'].each do |element|
          break if element['tags'] == nil
          element['tags'].each { |tag| tags.add tag['name'] }
        end
      end
      tags.to_a
    end

    def self.has_tags given, search
      return false if given == nil
      search.count{|tag_for_search| given.map{|t| t["name"]}.include?(tag_for_search)}==search.size
    end
  end
end
{'fraction_non_alphanumeric': 0.10780333784393324, 'fraction_numerical': 0.0004510599909788002, 'mean_word_length': 2.27790096082779, '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': '4407864', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1315, 'n_words': 340}