<commit_before>var jsonld_1 = require('jsonld');
var n3_1 = require('n3');
var shared_1 = require('./shared');
function toJson(file) {
    if (file.context[''])
        delete file.context['']; // JSON-LD doesn't support the empty prefix
    return jsonld_1.promises.fromRDF(file.document)
        .then(function (doc) { return jsonld_1.promises.compact(doc, file.context); })
        .then(function (doc) { return JSON.stringify(doc, null, 4); });
}
exports.toJson = toJson;
function n3Writer(file, format) {
    var doc = shared_1.jsonldToN3Quads(file.document);
    return new Promise(function (resolve, reject) {
        var w = n3_1.Writer({ format: format, prefixes: file.context });
        doc.forEach(function (triple) { return w.addTriple(triple); });
        w.end(function (err, result) {
            if (err)
                reject(err);
            else
                resolve(result);
        });
    });
}
function toTriG(file) {
    return n3Writer(file, 'application/trig');
}
exports.toTriG = toTriG;
function toNQuads(file) {
    return n3Writer(file, 'N-Quads');
}
exports.toNQuads = toNQuads;
function toJS(file, jsTemplate) {
    if (jsTemplate === void 0) { jsTemplate = 'const quads = ${quadArray};\nexport default quads;'; }
    return toNQuads(file)
        .then(function (nquads) { return nquads.split(/\s*\.\s*[\r|\n]/).filter(function (nquads) { return !!nquads; }); })
        .then(function (nquads) { return nquads.map(function (quad) { return ("[\n        " + quadToJS(quad) + "\n    ]"); }); })
        .then(function (nquads) { return ("[\n    " + nquads.join(',') + "\n]"); })
        .then(function (array) { return jsTemplate.replace(/\$\{\s*quadArray\s*\}/, array); });
}
exports.toJS = toJS;
function quadToJS(quad) {
    // Get the array of quad parts, regexp is to catch spaces in quotes
    var quadArr = quad.match(/(?:[^\s"]+|"[^"]*")+/g);
    for (var i = 0; i < 4; i++) {
        var qPart = quadArr[i];
        if (!qPart || n3_1.Util.isBlank(qPart) || qPart === '@default') {
            // Empty === null
            quadArr[i] = 'null';
        }
        else if (qPart[0] === '<' && qPart[qPart.length - 1] === '>') {
            // Remove the '<>' from resources in NQuads
            quadArr[i] = "'" + qPart.slice(1, -1) + "'";
        }
        else {
            var m = qPart.match(/^"(.*)"(?:\^\^<http:\/\/www.w3.org\/2001\/XMLSchema#(.*)>)?$/);
            // If it's a string, it should get quotes
            if (!m[2] || m[2] === 'string')
                quadArr[i] = "'" + qPart + "'";
            else if (m[1])
                quadArr[i] = m[1];
        }
    }
    return quadArr.join(',\n        ');
}
function toType(file, type, jsTemplate) {
    switch (type) {
        case shared_1.Type.Json:
            return toJson(file);
        case shared_1.Type.NQuads:
            return toNQuads(file);<commit_msg>Forgot to build<commit_after>var jsonld_1 = require('jsonld');
var n3_1 = require('n3');
var shared_1 = require('./shared');
function toJson(file) {
    if (file.context[''])
        delete file.context['']; // JSON-LD doesn't support the empty prefix
    return jsonld_1.promises.fromRDF(file.document)
        .then(function (doc) { return jsonld_1.promises.compact(doc, file.context); })
        .then(function (doc) { return JSON.stringify(doc, null, 4); });
}
exports.toJson = toJson;
function n3Writer(file, format) {
    var doc = shared_1.jsonldToN3Quads(file.document);
    return new Promise(function (resolve, reject) {
        var w = n3_1.Writer({ format: format, prefixes: file.context });
        doc.forEach(function (triple) { return w.addTriple(triple); });
        w.end(function (err, result) {
            if (err)
                reject(err);
            else
                resolve(result);
        });
    });
}
function toTriG(file) {
    return n3Writer(file, 'application/trig');
}
exports.toTriG = toTriG;
function toNQuads(file) {
    return n3Writer(file, 'N-Quads');
}
exports.toNQuads = toNQuads;
function toJS(file, jsTemplate) {
    if (jsTemplate === void 0) { jsTemplate = 'const quads = ${quadArray};\nexport default quads;'; }
    return toNQuads(file)
        .then(function (nquads) { return nquads.split(/\s*\.\s*[\r|\n]/).filter(function (nquads) { return !!nquads; }); })
        .then(function (nquads) { return nquads.map(function (quad) { return ("[\n        " + quadToJS(quad) + "\n    ]"); }); })
        .then(function (nquads) { return ("[\n    " + nquads.join(',') + "\n]"); })
        .then(function (array) { return jsTemplate.replace(/\$\{\s*quadArray\s*\}/, array); });
}
exports.toJS = toJS;
function quadToJS(quad) {
    // Get the array of quad parts, regexp is to catch spaces in quotes
    var quadArr = quad.match(/(?:[^\s"]+|"[^"]*")+/g);
    for (var i = 0; i < 4; i++) {
        var qPart = quadArr[i];
        if (!qPart || n3_1.Util.isBlank(qPart) || qPart === '@default') {
            // Empty === null
            quadArr[i] = 'null';
        }
        else if (qPart[0] === '<' && qPart[qPart.length - 1] === '>') {
            // Remove the '<>' from resources in NQuads
            quadArr[i] = "'" + qPart.slice(1, -1) + "'";
        }
        else {
            // it's probably a literal
            quadArr[i] = "'" + qPart + "'";
        }
    }
    return quadArr.join(',\n        ');
}
function toType(file, type, jsTemplate) {
    switch (type) {
        case shared_1.Type.Json:
            return toJson(file);
        case shared_1.Type.NQuads:
            return toNQuads(file);
{'fraction_non_alphanumeric': 0.1848178867652362, 'fraction_numerical': 0.010998918139199423, 'mean_word_length': 2.3947368421052633, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '7520673', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1872, 'n_words': 413}