<commit_before>library configuration;

import 'package:useful/useful.dart';

class ComputedValue {
  final _computation;
  bool _evaluated = false;
  dynamic _value;
  ComputedValue(dynamic this._computation(ConfigMap config));

  /** Lazy compute the value */
  getValue(config) {
    if (_evaluated) return _value;
    _value = _computation(config);
    _evaluated = true;
    return _value;
  }
}

$(dynamic computation(ConfigMap config)) => new ComputedValue(computation);

class ConfigMap {
  ConfigMap root;
  Map _data;
  /**
   * Recursively converts [other] to [ConfigMap].
   */
  ConfigMap({ConfigMap this.root: null, Map other: const {}}) {
    if (root == null) root = this;
    _data = {};
    other.forEach((k,v) {
      if (v is! Map) {
        _data[k] = v;
      } else {
        _data[k] = new ConfigMap(root:root,other:v);
      }
    });
  }

  /**
   * Recursively converts to [Map]
   */
  Map toMap() {
    var res = {};
    _data.forEach((k,v) {
      if (v is ConfigMap) {
        res[k] = v.toMap();
      } else {
        res[k] = this[k];
      }
    });
    return res;
  }

  ConfigMap.config(ConfigMap this.root, Map this._data);
  operator[](key) => _data[key] is ComputedValue ? _data[key].getValue(root) : _data[key];
}

class Configuration {

  final Map<String, Map > _configurations = {};

  /**
   * Register configuration under [name].
   */
  void add(String name, Map configuration, {String parent: null}) {
    configuration['__name__'] = name;
    _configurations[name] = {
      "parent": parent,
      "configMap": new ConfigMap(other:configuration)
    };
  }

  /**
   * Get configuration stored under [name].
   *
   * Name of the configuration is stored under key "__name__".
   * Throws [ArgumentError] if configuration with [name] does not exists.
   */
  Map get(name) {
    if (!_configurations.containsKey(name)) throw new ArgumentError("Configuration does not exist");
    var config = _configurations[name];
    if (config["parent"] == null) {
      return config["configMap"].toMap();
    } else {
      return mergeMaps(get(config["parent"]), config["configMap"]);
    }
  }
}<commit_msg>Update configuration.dart<commit_after>library configuration;

import 'package:useful/useful.dart';

class ComputedValue {
  final _computation;
  bool _evaluated = false;
  dynamic _value;
  ComputedValue(dynamic this._computation(ConfigMap config));

  /** Lazy compute the value */
  getValue(config) {
    if (_evaluated) return _value;
    _value = _computation(config);
    _evaluated = true;
    return _value;
  }
}

$(dynamic computation(ConfigMap config)) => new ComputedValue(computation);

class ConfigMap {
  ConfigMap root;
  Map _data;
  
  _convert(Map map, condition, convertValue) {
    var res = {};
    map.forEach((k, v)) {
      v = if (condition(v)) convertValue(v);
      res[k] = v;
    }
  }
  /**
   * Recursively converts [other] to [ConfigMap].
   */
  ConfigMap({ConfigMap this.root: null, Map other: const {}}) {
    if (root == null) root = this;
    _data = _convert(other, (v) => v is Map, (v) => new ConfigMap(root: root, other: v));
  }

  /**
   * Recursively converts to [Map]
   */
  Map toMap() {
    return _convert(_data, (v) => v is ConfigMap, (v) => v.toMap());
  }

  operator[](key) => _data[key] is ComputedValue ? _data[key].getValue(root) : _data[key];
}

class Configuration {

  final Map<String, Map > _configurations = {};

  /**
   * Register configuration under [name].
   */
  void add(String name, Map configuration, {String parent: null}) {
    configuration['__name__'] = name;
    _configurations[name] = {
      "parent": parent,
      "configMap": new ConfigMap(other:configuration)
    };
  }

  /**
   * Get configuration stored under [name].
   *
   * Name of the configuration is stored under key "__name__".
   * Throws [ArgumentError] if configuration with [name] does not exists.
   */
  Map get(name) {
    if (!_configurations.containsKey(name)) throw new ArgumentError("Configuration does not exist.");
    var config = _configurations[name];
    var parent = config["parent"];
    
    var configMap = config["configMap"];
    
    if (parent != null) configMap = mergeMaps(get(parent), configMap);
    
    return configMap.toMap();
  }
}
{'fraction_non_alphanumeric': 0.14205212491195116, 'fraction_numerical': 0.0, 'mean_word_length': 3.15609756097561, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 13, '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': '6163470', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1355, 'n_words': 352}