<commit_before>import re
from parserTools.cleaner import *

separatorString = ".body"
regexFixUserMissingSpaces = r"((\))(\())" #adds a space between )( if it is replaced by "\\2 \\3"

def readFile(filename):#read a file or print an error
    try:
        file = open(filename)
    except IOError:
        print("ERROR - Unable to open file %s" % filename)
        exit()
    return file.read()

def separateHeadBody(text):
    parserHead = parserBody = ""
    parts = text.split(separatorString,1)  #separate head from body
    if len(parts)==2:
        parserHead = parts[0].strip("\n")
        parserBody = parts[1].strip("\n")
    else:
        parserBody = parts[0].strip("\n")
    return parserHead, parserBody

def inputTextToList(text, delimiter):
    temp = []
    for line in text.splitlines():
        parts = line.split(delimiter)
        for part in parts:
            temp.append(part)
    return temp

def parseTextToList(text):
    i = 0
    lines = text.splitlines()
    fullLines = []
    temp = ""
    while i < len(lines):
        if isLineComplete(temp):
            temp = re.sub(regexFixUserMissingSpaces, "\\2 \\3", temp, 0, re.MULTILINE)
            fullLines.append(removePunctuationSpaces(removeRedundantWhitespaces(temp)))
            temp =lines[i]
        else:
            temp+=lines[i]
        if i == len(lines) - 1 and isLineComplete(temp):
            temp = re.sub(regexFixUserMissingSpaces, "\\2 \\3", temp, 0, re.MULTILINE)
            fullLines.append(removePunctuationSpaces(removeRedundantWhitespaces(temp)))<commit_msg>utils improvements<commit_after>import re
from parserTools.cleaner import *

separatorString = ".body"
regexFixUserMissingSpaces = r"((\))(\())" #adds a space between )( if it is replaced by "\\2 \\3"

def readFile(filename):#read a file or print an error
    try:
        file = open(filename)
    except IOError:
        print("ERROR - Unable to open file %s" % filename)
        exit()
    temp = file.read()
    file.close()
    return temp
def separateHeadBody(text):
    parserHead = parserBody = ""
    parts = text.split(separatorString,1)  #separate head from body
    if len(parts)==2:
        parserHead = parts[0].strip("\n")
        parserBody = parts[1].strip("\n")
    else:
        parserBody = parts[0].strip("\n")
    return parserHead, parserBody

def inputTextToList(text, delimiter):
    temp = []
    for line in text.splitlines():
        parts = line.split(delimiter)
        for part in parts:
            temp.append(part)
    return temp

def parseTextToList(text):
    #replace ][ by ]\n[ to separate containers
    regex = r"\]\s*\["
    subst = "]\\n["
    text = re.sub(regex, subst, text, 0, re.MULTILINE)
    i = 0
    lines = text.splitlines()
    fullLines = []
    temp = ""
    while i < len(lines):
        if isLineComplete(temp):
            temp = re.sub(regexFixUserMissingSpaces, "\\2 \\3", temp, 0, re.MULTILINE)
            fullLines.append(removePunctuationSpaces(removeRedundantWhitespaces(temp)))
            temp =lines[i]
        else:
            temp+=lines[i]
        if i == len(lines) - 1 and isLineComplete(temp):
            temp = re.sub(regexFixUserMissingSpaces, "\\2 \\3", temp, 0, re.MULTILINE)
            fullLines.append(removePunctuationSpaces(removeRedundantWhitespaces(temp)))
{'fraction_non_alphanumeric': 0.1309739866908651, 'fraction_numerical': 0.009376890502117362, 'mean_word_length': 2.634065934065934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4186111', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1023, 'n_words': 261}