<commit_before>var xml = {
  categories: [],
  doc: '',
  add: function() {
    that = this;
    $(that.doc).find('span').each(function() {
      that.categories.push(this.getAttribute('category'));
    });
  },
  filter: function(arr) {
    var filteredArray = [], prev;
    arr.sort();
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] !== prev) {
        filteredArray.push(arr[i]);
      }
      prev = arr[i];
    }
    return filteredArray
  },
  show: function() {
    that = this;
    filteredArray = this.filter(this.categories);
    this.categories = filteredArray;
    $(filteredArray).each(function() {
      $('thead tr').append('<th>' + this + '</th>');
      $('tbody tr').append('<td>' + that.count(that, this) + '</td>');
    });
  },
  count: function(obj, category) {
    arr = [];
    matches = [];
    str = text.doc;
    elements = this.doc.querySelectorAll("[category=" + category + "]")
    for (var i = 0; i < elements.length; i++) {
      arr.push(elements[i].textContent.replace(/(\r\n|\n|\r)/gm,"").trim());
    }
    filteredArray = this.filter(arr);
    for (var i = 0; i < filteredArray.length; i++) {
      pattern = filteredArray[i];
      regex = new RegExp(pattern, 'gi');
      if (str.match(regex)) {
        matches.push(str.match(regex));
      }
    }
    return matches.length;
  }
}
<commit_msg>Separate concerns of match and count methods<commit_after>var xml = {
  categories: [],
  doc: '',
  add: function() {
    that = this;
    $(that.doc).find('span').each(function() {
      that.categories.push(this.getAttribute('category'));
    });
  },
  filter: function(arr) {
    var filteredArray = [], prev;
    arr.sort();
    for (var i = 0; i < arr.length; i++) {
      if (arr[i] !== prev) {
        filteredArray.push(arr[i]);
      }
      prev = arr[i];
    }
    return filteredArray
  },
  show: function() {
    that = this;
    filteredArray = this.filter(this.categories);
    this.categories = filteredArray;
    $(filteredArray).each(function() {
      $('thead tr').append('<th>' + this + '</th>');
      $('tbody tr').append('<td>' + that.matchCount(this) + '</td>');
    });
  },
  matchCount: function(category) {
    return this.match(category).length;
  },
  match: function(category) {
    arr = [];
    matches = [];
    str = text.doc;
    elements = this.doc.querySelectorAll("[category=" + category + "]")
    for (var i = 0; i < elements.length; i++) {
      arr.push(elements[i].textContent.replace(/(\r\n|\n|\r)/gm,"").trim());
    }
    filteredArray = this.filter(arr);
    for (var i = 0; i < filteredArray.length; i++) {
      pattern = filteredArray[i];
      regex = new RegExp(pattern, 'gi');
      if (str.match(regex)) {
        matches.push(str.match(regex));
      }
    }
    return matches;
  }
}

{'fraction_non_alphanumeric': 0.20128939828080228, 'fraction_numerical': 0.002148997134670487, 'mean_word_length': 2.6178756476683938, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '6458341', 'n_tokens_mistral': 930, 'n_tokens_neox': 922, 'n_words': 182}