convert_format.py 950 字节
Newer Older
F
frankwhzhang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import sys


def convert_format(input, output):
    with open(input) as rf:
        with open(output, "w") as wf:
            last_sess = -1
            sign = 1
            i = 0
            for l in rf:
                i = i + 1
                if i == 1:
                    continue
                if (i % 1000000 == 1):
                    print(i)
                tokens = l.strip().split()
                if (int(tokens[0]) != last_sess):
                    if (sign):
                        sign = 0
                        wf.write(tokens[1] + " ")
                    else:
                        wf.write("\n" + tokens[1] + " ")
                    last_sess = int(tokens[0])
                else:
                    wf.write(tokens[1] + " ")


input = "rsc15_train_tr.txt"
output = "rsc15_train_tr_paddle.txt"
input2 = "rsc15_test.txt"
output2 = "rsc15_test_paddle.txt"
convert_format(input, output)
convert_format(input2, output2)