<commit_before>""" Third step of the algorithm."""

import sys

# define a triple class ?
    
def getWords(t):
    """
        concatenate all strings of the node (in wordList)
    """
    l = t.wordList
    l.sort(key = lambda x: x[1]) 
    s = ''
    for w in l:
        s += ' ' + w[0]
    return s
    
def tripleProduce1(t,nodeToID,triplesBucket):
    """
        a -b-> c : ?A = ?C
    """
    assert t.parent != None
    for tr in triplesBucket:
        for i in range(0,3):
            if tr[i] == nodeToID[t]:
                tr[i] = nodeToID[t.parent]
    nodeToID[t] = nodeToID[t.parent]
    
def tripleProduce2(t,nodeToID,triplesBucket,suffix=''):
    """
        a -b-> c : a(?A,c)
        suffix: for prep_x
    """
    assert t.parent != None
    triplesBucket.append([nodeToID[t.parent],getWords(t.parent)+' '+suffix,getWords(t)])

def tripleProduce3(t,nodeToID,triplesBucket):
    """
        a -b-> c : c(?A,a)
    """
    assert t.parent != None
    triplesBucket.append([nodeToID[t.parent],getWords(t),getWords(t.parent)])
        
tripleMap = {
    'root'    : tripleProduce1,<commit_msg>modif<commit_after>""" Third step of the algorithm."""

import sys
    
def getWords(t):
    """
        concatenate all strings of the node (in wordList)
    """
    l = t.wordList
    l.sort(key = lambda x: x[1]) 
    s = ''
    for w in l:
        s += ' ' + w[0]
    return s
    
def tripleProduce1(t,nodeToID,triplesBucket):
    """
        a -b-> c : ?A = ?C
    """
    assert t.parent != None
    for tr in triplesBucket:
        for i in range(0,3):
            if tr[i] == nodeToID[t]:
                tr[i] = nodeToID[t.parent]
    nodeToID[t] = nodeToID[t.parent]
    
def tripleProduce2(t,nodeToID,triplesBucket,suffix=''):
    """
        a -b-> c : a(?A,c) is c is a leaf
                   a(?A,?C) otherwise
        suffix: for prep_x
    """
    assert t.parent != None
    if not t.child:
        triplesBucket.append([nodeToID[t.parent],getWords(t.parent)+' '+suffix,getWords(t)])
    else:
        triplesBucket.append([nodeToID[t.parent],getWords(t.parent)+' '+suffix,nodeToID[t]])

def tripleProduce3(t,nodeToID,triplesBucket):
    """
        a -b-> c : c(?A,a) is 
    """
    assert t.parent != None
    triplesBucket.append([nodeToID[t.parent],getWords(t),getWords(t.parent)])
        
tripleMap = {
    'root'    : tripleProduce1,
{'fraction_non_alphanumeric': 0.15998311523849726, 'fraction_numerical': 0.006753904601097509, 'mean_word_length': 2.2554945054945055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5613047', 'n_tokens_mistral': 895, 'n_tokens_neox': 873, 'n_words': 187}