<commit_before>var rdf = require('ext-rdflib');
var RDF2h = require('rdf2h');
var GraphNode = require("rdfgraphnode-rdfext");


function LD2h() {
}

//LD2h.store = new LdpStore();

//Needed for inserted scripts to be executed
function replaceElement(element) {
    const newElement = document.createElement(element.nodeName);
    //copy attributes (eg. src)
    for (let i = 0; i < element.attributes.length; i++) {
        newElement.setAttribute(element.attributes[i].name, element.attributes[i].value);
    }
    newElement.innerHTML = element.innerHTML;
    element.parentNode.insertBefore(newElement, element);
    element.remove();
}

function insertHTML(node, htmlString) {
    node.innerHTML = "";
    //innerHTML should work if no scripts are included
    if (!/<script/i.test(htmlString)) {
        try {
            node.innerHTML = htmlString;
        }
        //fail silently and try elaborated method below
        catch (e) {}
    }
    //if innerHTML failed or wasn't executed
    if (node.innerHTML === "") {
        const tmp = document.createElement(node.nodeName);
        tmp.innerHTML = htmlString;
        if (tmp.hasChildNodes()) {
            scripts = tmp.getElementsByTagName("script");
            if (scripts.length > 0) {
                scripts = Array.from(scripts)
                for (let i = 0; i < scripts.length; i++) {
                    replaceElement(scripts[i]);
                }
            }
            //tmp.firstChild is live, so this will move all children
            while (tmp.firstChild) {
                console.log(tmp.firstChild)
                node.appendChild(tmp.firstChild);
            }
        } else {
            console.log("no children");
        }
    }
}

function setHtmlContent(node, content) {
    if (node.nodeName === "HTML") {
        let tmp = document.createElement("html");
        tmp.innerHTML = content;
        let head = tmp.getElementsByTagName("head")[0].innerHTML;
        let body = tmp.getElementsByTagName("body")[0].innerHTML;
        insertHTML(node.getElementsByTagName("head")[0], head);
        insertHTML(node.getElementsByTagName("body")[0], body);<commit_msg>added missing declaration of var<commit_after>var rdf = require('ext-rdflib');
var RDF2h = require('rdf2h');
var GraphNode = require("rdfgraphnode-rdfext");


function LD2h() {
}

//LD2h.store = new LdpStore();

//Needed for inserted scripts to be executed
function replaceElement(element) {
    const newElement = document.createElement(element.nodeName);
    //copy attributes (eg. src)
    for (let i = 0; i < element.attributes.length; i++) {
        newElement.setAttribute(element.attributes[i].name, element.attributes[i].value);
    }
    newElement.innerHTML = element.innerHTML;
    element.parentNode.insertBefore(newElement, element);
    element.remove();
}

function insertHTML(node, htmlString) {
    node.innerHTML = "";
    //innerHTML should work if no scripts are included
    if (!/<script/i.test(htmlString)) {
        try {
            node.innerHTML = htmlString;
        }
        //fail silently and try elaborated method below
        catch (e) {}
    }
    //if innerHTML failed or wasn't executed
    if (node.innerHTML === "") {
        const tmp = document.createElement(node.nodeName);
        tmp.innerHTML = htmlString;
        if (tmp.hasChildNodes()) {
            let scripts = tmp.getElementsByTagName("script");
            if (scripts.length > 0) {
                scripts = Array.from(scripts)
                for (let i = 0; i < scripts.length; i++) {
                    replaceElement(scripts[i]);
                }
            }
            //tmp.firstChild is live, so this will move all children
            while (tmp.firstChild) {
                console.log(tmp.firstChild)
                node.appendChild(tmp.firstChild);
            }
        } else {
            console.log("no children");
        }
    }
}

function setHtmlContent(node, content) {
    if (node.nodeName === "HTML") {
        let tmp = document.createElement("html");
        tmp.innerHTML = content;
        let head = tmp.getElementsByTagName("head")[0].innerHTML;
        let body = tmp.getElementsByTagName("body")[0].innerHTML;
        insertHTML(node.getElementsByTagName("head")[0], head);
        insertHTML(node.getElementsByTagName("body")[0], body);
{'fraction_non_alphanumeric': 0.12762036397143514, 'fraction_numerical': 0.00506795669200645, 'mean_word_length': 2.3763608087091757, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '5139297', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1207, 'n_words': 278}