-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsentence_segment.py
74 lines (52 loc) · 1.43 KB
/
sentence_segment.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Usage : python sentence_segment.py [path-to-eng-ascii-ile] [path-to-parallel-sumerian_file] [output_eng_file] [output_sum_file]
import os, re, sys
eng_file = sys.argv[1]
sum_file = sys.argv[2]
OUTPUT_ENG_FILE = sys.argv[3]
OUTPUT_SUM_FILE = sys.argv[4]
file1= [] # Store Eng transformed file as list of sentences/.
file2= [] # Store Sumerian transformed file as a list of sentences.
dot_numbers = [] # Keep track of dot numbers
# Function to process the sentence segmentation heuristic.
with open(eng_file, 'r') as f, open(sum_file, 'r') as g:
i=0
temp_file1 = []
temp_file2 = []
for line in f:
line = line.strip()
split_line = line.split()
if '.' not in split_line:
for item in split_line:
temp_file1.append(item)
i+=1
else:
for item in split_line:
temp_file1.append(item)
dot_numbers.append(i)
i+=1
sentence = ' '.join(temp_file1)
file1.append(sentence.strip())
temp_file1 = []
j=0
for line in g:
line = line.strip()
split_line = line.split()
if j in dot_numbers:
j+=1
for item in split_line:
temp_file2.append(item)
sentence = ' '.join(temp_file2)
file2.append(sentence.strip())
temp_file2 = []
else:
for item in split_line:
temp_file2.append(item)
j+=1
# Write to the new files
with open(OUTPUT_ENG_FILE, 'w+') as o, open(OUTPUT_SUM_FILE, 'w+') as p:
for item in file1:
o.write(item)
o.write('\n')
for item in file2:
p.write(item)
p.write('\n')