<commit_before>var es = require('event-stream')
  , _ = require('underscore');

exports.toVextabs = function(stavesPerPage) {
    return es.mapSync(function(parsed) {
        return _.map(subarraysOfLength(_.flatten(_.map(parsed.texts, function(verse) {
            return _.map(_.zip(parsed.notes, verse), function(noteVerse) {
                return [
                    parsed.headline,
                    'notes ' + noteVerse[0],
                    'text ++,.11,.font=Arial-14-normal,' + noteVerse[1]
                ].join('\n');
            });
        })), stavesPerPage), function(page) {
            return 'options space=0 stave-distance=40\n\n' + page.join('\n\n');
        });
    });
};


function subarraysOfLength(array, length) {
    var subarrays = [[]]
      , i;
    
    for (i = 0; i < array.length; i++) {
        if (subarrays[subarrays.length - 1].length < length) {
            subarrays[subarrays.length - 1].push(array[i]);
        } else {
            subarrays.push([array[i]]);
        }
    }
    
    return subarrays;
}<commit_msg>added new pages for new verses (entries in the parsed texts list); added documentation on what the .toPdf actually does; added functional-programming styled processing of parsed content<commit_after>var es = require('event-stream')
  , _ = require('underscore');

/**
 * <p>converts a parsed .staves file like</p>
 * <pre>{
 *   headline: <String>,
 *   notes: [<String>, ...],
 *   texts: [[<String>, ...], ...]
 * }</pre>
 * <p>into a list of .vextab files, e.g.</p>
 * <pre>[
 *   '<options>\n\n<headline>\n<notes-line>\n<text-line>\n\n...',
 *   ...
 * ]</pre>
 * <p>where each .vextab file fits on a single page
 * defined by --width and --height command-line
 * arguments and each entry in the parsed .staves
 * texts creates a new page</p>
 */
exports.toVextabs = function(stavesPerPage) {
    return es.mapSync(function(parsed) {
        return _.chain(parsed.texts)
            // => [<text>, ...]
            .map(function(verse) {
                return _.chain(parsed.notes)
                    // => [<note>, ...]
                    .zip(verse)
                    // => [[<note>, <text>], ...]
                    .map(createTabstave(parsed.headline))
                    // => [<headline>\n<note-line>\n<text-line>, ...]
                    .reduce(createSubArrays(stavesPerPage), [[]])
                    // => [[<headline>\n<note-line>\n<text-line> x stavesPerPage], ...]
                    .map(function(vextabs) { return vextabs.join('\n\n') })
                    // => [<headline>\n<note-line>\n<text-line>\n\n x stavesPerPage, ...]
                    .value()
            })
            .flatten()
            // => [<headline>\n<note-line>\n<text-line>\n\n x stavesPerPage, ...]
            .map(createPage)
            // => [<options>\n\n<headline>\n<note-line>\n<text-line>\n\n..., ...]
            .value();
    });
};

function createPage(tabstaves) {
    return 'options space=0 stave-distance=40\n\n' + tabstaves;
}

function createSubArrays(length) {
    return function(prev, now) {
        if (prev[prev.length - 1].length < length) {
            prev[prev.length - 1].push(now);
        } else {
            prev.push([now]);
        }
        return prev;
    };
}

function createTabstave(headline) {
    return function(noteVerse) {
        return [
            headline,
            convertNotesLine(noteVerse[0]),
            convertTextLine(noteVerse[1])
        ].join('\n');
    };
}

function convertNotesLine(notes) {
    return 'notes ' + notes;
}

function convertTextLine(text) {
    return 'text ++,.11,.font=Arial-14-normal,' + text;
}
{'fraction_non_alphanumeric': 0.1761969904240766, 'fraction_numerical': 0.006292749658002736, 'mean_word_length': 1.9154704944178629, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 48, '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': '6565010', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1155, 'n_words': 210}