<commit_before>import xml.etree.ElementTree as ET
import xml.dom.minidom
from topology import *

def parseFile(filename):
    return parseTree(ET.parse(filename))
    
def parseString(data):
    return parseTree(ET.fromstring(data))

def parseTree(tree):
    # Get XML Tree root and initialize topology
    root = tree.getroot()
    t = Topology()
 
    # Populate Edges
    edges = root.find("edges").findall("edge")
    print "Num Edges Detected: %d"%len(edges)
    for edge in edges:
        altitude = int(edge.attrib["altitude"].strip())
        rank = int(edge.attrib["rank"].strip())
        e = Edge(t,altitude,rank)

   
    # Populate Vertices
    vertices = root.find("vertices").findall("vertex")
    print "Num Vertices Detected: %d"%len(vertices)
    for vertex in vertices:
        index = int(vertex.attrib['index'].strip())
        v = Vertex(t,index)

        # Make connections
        for collector in vertex.find("collectors").findall("collector"):
            order = int(collector.attrib["order"].strip())
            altitude = int(collector.attrib["altitude"].strip())

            #TODO Handle case in which we read in from multiple directions
#             if order in v.collectors:
#                 v.collectors[order]
            v.collectors[order] = t.edges[altitude]

        for emitter in vertex.find("emitters").findall("emitter"):
            order = int(emitter.attrib["order"].strip())
            altitude = int(emitter.attrib["altitude"].strip())
            #TODO Handle case in which we output in multiple directions
#             if order in v.emitters:
#                 v.emitters[order]
            v.emitters[order] = t.edges[altitude]

<commit_msg>[db] cleans up whitespace in parser<commit_after>import xml.etree.ElementTree as ET
import xml.dom.minidom
from topology import *

def parseFile(filename):
    return parseTree(ET.parse(filename))
    
def parseString(data):
    return parseTree(ET.fromstring(data))

def parseTree(tree):
    # Get XML Tree root and initialize topology
    root = tree.getroot()
    t = Topology()
 
    # Populate Edges
    edges = root.find("edges").findall("edge")
    print "Num Edges Detected: %d"%len(edges)
    for edge in edges:
        altitude = int(edge.attrib["altitude"].strip())
        rank = int(edge.attrib["rank"].strip())
        e = Edge(t,altitude,rank)

   
    # Populate Vertices
    vertices = root.find("vertices").findall("vertex")
    print "Num Vertices Detected: %d"%len(vertices)
    for vertex in vertices:
        index = int(vertex.attrib['index'].strip())
        v = Vertex(t,index)

        # Make edge connections to this vertex
        for collector in vertex.find("collectors").findall("collector"):
            order = int(collector.attrib["order"].strip())
            altitude = int(collector.attrib["altitude"].strip())
            v.collectors[order] = t.edges[altitude]

        for emitter in vertex.find("emitters").findall("emitter"):
            order = int(emitter.attrib["order"].strip())
            altitude = int(emitter.attrib["altitude"].strip())
            v.emitters[order] = t.edges[altitude]

{'fraction_non_alphanumeric': 0.1320574162679426, 'fraction_numerical': 0.0, 'mean_word_length': 2.8197320341047503, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4681918', 'n_tokens_mistral': 943, 'n_tokens_neox': 925, 'n_words': 216}