<commit_before>#!/usr/bin/python

import xml.sax, os, errno, urllib, urllib2, sys
from xml.sax.handler import ContentHandler

# Suggested by http://stackoverflow.com/q/600268/223092
def mkdir_p(path):
    try:
        os.makedirs(path)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise

class Node:

    """Represents an OSM node as returned via the Overpass API"""

    def __init__(self, node_id, latitude, longitude):
        self.node_id = node_id
        self.lat = latitude
        self.lon = longitude
        self.tags = {}

    def get_element_name(self):
        return 'node'

    def __eq__(self, other):
        if type(other) is type(self):
            return self.node_id == other.node_id
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def pretty(self, indent=0):
        i = u" "*indent
        result = i + u"node (%s) lat: %s, lon: %s" % (self.node_id, self.lat, self.lon)
        for k, v in sorted(self.tags.items()):
            result += u"\n%s  %s => %s" % (i, k, v)
        return result

    def __hash__(self):
        return hash(self.node_id)

    def __repr__(self):
        return "node(%s) lat: %s, lon: %s" % (self.node_id, self.lat, self.lon)

class Way:

    """Represents an OSM way as returned via the Overpass API"""

    def __init__(self, way_id, nodes=None):
        self.way_id = way_id
        self.nodes = nodes or []
        self.tags = {}

    def get_element_name(self):
        return 'way'

    def __eq__(self, other):
        if type(other) is type(self):
            return self.way_id == other.way_id
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def pretty(self, indent=0):
        i = u" "*indent
        result = i + u"way (%s)" % (self.way_id)
        for k, v in sorted(self.tags.items()):
            result += u"\n%s  %s => %s" % (i, k, v)
        for node in self.nodes:
            result += u"\n" + node.pretty(indent + 2)
        return result
<commit_msg>Add a helper method returning a (longitude, latitude) tuple<commit_after>#!/usr/bin/python

import xml.sax, os, errno, urllib, urllib2, sys
from xml.sax.handler import ContentHandler

# Suggested by http://stackoverflow.com/q/600268/223092
def mkdir_p(path):
    try:
        os.makedirs(path)
    except OSError as exc:
        if exc.errno == errno.EEXIST:
            pass
        else:
            raise

class Node:

    """Represents an OSM node as returned via the Overpass API"""

    def __init__(self, node_id, latitude, longitude):
        self.node_id = node_id
        self.lat = latitude
        self.lon = longitude
        self.tags = {}

    def get_element_name(self):
        return 'node'

    def __eq__(self, other):
        if type(other) is type(self):
            return self.node_id == other.node_id
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def pretty(self, indent=0):
        i = u" "*indent
        result = i + u"node (%s) lat: %s, lon: %s" % (self.node_id, self.lat, self.lon)
        for k, v in sorted(self.tags.items()):
            result += u"\n%s  %s => %s" % (i, k, v)
        return result

    def __hash__(self):
        return hash(self.node_id)

    def __repr__(self):
        return "node(%s) lat: %s, lon: %s" % (self.node_id, self.lat, self.lon)

    def lon_lat_tuple(self):
        return (self.lon, self.lat)

class Way:

    """Represents an OSM way as returned via the Overpass API"""

    def __init__(self, way_id, nodes=None):
        self.way_id = way_id
        self.nodes = nodes or []
        self.tags = {}

    def get_element_name(self):
        return 'way'

    def __eq__(self, other):
        if type(other) is type(self):
            return self.way_id == other.way_id
        return False

    def __ne__(self, other):
        return not self.__eq__(other)

    def pretty(self, indent=0):
        i = u" "*indent
        result = i + u"way (%s)" % (self.way_id)
        for k, v in sorted(self.tags.items()):
            result += u"\n%s  %s => %s" % (i, k, v)
        for node in self.nodes:
            result += u"\n" + node.pretty(indent + 2)
        return result

{'fraction_non_alphanumeric': 0.1281630740393627, 'fraction_numerical': 0.007497656982193065, 'mean_word_length': 2.0957215373459026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6153989', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1409, 'n_words': 409}