forked from iwangjian/ByteCup2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit_data.py
38 lines (30 loc) · 1.29 KB
/
commit_data.py
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
34
35
36
37
38
import os
import argparse
def process_decoded(args):
if not os.path.exists(args.result_dir):
os.mkdir(args.result_dir)
punct = ["/", "`", "+", "-", ";", "-lrb-", "-rrb-", "``", "|", "~", """]
for file in os.listdir(args.decode_dir):
file_path = os.path.join(args.decode_dir, file)
file_id = int(str(file).split('.')[0]) + 1
res_file = str(file_id) + '.txt'
res_path = os.path.join(args.result_dir, res_file)
temp = []
with open(file_path, 'r') as fr:
text = fr.read().strip()
data = text.split(" ")
for word in data:
if not word in punct:
temp.append(word)
with open(res_path, 'w', encoding='utf-8') as fw:
fw.write(" ".join(temp))
fw.write('\n')
print("Finished: %s" % args.result_dir)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Convert decoded files to commit files')
parser.add_argument('--decode_dir', action='store', required=True,
help='directory of decoded summaries')
parser.add_argument('--result_dir', action='store', required=True,
help='directory of submission')
args = parser.parse_args()
process_decoded(args)