<commit_before>var _ = require('lodash');

module.exports = function(results, objects, strict) {
  strict = !!strict;

  if (!results)
    return (strict) ? undefined : {};

  if (!objects)
		return results;

  if (!_.isArray(objects))
    if (_.isString(objects))
      objects = [objects];
    else
      return results;

  var predicate = function(value, index, array) {
    return _.isEmpty(value) && _.isObject(value);
  };

  if (_.isObject(results)) {
    return __buildObj(results, objects);
  } else if (_.isArray(results)) {
    var res = [];
    for (var i = 0; i < results.length; i++) {
      res.push(__buildObj(results[i],objects));
    }
    return res;
  } else {
    return (strict) ? undefined : {};
  }

  function __buildObj(results, objects) {
    var obj = {};

    objects.forEach(function(group) {
      obj[group] = {};
    });

    // Iterate over object properties
    var r = new RegExp('__(.+?)__(.+)');
    _.forOwn(results, function(value, key) {
      var matches = r.exec(key);
      if (matches !== null && _.has(obj, matches[1]) && matches.length == 3 && matches[1].length > 0 && matches[2].length > 0) {
        if ((!value && !strict) || value)
          obj[matches[1]][matches[2]] = value;
      } else {
        obj[key] = value;
      }
    });

    if (strict) {
      _.forOwn(obj, function(value, key) {
        if (!value && _.includes(objects, key))
          delete obj[key];
      });
    }

    return (strict) ? _(obj).omitBy(predicate).value() : obj;
  }
};
<commit_msg>One more fix.<commit_after>var _ = require('lodash');

module.exports = function(results, objects, strict) {
  strict = !!strict;

  if (!results)
    return (strict) ? undefined : {};

  if (!objects)
		return results;

  if (!_.isArray(objects))
    if (_.isString(objects))
      objects = [objects];
    else
      return results;

  var predicate = function(value, index, array) {
    return _.isEmpty(value) && _.isObject(value);
  };

  if (_.isArray(results)) {
    var res = [];
    for (var i = 0; i < results.length; i++) {
      res.push(__buildObj(results[i],objects));
    }
    return res;
  } else if (_.isObject(results)) {
    return __buildObj(results, objects);
  } else {
    return (strict) ? undefined : {};
  }

  function __buildObj(results, objects) {
    var obj = {};

    objects.forEach(function(group) {
      obj[group] = {};
    });

    // Iterate over object properties
    var r = new RegExp('__(.+?)__(.+)');
    _.forOwn(results, function(value, key) {
      var matches = r.exec(key);
      if (matches !== null && _.has(obj, matches[1]) && matches.length == 3 && matches[1].length > 0 && matches[2].length > 0) {
        if ((!value && !strict) || value)
          obj[matches[1]][matches[2]] = value;
      } else {
        obj[key] = value;
      }
    });

    if (strict) {
      _.forOwn(obj, function(value, key) {
        if (!value && _.includes(objects, key))
          delete obj[key];
      });
    }

    return (strict) ? _(obj).omitBy(predicate).value() : obj;
  }
};

{'fraction_non_alphanumeric': 0.17969776609724047, 'fraction_numerical': 0.005913272010512484, 'mean_word_length': 2.573943661971831, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3556192', 'n_tokens_mistral': 1013, 'n_tokens_neox': 976, 'n_words': 230}