forked from s-celles/word_gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_map.py
36 lines (28 loc) · 854 Bytes
/
make_map.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import numpy as np
import re
import codecs
def lang_count():
filepath = 'input.txt'
count = np.zeros((256,256,256), dtype='int32')
res = []
print('...Please wait a bit while I process the data in ' + str(filepath) + '...')
with codecs.open(filepath, "r", "ISO-8859-1") as lines:
for l in lines:
# Split on white space or open parenthesis and keep the first string
l2 = re.split("[ ,\(]", l)[0]
l2 = l2 + "\n"
i = 0
j = 0
for k in [ord(c) for c in list(l2)]:
count[i, j, k] += 1
i = j
j = k
return count
def main():
count = lang_count()
count.tofile('counts.bin')
if __name__ == '__main__':
main()