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

function parseFlat(config, coerce) {
    var i, key, next, properties, property, value, _i, _len;
    for (key in config) {
        if ('function' === typeof coerce) {
            config[key] = value = coerce(config[key]);
        } else {
            value = config[key];
        }
        properties = key.split('.');
        if (properties.length < 2) {
            continue;
        }
        next = config;
        delete config[key];
        for (i = _i = 0, _len = properties.length; _i < _len; i = ++_i) {
            property = properties[i];
            if (i === properties.length - 1) {
                next[property] = value;
                break;
            }
            if (!next.hasOwnProperty(property)) {
                next[property] = {};
            }
            next = next[property];
        }
        next = null;
    }
}

function parse(filePath, coerce) {
    var config;
    var child, config, index, parent, section, sections, _i, _ref;
    config = ini.parse(fs.readFileSync(filePath, 'utf-8'));
    for (section in config) {
        if (!/\s*:\s*/.test(section)) {
            continue;
        }
        sections = section.split(/\s*:\s*/);
        child = sections[0];
        config[child] = {};
        for (index = _i = 1, _ref = sections.length; _i < _ref; index = _i += 1) {
            parent = sections[index];
            if (!config.hasOwnProperty(parent)) {
                continue;
            }
            _.extend(config[child], config[parent]);
        }
        _.extend(config[child], config[section]);
        delete config[section];
    }
    for (section in config) {
        parseFlat(config[section], coerce);
    }
    return config;
}

function isObject(value) {
    // Avoid a V8 JIT bug in Chrome 19-20.
    // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
    var type = typeof value;
    return type == 'function' || (value && type == 'object') || false;
}

function parser(registry) {
    if (!isObject(registry) || 'function' !== typeof registry.has || 'function' !== typeof registry.get) {
        registry = {
            has: function() {
                return false;
            }<commit_msg>sm-ini-config-parser.js: little refactoring sem-lib: replace collections by js-sorted-set PersistenceManager.coffee     save options where changed in case of update     can now update/delete models with unique constraint and no id     add default model constructor     add experimental override property<commit_after>var fs = require('fs'),
    ini = require('ini'),
    _ = require('lodash');

function parseFlat(config, coerce) {
    var i, key, next, properties, property, value, _len, parsedConfig = {};
    for (key in config) {
        if ('function' === typeof coerce) {
            value = coerce(config[key]);
        } else {
            value = config[key];
        }

        properties = key.split('.');
        _len = properties.length
        if (_len < 2) {
            parsedConfig[key] = value;
            continue;
        }

        next = parsedConfig;
        for (i = 0; i < _len; i++) {
            property = properties[i];
            if (i === _len - 1) {
                next[property] = value;
                break;
            }
            if (!next.hasOwnProperty(property)) {
                next[property] = {};
            }
            next = next[property];
        }
    }

    return parsedConfig;
}

function parse(filePath, coerce) {
    var child, configs, index, parent, section, sections, _len;
    configs = ini.parse(fs.readFileSync(filePath, 'utf-8'));

    for (section in configs) {
        if (!/\s*:\s*/.test(section)) {
            continue;
        }
        sections = section.split(/\s*:\s*/);
        child = sections[0];
        configs[child] = {};
        for (index = 1, _len = sections.length; index < _len; index++) {
            parent = sections[index];
            if (!configs.hasOwnProperty(parent)) {
                continue;
            }
            _.extend(configs[child], configs[parent]);
        }
        _.extend(configs[child], configs[section]);
        delete configs[section];
    }

    for (section in configs) {
        configs[section] = parseFlat(configs[section], coerce);
    }

    return configs;
}

function isObject(value) {
    // Avoid a V8 JIT bug in Chrome 19-20.
    // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
    var type = typeof value;
    return type == 'function' || (value && type == 'object') || false;
}

function parser(registry) {
    if (!isObject(registry) || 'function' !== typeof registry.has || 'function' !== typeof registry.get) {
        registry = {
            has: function() {
                return false;
            }
{'fraction_non_alphanumeric': 0.13971193415637861, 'fraction_numerical': 0.006790123456790123, 'mean_word_length': 1.8780343398460628, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2724083', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1394, 'n_words': 362}