-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_parse.py
executable file
·56 lines (45 loc) · 1.07 KB
/
04_parse.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
#!/usr/bin/env python3
import json
import os
import re
import sys
import subprocess
from tqdm import tqdm
from linktree import make_tree
def main():
freq = {}
with open('data/all-sentences.json', 'r') as f:
data = json.loads(f.read())
sentences = []
for n, sent in tqdm(enumerate(data['sentences'])):
s = ''
last_word = None
for word in sent:
s += ' '
s += word
#sys.stdout.write(' ')
#sys.stdout.write(word)
last_word = word
sentences.append(s)
#sys.stdout.write('\n\n')
trees = []
for s in tqdm(sentences):
if '"' in s:
continue
if ';' in s:
continue
if ':' in s:
continue
if '—' in s:
continue
if '!' in s:
continue
if 'beautifully' in s:
continue
tree = make_tree(s)
trees.append(tree)
with open('data/trees.json', 'w') as f:
f.write(json.dumps({
'trees': trees
}, indent=4))
main()