<commit_before>#!/usr/bin/env python
# usage: ./renamer [data_directory]

import os, re

data_dir = "test" 

files = sorted(os.listdir(data_dir))
for a in files: 
    b = re.sub('_','',a, 1) 
    c = re.sub('_','.',b,1) 
    print "{0} ==> {1}".format(a,c) 
<commit_msg>implemented suffix substitution with integer increment<commit_after>#!/usr/bin/env python
# usage: ./renamer [data_directory]

import os, re
from collections import defaultdict

data_dir = "test" 

tally = defaultdict(int)
files = sorted(os.listdir(data_dir))
for a in files: 
    b = re.sub('_','',a, 1) 
    c = re.sub('_','.',b,1) 
    prefix = c.split('.')[0]
    tally[prefix] += 1 
    d =  prefix + "." + str(tally[prefix]-1)
    print "{0} ==> {1}".format(a,d) 
    os.rename( os.path.join(data_dir, a), os.path.join(data_dir,  d))
{'fraction_non_alphanumeric': 0.20148331273176762, 'fraction_numerical': 0.013597033374536464, 'mean_word_length': 3.550561797752809, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1809781', 'n_tokens_mistral': 336, 'n_tokens_neox': 320, 'n_words': 71}