forked from kentonl/e2e-coref
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_char_vocab.py
executable file
·29 lines (25 loc) · 953 Bytes
/
get_char_vocab.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import json
import io
def get_char_vocab(input_filenames, output_filename):
vocab = set()
for filename in input_filenames:
with open(filename) as f:
for line in f.readlines():
for sentence in json.loads(line)["sentences"]:
for word in sentence:
vocab.update(word)
vocab = sorted(list(vocab))
with io.open(output_filename, mode="w", encoding="utf8") as f:
for char in vocab:
f.write(char)
f.write(u"\n")
print("Wrote {} characters to {}".format(len(vocab), output_filename))
def get_char_vocab_language(language):
get_char_vocab(["{}.{}.jsonlines".format(partition, language) for partition in ("train", "dev", "test")], "char_vocab.{}.txt".format(language))
get_char_vocab_language("english")
get_char_vocab_language("chinese")
get_char_vocab_language("arabic")