<commit_before>'use strict'

module.exports = function (predicates, triples, types, target, pos, index) {
    triples.forEach(triple => {

        let config = predicates[triple[1]];
        if (!config || (!config.nodes && !config.edges)) {
            return console.error('Flow-visualizer.parse: Invalid triple "' + triple + '".');
        }

        Object.keys(config).forEach(category => config[category].forEach(map => {

            if (!types[map.type]) {
                return console.error('flow-visualizer.parse: type "' + map.type + '" not found for predicate "' + triple[1] + '".');
            }

            Parse(map, triple, types[map.type][category] || {}, target[category], pos, index)
        }));
    });
};

function Parse (map, triple, type, target, pos, index) {

    let parsed = {
        x: pos.x,
        y: pos.y
    };

    map.subject && map.subject.forEach(prop => parsed[prop] = triple[0]);
    map.object && map.object.forEach(prop => parsed[prop] = triple[2]);

    parsed.id = parsed.id || type.id || triple[0] + triple[2];
 
    add(Object.assign(parsed, type), target, index);
}

function add (object, target, index) {

    if (index[object.id]) {
        ++index[object.id];
        return;
    }

    index[object.id] = 1;
    target.push(object);
}
<commit_msg>make type optional<commit_after>'use strict'

module.exports = function (predicates, triples, types, target, pos, index) {
    triples.forEach(triple => {

        let config = predicates[triple[1]];
        if (!config || (!config.nodes && !config.edges)) {
            return console.error('Flow-visualizer.parse: Invalid triple "' + triple + '".');
        }

        Object.keys(config).forEach(category => config[category].forEach(map => {

            if (map.type && !types[map.type]) {
                return console.error('flow-visualizer.parse: type "' + map.type + '" not found for predicate "' + triple[1] + '".');
            }

            Parse(map, triple, map.type ? types[map.type][category] || {} : {}, target[category], pos, index)
        }));
    });
};

function Parse (map, triple, type, target, pos, index) {

    let parsed = {
        x: pos.x,
        y: pos.y
    };

    map.subject && map.subject.forEach(prop => parsed[prop] = triple[0]);
    map.object && map.object.forEach(prop => parsed[prop] = triple[2]);

    parsed.id = parsed.id || type.id || triple[0] + triple[2];
 
    add(Object.assign(parsed, type), target, index);
}

function add (object, target, index) {

    if (index[object.id]) {
        ++index[object.id];
        return;
    }

    index[object.id] = 1;
    target.push(object);
}

{'fraction_non_alphanumeric': 0.17796289284361985, 'fraction_numerical': 0.005301022340022719, 'mean_word_length': 2.536813922356091, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4958846', 'n_tokens_mistral': 836, 'n_tokens_neox': 811, 'n_words': 174}