示例#1
0
def create_database_from_csv(csv_filename,
                             dump_filename,
                             phrase_size,
                             debug_mode=False):
    start = datetime.datetime.now()
    print('Criando sql: ', dump_filename)
    db = DB(debug=debug_mode,
            path='',
            filename=dump_filename[:-4],
            run_on_ram=True)
    with open(csv_filename, newline='',
              encoding='utf-8-sig') as csvfile:  # lendo o csv
        reader = csv.reader(csvfile, delimiter=";", quoting=csv.QUOTE_NONE)
        for row in reader:  # para cada linha
            t = Text(str.split(str.upper(row[1])), row[0])  # cria um Text
            if t:
                t.build_phrases(phrase_size)
                if debug_mode:
                    t.print_phrases()
                db.insert_text(t, debug_mode)
                del t
            else:
                return -100
    end = datetime.datetime.now()
    print('Começou: ' + start.strftime("%H:%M:%S"))
    print('Terminou: ' + end.strftime("%H:%M:%S"))
    print('Delta: ' + str(end - start))

    return db
示例#2
0
def validation_train(report_dir, source_name):
    line_count = 0
    # inicio do treino ===============================
    start = datetime.datetime.now()
    db = DB(report_dir + "/", "database", debug=False, run_on_ram=True)
    print(report_dir)
    with open(source_name, newline='',
              encoding='utf-8-sig') as csvfile:  # lendo o csv
        reader = csv.reader(csvfile, delimiter=";",
                            quoting=csv.QUOTE_NONE)  # leitura do arquivo
        for row in reader:  # para cada linha
            line_count = line_count + 1
            print(str(line_count))
            t = Text(str.split(str.upper(row[1])), row[0])  # cria um Text
            if t:
                t.build_phrases(3)
                #  t.print_phrases()
                db.insert_text(t, False)
                del t
            else:
                return -100
    end = datetime.datetime.now()
    print('Começou: ' + start.strftime("%H:%M:%S"))
    print('Terminou: ' + end.strftime("%H:%M:%S"))
    print('Delta: ' + str(end - start))
示例#3
0
def train():
    default = 'database/treino.csv'
    a = input('Nome default da tabela de Treino: ' + default +
              '\n1 - Continuar'
              '\n2 - Mudar'
              '\nSelecione uma opção: ')
    if str.upper(a) in {'S', 'Y', '1'}:
        print('Continuando com a a tabela: ' + default)
    else:
        i = 1
        filenames = []
        for f in os.listdir(os.path.join(
                Path().absolute(),
                "database")):  # lendo todos os arquivos .csv em database/
            if f.endswith(".csv"):
                print(str(i) + ' - ' + f)
                filenames.append('database/' + f)
                i += 1

        while True:
            a = input('Digite o numero da tabela que deseja usar: ')
            a = int(a) - 1
            if a == -1:
                exit(0)
            try:
                default = filenames[a]
                break
            except IndexError:
                print('Numero inválido. Se deseja sair digite 0.')

    a = input('Debug? S/N: ')
    debug_mode = False
    if str.upper(a) in {'S', 'Y', '1'}:
        debug_mode = True

    start = datetime.datetime.now()
    db = DB(debug=debug_mode, filename='basefull', run_on_ram=True)
    with open(default, newline='',
              encoding='utf-8-sig') as csvfile:  # lendo o csv
        reader = csv.reader(csvfile, delimiter=";", quoting=csv.QUOTE_NONE)
        for row in reader:  # para cada linha
            t = Text(str.split(str.upper(row[1])), row[0])  # cria um Text
            if t:
                t.build_phrases(3)
                if debug_mode:
                    t.print_phrases()
                db.insert_text(t, debug_mode)
                del t
            else:
                return -100

    end = datetime.datetime.now()
    print('Começou: ' + start.strftime("%H:%M:%S"))
    print('Terminou: ' + end.strftime("%H:%M:%S"))
    print('Delta: ' + str(end - start))
示例#4
0
def train(file, phrase_size):
    db = DB(path='', filename=file, run_on_ram=True)
    with open(file, newline='', encoding='utf-8-sig') as csvfile:  # lendo o csv
        reader = csv.reader(csvfile, delimiter=";", quoting=csv.QUOTE_NONE)
        for row in reader:  # para cada linha
            t = Text(str.split(str.upper(row[1])), row[0])  # cria um Text
            if t:
                t.build_phrases(phrase_size)
                db.insert_text(t)
                del t
            else:
                return -100