<commit_before>#!/usr/bin/python

# import xml.sax
from xml.dom.minidom import parse
import xml.dom.minidom
import sys
import hashlib
import json
import os

# try:
#       from bs4 import BeautifulSoup
#     except ImportError:
#       try:
#         from BeautifulSoup import BeautifulSoup
#       except ImportError:
#         print "BeautifulSoup not present."
#         sys.exit()

nodes = {}
edges = []
node_count = 0;
edge_count = 0;

NODEFILE = "nodes.json"
EDGEFILE = "edges.json"
GML = "data.gml"

def hashString(data):
    data = data.encode('ascii',errors='ignore')
    data = str(data)
    return hashlib.md5(data).hexdigest()

def saveNodes2Json():
    with open(NODEFILE, 'w') as f:
        json.dump(nodes, f)
    return True;

def saveEdges2Json():
    with open(EDGEFILE, 'w') as f:
        json.dump(edges, f)
    return True;

def save2GML():
    f = open(GML, 'w')
    f.write("graph" + '\n')
    f.write("[" + '\n')
    for n in nodes:
        n = nodes[n]
        f.write('  node' + '\n')
        f.write('  [' + '\n')
        if n.type == 1:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    name '+str(n.name) + '\n')
        elif n.type == 2:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    title '+str(n.title.encode('ascii',errors='ignore')) + '\n')
            f.write('    year '+str(n.year) + '\n')
        elif n.type == 3:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    title '+str(n.title.encode('ascii',errors='ignore')) + '\n')
        f.write('  ]' + '\n')
    for e in edges:
        f.write('  edge' + '\n')
        f.write('  [' + '\n')
        f.write('    ' + str(e[0]) + '\n')
        f.write('    ' +str(e[1]) + '\n')
        f.write('  ]' + '\n')
    f.write("]")
    f.close()
# def saveNodes2GML():
#     with open(NODEFILE, 'w') as f:
#         json.dump(nodes, f)
#     return True;

# def saveEdges2GML():
#     with open(EDGEFILE, 'w') as f:
#         json.dump(edges, f)
#     return True;

class Author():
    def __init__(self):
        self.type = 1
        self.id = ""
        self.name = ""
<commit_msg>added source and target labels before edge members, added quotation marks around names and titles, changed quotation marks in these strings to single quotes.<commit_after>#!/usr/bin/python

# import xml.sax
from xml.dom.minidom import parse
import xml.dom.minidom
import sys
import hashlib
import json
import os
import re

# try:
#       from bs4 import BeautifulSoup
#     except ImportError:
#       try:
#         from BeautifulSoup import BeautifulSoup
#       except ImportError:
#         print "BeautifulSoup not present."
#         sys.exit()

nodes = {}
edges = []
node_count = 0;
edge_count = 0;

NODEFILE = "nodes.json"
EDGEFILE = "edges.json"
GML = "data.gml"

def hashString(data):
    data = data.encode('ascii',errors='ignore')
    data = str(data)
    return hashlib.md5(data).hexdigest()

def saveNodes2Json():
    with open(NODEFILE, 'w') as f:
        json.dump(nodes, f)
    return True;

def saveEdges2Json():
    with open(EDGEFILE, 'w') as f:
        json.dump(edges, f)
    return True;

def save2GML():
    f = open(GML, 'w')
    f.write("graph" + '\n')
    f.write("[" + '\n')
    for n in nodes:
        n = nodes[n]
        f.write('  node' + '\n')
        f.write('  [' + '\n')
        if n.type == 1:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    name \"'+str(n.name) + '\"\n')
        elif n.type == 2:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    title \"'+str(n.title.encode('ascii',errors='ignore')).replace("\"", "\'") + '\"\n')
            f.write('    year '+str(n.year) + '\n')
        elif n.type == 3:
            f.write('    id '+n.id + '\n')
            f.write('    type '+str(n.type) + '\n')
            f.write('    title \"'+str(n.title.encode('ascii',errors='ignore')).replace("\"", "\'") + '\"\n')
        f.write('  ]' + '\n')
    for e in edges:
        f.write('  edge' + '\n')
        f.write('  [' + '\n')
        f.write('    source ' + str(e[0]) + '\n')
        f.write('    target ' +str(e[1]) + '\n')
        f.write('  ]' + '\n')
    f.write("]")
    f.close()
# def saveNodes2GML():
#     with open(NODEFILE, 'w') as f:
#         json.dump(nodes, f)
#     return True;

# def saveEdges2GML():
#     with open(EDGEFILE, 'w') as f:
#         json.dump(edges, f)
#     return True;

class Author():
    def __init__(self):
        self.type = 1
        self.id = ""
        self.name = ""

{'fraction_non_alphanumeric': 0.1918238993710692, 'fraction_numerical': 0.006289308176100629, 'mean_word_length': 1.9432449105490437, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '5670350', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1711, 'n_words': 423}