<commit_before>iD.Connection = function() {

    var event = d3.dispatch('auth', 'load'),
        url = 'http://www.openstreetmap.org',
        connection = {},
        user = {},
        version,
        keys,
        inflight = {},
        loadedTiles = {},
        oauth = iD.OAuth().url(url);

    function bboxUrl(b) {
        return url + '/api/0.6/map?bbox=' + [b[0][0],b[1][1],b[1][0],b[0][1]];
    }

    function bboxFromAPI(box, tile, callback) {
        function done(err, parsed) {
             loadedTiles[tile.toString()] = true;
             delete inflight[tile.toString()];
             callback(err, parsed);
         }
         inflight[tile.toString()] = loadFromURL(bboxUrl(box), done);
    }

    function loadFromURL(url, callback) {
        function done(dom) {
            return callback(null, parse(dom));
        }
        return d3.xml(url).get().on('load', done);
    }

    function getNodes(obj) {
        var nelems = obj.getElementsByTagName('nd'), nodes = new Array(nelems.length);
        for (var i = 0, l = nelems.length; i < l; i++) {
            nodes[i] = 'n' + nelems[i].attributes.ref.nodeValue;
        }
        return nodes;
    }

    function getTags(obj) {
        var tags = {}, tagelems = obj.getElementsByTagName('tag');
        for (var i = 0, l = tagelems.length; i < l; i++) {
            var item = tagelems[i];
            tags[item.attributes.k.nodeValue] = item.attributes.v.nodeValue;
        }
        return tags;
    }

    function getMembers(obj) {
        var elems = obj.getElementsByTagName('member'),
            members = new Array(elems.length);

        for (var i = 0, l = elems.length; i < l; i++) {
            members[i] = {
                id: elems[i].attributes.type.nodeValue[0] + elems[i].attributes.ref.nodeValue,
                type: elems[i].attributes.type.nodeValue,
                role: elems[i].attributes.role.nodeValue
            };
        }
        return members;
    }

    function objectData(obj) {
        switch(obj.type) {
            case 'node': return nodeData(obj);
            case 'way': return wayData(obj);
            case 'relation': return relationData(obj);
        }
    }

    function nodeData(obj) {
        var o = { type: 'node', tags: getTags(obj) };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        if (o.lon && o.lat) {
            o.loc = [parseFloat(o.lon), parseFloat(o.lat)];
            delete o.lon; delete o.lat;
        }
        o.id = iD.Entity.id.fromOSM('node', o.id);
        return new iD.Node(o);
    }

    function wayData(obj) {
        var o = { type: 'way', nodes: getNodes(obj),
            tags: getTags(obj)
        };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        o.id = iD.Entity.id.fromOSM('way', o.id);
        return new iD.Way(o);
    }

    function relationData(obj) {
        var o = {
            type: 'relation', members: getMembers(obj),
            tags: getTags(obj)
        };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        o.id = iD.Entity.id.fromOSM('relation', o.id);
        return new iD.Relation(o);
    }

    function addWay(o, wparentsOf) {
        for (var i = 0; i < o.nodes.length; i++) {
            if (o.nodes[i]) {
                if (wparentsOf[o.nodes[i]] === undefined) {
                    wparentsOf[o.nodes[i]] = [];
                }
                wparentsOf[o.nodes[i]].push(o.id);
            }
        }
    }

    function addRelation(o, rparentsOf) {
        for (var i = 0; i < o.members.length; i++) {
            if (o.members[i].id) {
                if (rparentsOf[o.members[i].id] === undefined) {
                    rparentsOf[o.members[i].id] = [];
                }
                rparentsOf[o.members[i].id].push(o.id);
            }
        }
    }

    function parse(dom) {
        if (!dom || !dom.childNodes) return new Error('Bad request');
        var root = dom.childNodes[0];
        var entities = {};
        var rparentsOf = {},
            wparentsOf = {};

        var o, l;
        for (i = 0, l = root.childNodes.length; i < l; i++) {
            switch(root.childNodes[i].nodeName) {
                case 'node':
                    o = nodeData(root.childNodes[i]);
                    entities[o.id] = o;
                    break;
                case 'way':
                    o = wayData(root.childNodes[i]);
                    addWay(o, wparentsOf);
                    entities[o.id] = o;
                    break;
                case 'relation':
                    o = relationData(root.childNodes[i]);
                    addRelation(o, rparentsOf);
                    entities[o.id] = o;
                    break;
            }
        }

        var g = iD.Graph(entities);
        var i;

        for (i in wparentsOf) {
            if (entities[i]) {
                g.transient(entities[i], 'parentWays', d3.functor(wparentsOf[i]));
                g.transient(entities[i], 'poi', d3.functor(true));
            }
        }

        for (i in g.entities) {
            if (entities[i].type === 'node') {
                g.transient(entities[i], 'poi', d3.functor(false));
            }
        }

        for (i in rparentsOf) {
            if (entities[i]) g.transient(entities[i],
                'parentRelations', d3.functor(rparentsOf[i]));
        }

        return g;
    }

    function authenticated() {
        return oauth.authenticated();
    }

    // Generate Changeset XML. Returns a string.
    connection.changesetJXON = function(tags) {
        return {
            osm: {
                changeset: {
                    tag: _.map(tags, function(value, key) {
                        return { '@k': key, '@v': value };
                    }),<commit_msg>Remove vestigial code<commit_after>iD.Connection = function() {

    var event = d3.dispatch('auth', 'load'),
        url = 'http://www.openstreetmap.org',
        connection = {},
        user = {},
        version,
        keys,
        inflight = {},
        loadedTiles = {},
        oauth = iD.OAuth().url(url);

    function bboxUrl(b) {
        return url + '/api/0.6/map?bbox=' + [b[0][0],b[1][1],b[1][0],b[0][1]];
    }

    function bboxFromAPI(box, tile, callback) {
        function done(err, parsed) {
             loadedTiles[tile.toString()] = true;
             delete inflight[tile.toString()];
             callback(err, parsed);
         }
         inflight[tile.toString()] = loadFromURL(bboxUrl(box), done);
    }

    function loadFromURL(url, callback) {
        function done(dom) {
            return callback(null, parse(dom));
        }
        return d3.xml(url).get().on('load', done);
    }

    function getNodes(obj) {
        var nelems = obj.getElementsByTagName('nd'), nodes = new Array(nelems.length);
        for (var i = 0, l = nelems.length; i < l; i++) {
            nodes[i] = 'n' + nelems[i].attributes.ref.nodeValue;
        }
        return nodes;
    }

    function getTags(obj) {
        var tags = {}, tagelems = obj.getElementsByTagName('tag');
        for (var i = 0, l = tagelems.length; i < l; i++) {
            var item = tagelems[i];
            tags[item.attributes.k.nodeValue] = item.attributes.v.nodeValue;
        }
        return tags;
    }

    function getMembers(obj) {
        var elems = obj.getElementsByTagName('member'),
            members = new Array(elems.length);

        for (var i = 0, l = elems.length; i < l; i++) {
            members[i] = {
                id: elems[i].attributes.type.nodeValue[0] + elems[i].attributes.ref.nodeValue,
                type: elems[i].attributes.type.nodeValue,
                role: elems[i].attributes.role.nodeValue
            };
        }
        return members;
    }

    function objectData(obj) {
        switch(obj.type) {
            case 'node': return nodeData(obj);
            case 'way': return wayData(obj);
            case 'relation': return relationData(obj);
        }
    }

    function nodeData(obj) {
        var o = { type: 'node', tags: getTags(obj) };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        if (o.lon && o.lat) {
            o.loc = [parseFloat(o.lon), parseFloat(o.lat)];
            delete o.lon; delete o.lat;
        }
        o.id = iD.Entity.id.fromOSM('node', o.id);
        return new iD.Node(o);
    }

    function wayData(obj) {
        var o = { type: 'way', nodes: getNodes(obj),
            tags: getTags(obj)
        };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        o.id = iD.Entity.id.fromOSM('way', o.id);
        return new iD.Way(o);
    }

    function relationData(obj) {
        var o = {
            type: 'relation', members: getMembers(obj),
            tags: getTags(obj)
        };
        for (var i = 0, l = obj.attributes.length; i < l; i++) {
            o[obj.attributes[i].nodeName] = obj.attributes[i].nodeValue;
        }
        o.id = iD.Entity.id.fromOSM('relation', o.id);
        return new iD.Relation(o);
    }

    function parse(dom) {
        if (!dom || !dom.childNodes) return new Error('Bad request');
        var root = dom.childNodes[0];
        var entities = {};

        var i, o, l;
        for (i = 0, l = root.childNodes.length; i < l; i++) {
            switch(root.childNodes[i].nodeName) {
                case 'node':
                    o = nodeData(root.childNodes[i]);
                    entities[o.id] = o;
                    break;
                case 'way':
                    o = wayData(root.childNodes[i]);
                    entities[o.id] = o;
                    break;
                case 'relation':
                    o = relationData(root.childNodes[i]);
                    entities[o.id] = o;
                    break;
            }
        }

        return iD.Graph(entities);
    }

    function authenticated() {
        return oauth.authenticated();
    }

    // Generate Changeset XML. Returns a string.
    connection.changesetJXON = function(tags) {
        return {
            osm: {
                changeset: {
                    tag: _.map(tags, function(value, key) {
                        return { '@k': key, '@v': value };
                    }),
{'fraction_non_alphanumeric': 0.1490060015003751, 'fraction_numerical': 0.00450112528132033, 'mean_word_length': 1.5459536882310814, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '5961066', 'n_tokens_mistral': 3418, 'n_tokens_neox': 3300, 'n_words': 674}