<commit_before>/*!
 * bewbem
 * Copyright(c) 2015 VovanR <<EMAIL>>
 * MIT Licensed
 */

module.exports = {
    /**
     * @param {String} name
     * @return {String}
     */
    getBlockName: function (name) {
        var result = name.split('_')[0];

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            result = name.split('__')[1].split('_')[0];
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModName: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModValue: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModValue: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {Object}
     */
    parse: function (name) {
        return {
            block: {
                name: this.getBlockName(name),
                mod: {
                    name: this.getBlockModName(name),
                    value: this.getBlockModValue(name)
                }
            },
            elem: {
                name: this.getElemName(name),
                mod: {
                    name: this.getElemModName(name),
                    value: this.getElemModValue(name)
                }
            }
        };
    },
};
<commit_msg>Parser: Add memoization to parser #2<commit_after>/*!
 * bewbem
 * Copyright(c) 2015 VovanR <<EMAIL>>
 * MIT Licensed
 */

// For Parser memoization
var parsedCache = {};

module.exports = {
    /**
     * @param {String} name
     * @return {String}
     */
    getBlockName: function (name) {
        var result = name.split('_')[0];

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            result = name.split('__')[1].split('_')[0];
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModName: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getBlockModValue: function (name) {
        var result = '';

        if (/_/.test(name)) {
            if (!/__/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModName: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[1];
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {String}
     */
    getElemModValue: function (name) {
        var result = '';

        if (/__/.test(name)) {
            name = name.split('__')[1];

            if (/_/.test(name)) {
                result = name.split('_')[2] || '';
            }
        }

        return result;
    },

    /**
     * @param {String} name
     * @return {Object}
     */
    parse: function (name) {
        if (!parsedCache.hasOwnProperty(name)) {
            parsedCache[name] = {
                block: {
                    name: this.getBlockName(name),
                    mod: {
                        name: this.getBlockModName(name),
                        value: this.getBlockModValue(name)
                    }
                },
                elem: {
                    name: this.getElemName(name),
                    mod: {
                        name: this.getElemModName(name),
                        value: this.getElemModValue(name)
                    }
                }
            };
        }

        return parsedCache[name];
    },
};

{'fraction_non_alphanumeric': 0.1583772186463819, 'fraction_numerical': 0.0052662375658279695, 'mean_word_length': 1.1747243426632739, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4758107', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1502, 'n_words': 292}