-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_sentence_ids.py
43 lines (32 loc) · 1.24 KB
/
add_sentence_ids.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
39
40
41
42
43
#!/usr/bin/env python
#
# Author: (c) 2016 Vincent Kriz <kriz@ufal.mff.cuni.cz>
#
import sys
import logging
import argparse
# Logging.
from wheel.metadata import requires_to_requires_dist
logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', level=logging.DEBUG)
# Parse command line arguments.
parser = argparse.ArgumentParser()
parser.description = 'Add sentence IDs into the CoNLLU file.'
parser.add_argument('--input_file', required=True, help='an input file')
parser.add_argument('--output_file', required=True, help='an output file')
args = parser.parse_args()
sentence_counter = 0
with open(args.input_file, 'r') as fin:
with open(args.output_file, 'w') as fout:
sentence = []
for one_line in fin:
one_line = one_line.rstrip()
sentence.append(one_line)
if one_line == '':
sentence_counter += 1
if (sentence_counter % 10000) == 0:
logging.info('Processed %d sentences.', sentence_counter)
sent_id = 'en%09d' % sentence_counter
fout.write('# sent_id %s\n' % sent_id)
fout.write('\n'.join(sentence))
fout.write('\n')
sentence = []