<commit_before>const yaml = require('js-yaml')
const chalk = require('chalk')
const path = require('path')
const helpers = require('../helpers')

module.exports = {
    getInterface: getInterface,
    generateInterface: generateInterface,
    printInterface: printInterface,
    printInterfaceItem: printInterfaceItem
}

// get the model interface
function getInterface(config) {
    let modelInterface = {}

    for (let i in config) {
        if (config[i]._type == 'model_item') {
            if (config[i].list) {
                modelInterface[i] = [config[i].origin]
            } else {
                modelInterface[i] = {
                    arguments: config[i].arguments,
                    impl_arguments: config[i].impl_arguments || []
                }
            }
        }
    }

    return modelInterface
}

// create files containing the model interface
function generateInterface(config, output) {
    let modelInterface = getInterface(config)

    for (let i in modelInterface) {
        helpers.writeFile(
            path.join(output, i + '.yaml'),
            yaml.safeDump({ [i]: modelInterface[i] })
        )
    }
}

// print the model interface<commit_msg>Stringified arrays in the interface print so that it's more readable<commit_after>const yaml = require('js-yaml')
const chalk = require('chalk')
const path = require('path')
const helpers = require('../helpers')

module.exports = {
    getInterface: getInterface,
    generateInterface: generateInterface,
    printInterface: printInterface,
    printInterfaceItem: printInterfaceItem
}

// get the model interface
function getInterface(config) {
    let modelInterface = {}

    for (let i in config) {
        if (config[i]._type == 'model_item') {
            if (config[i].list) {
                modelInterface[i] = [config[i].origin]
            } else {
                modelInterface[i] = {
                    arguments: config[i].arguments,
                    impl_arguments: config[i].impl_arguments || []
                }
            }
        }
    }

    function stringifyArrays(model) {
        for (let i in model) {
            if (Array.isArray(model[i]) && helpers.isScalar(model[i][0])) {
                model[i] = `[${model[i][0]}]`
            } else if (!helpers.isScalar(model[i])) {
                stringifyArrays(model[i])
            }
        }
    }

    stringifyArrays(modelInterface)

    return modelInterface
}

// create files containing the model interface
function generateInterface(config, output) {
    let modelInterface = getInterface(config)

    for (let i in modelInterface) {
        helpers.writeFile(
            path.join(output, i + '.yaml'),
            yaml.safeDump({ [i]: modelInterface[i] })
        )
    }
}

// print the model interface
{'fraction_non_alphanumeric': 0.11737257717157215, 'fraction_numerical': 0.0007178750897343862, 'mean_word_length': 2.2145328719723185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6596387', 'n_tokens_mistral': 775, 'n_tokens_neox': 751, 'n_words': 180}