Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 041d586
  • /
  • model
  • /
  • model_get_initial_datatypes.js
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:698561c9128a1017c2e239bb5ebf85fe0f424886
directory badge
swh:1:dir:afc4d6d3ec61f1e72dacbe98843f2f249093a47d

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
model_get_initial_datatypes.js
function replace_spaces_with_underscore(value) {
    value = value.split(" ").join("_");
    value = value.split(")").join("_");
    value = value.split("(").join("_");
    value = value.split("/").join("_");
    value = value.split("-").join("_");
    value = value.split("[").join("_");
    value = value.split("]").join("_");
    value = value.split(".").join("_");
    value = value.split("?").join("_");
    value = value.split("!").join("_");
    value = value.split("@").join("_");
    value = value.split("*").join("_");

    value = value.split("ä").join("ae");
    value = value.split("ü").join("ue");
    value = value.split("ö").join("oe");
    value = value.split("ß").join("ss");

    value = "id_qualitative_rectangle" + value;


    return value;
}

/**
 * This function identifies the initial datatypes
 * @param data
 * @returns {*}
 */
function identify_initial_datatypes(data) {

    let headerNames = d3.keys(data[0]);

    let headerNames_underscore = headerNames.map(replace_spaces_with_underscore);

    let columns = [];

 //   for (let i = 0; i < 91; i++) {
    for (let i = 0; i < headerNames.length; i++) {
        let obj = {};
        obj[key_header] = headerNames[i];
        obj[key_id] = headerNames_underscore[i];
        obj[key_column_values] = data.map(function (d) {

            if (d !== undefined) {
                return d[headerNames[i]];
            }

        });
        obj[key_data_type] = check_data_types(obj[key_column_values]);

        columns.push(obj);
    }

    /**
     * This function identifies the data types
     * @param x
     * @returns {string}
     */
    function check_data_types(x) {

        const regExp_date = /^(0?[1-9]|[12][0-9]|3[01])[\.\-](0?[1-9]|1[012])[\.\-]\d{4}$/; // regular Expression for dd.mm.yyyy

        if (x.every(function(i){ return !isNaN(i)})) {
            if (x.every(function(i){ return Number.isInteger(i)})) {
                return id_data_type__categorical;
            }
            return id_data_type__numerical;
        } else if (x.every(function(i){ return i === undefined || i === "" || regExp_date.test(i)})) {
            return id_data_type__date;
        } else if (x.every(function(i){ return typeof i === "string" })) {
            return id_data_type__categorical;
        }
    }

    return columns;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API