<commit_before>/*jslint browser: true, devel: true, nomen: true, sloppy: true */
var wikipediaImages = ['logo', 'red pencil', 'wikibooks', 'feature', 'star', 'symbol', 'vote', 'icon', 'question_book', 'disamb', 'edit', 'ambox', 'wiki_letter', 'speakerlink'];
var portalImages = ['caribou from wagon trails', 'rose amber', 'france loiret', 'Leaf_1_web', 'Martinique.web'];
var unwantedImages = ['map'];
var filterList = _.union(wikipediaImages, portalImages, unwantedImages);

var width = 1000;
var height = 500;

var rootCircleRadius = 30;
var rootCircleCenterXPos = 30;

var verticalBarLength = 100;
var verticalMargin = 30;

var horizontalOffset = 150;
var verticalBarXPos = rootCircleCenterXPos + rootCircleRadius + horizontalOffset;

var barWidth = 100;

// Distance between two children
var heightBetweenChildren = 100;


function getName(data) {
    return data.vernacularName || data.canonicalName || data.scientificName || "Error: could not find name";
}

function getScientificName(data) {
    var name = data.scientificName;

    // Used when name has date and scientist attached
    if (data.authorship) {
        var index = name.indexOf(data.authorship);
        if (index !== -1) {
            // remove the space before the name too
            return name.substring(0, index - 1);
        }
    }

    return name;
}

function getCommonName(data) {
    return data.vernacularName || data.canonicalName;
}


// Data stuff

function setInformationPaneDatum(value) {
    // Binds data to the information pane. The data is [id, has_wikipedia_content]. This allows us
    // to avoid reloading data when we go into sublevel if information pane has already the correct data.
    d3.select('#infoContainer').datum(value);
}

function getInformationPaneDatum() {
    return d3.select('#infoContainer').datum() || [-1, false];
}

function showInformation(data, tree, scrollToInformationPanel) {
   setUpInformationPanel();
   showWikipediaInformation(data, tree, scrollToInformationPanel);
}

function showWikipediaInformation(data, tree, scrollToInformationPanel) {
    putWikipediaInfoLoader();

    var speciesName = getScientificName(data);
    var commonName = getCommonName(data);
    var ID = data.id;

    wiki.article(commonName, speciesName, function (data) {
        removeWikipediaInfoLoader();

        var divSelection = d3.select('#speciesData');

        if (data) {
            setInformationPaneDatum([ID, true]);
            addWikipediaTextToSelection(data, tree, divSelection);
            if (!sidebarExists() && scrollToInformationPanel) {
                scrollToInformationPane();
            }

            addWikipediaImage(wiki, commonName, speciesName, divSelection);
        } else {
            setInformationPaneDatum([ID, false]);
            addNoAvailableInformationText(divSelection);
        }
    });
}

function addWikipediaImage(wiki, commonName, speciesName, divSelection) {
    wiki.image(commonName, speciesName, function (imagesData) {
        var url = chooseImage(imagesData || []);
        if (url) {
            addWikipediaImageToSelection(divSelection, url);
        }
    });
}

function addWikipediaImageToSelection(divSelection, url) {
    divSelection.insert('img', '#content')
        .attr('src', url)
        .attr('alt', 'image')
        .attr('class', 'ui huge image');
}

function addWikipediaTextToSelection(data, tree, divSelection) {
    var title = data.title;
    var raw_content = data.extract;
    var content = removeWikiCruft(raw_content);

    var titleText = title + " (" + tree.getTaxon() + ')';
    divSelection.append('h1').attr('class', 'header').text(titleText);
    divSelection.append('div').attr('id', 'content').html(content);
}

function addNoAvailableInformationText(divSelection) {
    divSelection.append('h1').text('No available information');
}

function removeWikiCruft(text) {
    var lowercaseText = text.toLowerCase();

    var index = lowercaseText.indexOf('see also');
    if (index !== -1) {
        return text.substring(0, index);
    }

    var index = lowercaseText.indexOf('references');
    if (index !== -1) {
        return text.substring(0, index);<commit_msg>Added good alt text to images.<commit_after>/*jslint browser: true, devel: true, nomen: true, sloppy: true */
var wikipediaImages = ['logo', 'red pencil', 'wikibooks', 'feature', 'star', 'symbol', 'vote', 'icon', 'question_book', 'disamb', 'edit', 'ambox', 'wiki_letter', 'speakerlink'];
var portalImages = ['caribou from wagon trails', 'rose amber', 'france loiret', 'Leaf_1_web', 'Martinique.web'];
var unwantedImages = ['map'];
var filterList = _.union(wikipediaImages, portalImages, unwantedImages);

var width = 1000;
var height = 500;

var rootCircleRadius = 30;
var rootCircleCenterXPos = 30;

var verticalBarLength = 100;
var verticalMargin = 30;

var horizontalOffset = 150;
var verticalBarXPos = rootCircleCenterXPos + rootCircleRadius + horizontalOffset;

var barWidth = 100;

// Distance between two children
var heightBetweenChildren = 100;


function getName(data) {
    return data.vernacularName || data.canonicalName || data.scientificName || "Error: could not find name";
}

function getScientificName(data) {
    var name = data.scientificName;

    // Used when name has date and scientist attached
    if (data.authorship) {
        var index = name.indexOf(data.authorship);
        if (index !== -1) {
            // remove the space before the name too
            return name.substring(0, index - 1);
        }
    }

    return name;
}

function getCommonName(data) {
    return data.vernacularName || data.canonicalName;
}


// Data stuff

function setInformationPaneDatum(value) {
    // Binds data to the information pane. The data is [id, has_wikipedia_content]. This allows us
    // to avoid reloading data when we go into sublevel if information pane has already the correct data.
    d3.select('#infoContainer').datum(value);
}

function getInformationPaneDatum() {
    return d3.select('#infoContainer').datum() || [-1, false];
}

function showInformation(data, tree, scrollToInformationPanel) {
    setUpInformationPanel();
    showWikipediaInformation(data, tree, scrollToInformationPanel);
}

function showWikipediaInformation(data, tree, scrollToInformationPanel) {
    putWikipediaInfoLoader();

    var speciesName = getScientificName(data);
    var commonName = getCommonName(data);
    var ID = data.id;

    wiki.article(commonName, speciesName, function (data) {
        removeWikipediaInfoLoader();

        var divSelection = d3.select('#speciesData');

        if (data) {
            setInformationPaneDatum([ID, true]);
            addWikipediaTextToSelection(data, tree, divSelection);
            if (!sidebarExists() && scrollToInformationPanel) {
                scrollToInformationPane();
            }

            addWikipediaImage(wiki, commonName, speciesName, divSelection);
        } else {
            setInformationPaneDatum([ID, false]);
            addNoAvailableInformationText(divSelection);
        }
    });
}

function addWikipediaImage(wiki, commonName, speciesName, divSelection) {
    wiki.image(commonName, speciesName, function (imagesData) {
        var url = chooseImage(imagesData || []);
        if (url) {
            addWikipediaImageToSelection(divSelection, commonName, speciesName, url);
        }
    });
}

function addWikipediaImageToSelection(divSelection, commonName, speciesName, url) {
    divSelection.insert('img', '#content')
        .attr('src', url + 'asdasdasdasd')
        .attr('alt', commonName + ' - ' + speciesName + ' (' + tree.getTaxon() + ')')
        .attr('class', 'ui huge image');
}

function addWikipediaTextToSelection(data, tree, divSelection) {
    var title = data.title;
    var raw_content = data.extract;
    var content = removeWikiCruft(raw_content);

    var titleText = title + " (" + tree.getTaxon() + ')';
    divSelection.append('h1').attr('class', 'header').text(titleText);
    divSelection.append('div').attr('id', 'content').html(content);
}

function addNoAvailableInformationText(divSelection) {
    divSelection.append('h1').text('No available information');
}

function removeWikiCruft(text) {
    var lowercaseText = text.toLowerCase();

    var index = lowercaseText.indexOf('see also');
    if (index !== -1) {
        return text.substring(0, index);
    }

    var index = lowercaseText.indexOf('references');
    if (index !== -1) {
        return text.substring(0, index);
{'fraction_non_alphanumeric': 0.1251179245283019, 'fraction_numerical': 0.00919811320754717, 'mean_word_length': 3.6701541850220263, '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': '2523618', 'n_tokens_mistral': 2544, 'n_tokens_neox': 2407, 'n_words': 615}