File size: 1,436 Bytes
e192c17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from os.path import join, dirname
from underthesea.file_utils import DATASETS_FOLDER
import random

random.seed(10)
text_file = join(DATASETS_FOLDER, "VNESES", "VNESEScorpus.txt")
with open(text_file) as f:
    lines = f.read().splitlines()
NUM_LONG_TOKENS = 50
NUM_SHORT_TOKENS = 20
NUM_MAX_TOKENS = 200


def longline_conditions(line):
    if len(line) < NUM_LONG_TOKENS or len(line) > NUM_MAX_TOKENS:
        return False
    if not (line[0].isupper() and line[-1] == "."):
        return False
    return True


long_lines = [line for line in lines if longline_conditions(line)]
print("Short lines", len(long_lines))


def shortline_conditions(line):
    if len(line) < NUM_SHORT_TOKENS:
        return False
    if len(line) > NUM_LONG_TOKENS:
        return False
    if not line[0].isupper():
        return False
    return True


short_lines = [line for line in lines if shortline_conditions(line)]
print("Short lines", len(short_lines))

print("Long lines", len(long_lines))
print("Short lines", len(short_lines))

pwd = dirname(__file__)
tmp = join(pwd, "data")
corpus_file = join(tmp, "UTS_Text_v1.txt")

with open(corpus_file, "w") as f:
    lines = long_lines + short_lines
    lines = lines[:1000]
    content = "\n".join(lines)
    f.write(content)

with open(join(tmp, "large", "train.txt"), "w") as f:
    lines = long_lines + short_lines
    lines = lines[:100000]
    content = "\n".join(lines)
    f.write(content)