<commit_before>"""Main"""

import argparse

import basepart
import ko

def main():
    """Main procedure of application"""
    # Parse arguments
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument( \
        'language', \
        choices=('ko', ), \
        help='set the valid language' \
        )
    arg_parser.add_argument( \
        'repeat', \
        type=int, \
        nargs='?', \
        default=1, \
        help='set the number of repetition' \
        )
    arg_parser.add_argument( \
        'length', \
        type=int, \
        nargs='?', \
        help='set the length of name' \
        )
    arg_parser.add_argument( \
        '-f', '--fresh', \
        action='store_true', \
        help='make the application return fresh result' \
        )
    arg_parser.add_argument( \
        '-p', '--print', \
        action='store_true', \
        help='print the result' \
        )
    arg_parser.add_argument( \
        '-s', '--storage', \
        default=basepart.DEFAULT_STORAGE, \
        help='set the path of result file' \
        )
    arg = arg_parser.parse_args()

    # Language-specified modification
    if arg.language == 'ko':
        if arg.length is None:
            arg.length = 2
        num_total_characters = ko.ComposerElementKorean.num_character_recommend ** 2

    # General modification
    if arg.length <= 0:
        raise basepart.NamingLibException('Wrong name length', arg.length)
    if arg.repeat <= 0:
        raise basepart.NamingLibException('Wrong repeat number', arg.repeat)

    # Open file
    file_stream = open(arg.storage, 'a+')
    file_stream.seek(0)
    list_name_original = file_stream.readlines()
    list_name_added = list()

    # Generate and store
    idx_generated = 0
    while idx_generated < arg.repeat:
        result = list()

        if arg.language == 'ko':
            for _ in range(arg.length):
                result.append(ko.ComposerElementKorean( \
                    initial=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[0]), \
                    medial=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[1]), \
                    final=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[2]) \
                    ).compose() \
                )
        result = ''.join(result)

        if arg.fresh and (result + '\n') in list_name_original + list_name_added:
            if len(list_name_original + list_name_added) >= \
                num_total_characters:
                raise basepart.NamingLibException('generated all of the eligible names')
        else:
            list_name_added.append(result + '\n')
            if arg.print:
                print(result, end='')
            idx_generated += 1

    # Write to file and close file
    file_stream.writelines(list_name_added)
    file_stream.close()

if __name__ == '__main__':
    main()<commit_msg>delete end=''<commit_after>"""Main"""

import argparse

import basepart
import ko

def main():
    """Main procedure of application"""
    # Parse arguments
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument( \
        'language', \
        choices=('ko', ), \
        help='set the valid language' \
        )
    arg_parser.add_argument( \
        'repeat', \
        type=int, \
        nargs='?', \
        default=1, \
        help='set the number of repetition' \
        )
    arg_parser.add_argument( \
        'length', \
        type=int, \
        nargs='?', \
        help='set the length of name' \
        )
    arg_parser.add_argument( \
        '-f', '--fresh', \
        action='store_true', \
        help='make the application return fresh result' \
        )
    arg_parser.add_argument( \
        '-p', '--print', \
        action='store_true', \
        help='print the result' \
        )
    arg_parser.add_argument( \
        '-s', '--storage', \
        default=basepart.DEFAULT_STORAGE, \
        help='set the path of result file' \
        )
    arg = arg_parser.parse_args()

    # Language-specified modification
    if arg.language == 'ko':
        if arg.length is None:
            arg.length = 2
        num_total_characters = ko.ComposerElementKorean.num_character_recommend ** 2

    # General modification
    if arg.length <= 0:
        raise basepart.NamingLibException('Wrong name length', arg.length)
    if arg.repeat <= 0:
        raise basepart.NamingLibException('Wrong repeat number', arg.repeat)

    # Open file
    file_stream = open(arg.storage, 'a+')
    file_stream.seek(0)
    list_name_original = file_stream.readlines()
    list_name_added = list()

    # Generate and store
    idx_generated = 0
    while idx_generated < arg.repeat:
        result = list()

        if arg.language == 'ko':
            for _ in range(arg.length):
                result.append(ko.ComposerElementKorean( \
                    initial=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[0]), \
                    medial=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[1]), \
                    final=basepart.IncludeList(ko.ComposerElementKorean.character_recommend[2]) \
                    ).compose() \
                )
        result = ''.join(result)

        if arg.fresh and (result + '\n') in list_name_original + list_name_added:
            if len(list_name_original + list_name_added) >= \
                num_total_characters:
                raise basepart.NamingLibException('generated all of the eligible names')
        else:
            list_name_added.append(result + '\n')
            if arg.print:
                print(result)
            idx_generated += 1

    # Write to file and close file
    file_stream.writelines(list_name_added)
    file_stream.close()

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.11489726027397261, 'fraction_numerical': 0.003767123287671233, 'mean_word_length': 1.9907834101382489, 'pattern_counts': {'":': 0, '<': 9, '<?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': '2672495', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1692, 'n_words': 353}