<commit_before>#!/usr/bin/python
from __future__ import print_function
from pt_data import masses
val = ""
multiples = {}


def add_commas(orig):
    with_Commas = ""
    for i in range(len(orig) - 1):
        with_Commas += orig[i]
        if orig[i + 1].isupper():
            with_Commas += ","
    with_Commas += orig[-1]
    return with_Commas


# adds comma markers so rest of the functions can work
def add_markers(val):
    if val.find('-') != -1:
        val = val.replace('-', ',')
    if val.find(' ') != -1:
        val = val.replace(' ', ',')
    if ',' not in val:
        val = add_commas(val)
    return val


# adds coefficients and symbol to the multiples dictionary
def add(mult, build):
    global multiples
    com = 0
    for i in range(len(build) - 1, -1, -1):
        if build[i] == ',':
            com = i
            break
    if com == 0:
        symb = build[com:]
    else:
        symb = build[com + 1:]
    multiples[symb] = mult


# returns the complete coeficcient given the starting number
def find_num(i, val):
    if val[i].isalpha() or val[i] == ',':
        return val[i]
    comma = val.find(",", i)
    if comma != -1:
        num = val[i:comma]
    else:
        num = val[i:]
    return num


# returns a string with no coefficients and builds the multiples
# dictionary
def strip_coeff(val):
    build = ""
    i = 0
    while i < len(val):
        if val[i] == ',':
            build += val[i]
        elif not val[i].isalpha():
            num = int(find_num(i, val))
            add(num, build)
        else:
            build += val[i]
        i += len(find_num(i, val))
    if len(build) == 0:
        return ""
    return build


def calc_single_element(val):<commit_msg>Added functionality to work with parenthesis<commit_after>#!/usr/bin/python
from __future__ import print_function
from pt_data import masses
val = ""
multiples = {}


def add_commas(orig):
    with_Commas = ""
    for i in range(len(orig) - 1):
        with_Commas += orig[i]
        if orig[i + 1].isupper():
            with_Commas += ","
    with_Commas += orig[-1]
    return with_Commas


# returns the complete coeficcient given the starting number
def find_num(i, val):
    if val[i].isalpha() or val[i] == ',':
        return val[i]
    count = i
    while(count < len(val) and not val[count].isalpha() and val[count] != ","):
        count += 1
    if count >= len(val):
        return val[i:]
    return val[i:count]


def distribute(val, num):
    build = ""
    sub = 1
    for i in range(len(val)):
        if not val[i].isalpha():
            sub = int(find_num(i, val))
            sub *= num
            build += str(sub)
            i += len(find_num(i, val)) - 1
        elif i+1 >= len(val) or (val[i+1].isupper()):
            sub = 1*num
            build += val[i]
            build += str(sub)
            i += len(find_num(i, val))
            sub = 1
        else:
            build += val[i]
    return build


def distrib_parenth(val):
    between = ""
    op = val.find('(')
    num = 1
    while(op != -1):
        close = val.find(')', op)
        between = val[op+1:close]
        if close+1 < len(val) and not val[close+1].isalpha() and val[close+1] != '':
            num = int(val[close+1])
            val = val[:op] + distribute(between, num) + val[close+2:]
        else:
            val = val[:op] + distribute(between, num) + val[close+1:]
        op = val.find('(', op+1)
        num = 1
    print(val)
    return val


# adds comma markers so rest of the functions can work
def add_markers(val):
    if "(" in val and ")" in val:
        val = distrib_parenth(val)
    if ',' not in val:
        val = add_commas(val)
    return val


# adds coefficients and symbol to the multiples dictionary
def add(mult, build):
    global multiples
    com = 0
    for i in range(len(build) - 1, -1, -1):
        if build[i] == ',':
            com = i
            break
    if com == 0:
        symb = build[com:]
    else:
        symb = build[com + 1:]
    multiples[symb] = mult


# returns a string with no coefficients and builds the multiples
# dictionary
def strip_coeff(val):
    build = ""
    i = 0
    while i < len(val):
        if val[i] == ',':
            build += val[i]
        elif not val[i].isalpha():
            num = int(find_num(i, val))
            add(num, build)
        else:
            build += val[i]
        i += len(find_num(i, val))
    if len(build) == 0:
        return ""
    return build


def calc_single_element(val):
{'fraction_non_alphanumeric': 0.14130434782608695, 'fraction_numerical': 0.009538598047914819, 'mean_word_length': 1.9644970414201184, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5126836', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1498, 'n_words': 439}