forked from Apsu/layout_generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_release.py
67 lines (51 loc) · 1.62 KB
/
make_release.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
from itertools import permutations
from os import path
import json
from glob import glob
from random import choice
def path_to_language(path: str):
return path.split("\\")[-1].split(".")[0]
def load_json(path: str):
with open(path, 'r', encoding='utf-8') as f:
return json.load(f)
def doubles_for_lang(language: str):
bigrams = load_json(f"static/language_data/{language}.json")['bigrams']
res = 0
for b, f in bigrams.items():
if b[0] == b[1]:
res += f
return res * 100
def check_doubles(path: str):
l = path_to_language(path)
print(f"{l:-<16}: {doubles_for_lang(l)}%")
def filterPossibilities(p: str):
c1, c2 = p[0], p[1]
if c1 == "a":
return c2 == "e"
elif c1 == "e":
return c2 == "a" or c2 == "i"
elif c1 == "i":
return c2 != "i"
elif c1 == "o":
return c2 == "i" or c2 == "u"
else:
return c2 == "a"
class Solution:
def countVowelPermutation(self, n: int) -> int:
pos = "aeiou"
perms = (p for p in permutations(pos, n) if filterPossibilities(p))
length = 0
for _ in perms:
length += 1
return length % (10**9 + 7)
def main():
print("doubles for each lanugage is:")
# for p in glob("static/language_data/*.json"):
# check_doubles(p)
e450k = open('450k.txt', 'r', encoding='utf8').read().split()
res = [choice(e450k) for _ in range(100_000_000)]
open('450k_corpus.txt', 'w+', encoding='utf8').write(" ".join(res))
# print(path.isdir("../generator_release"))
if __name__ == "__main__":
s = Solution()
s.countVowelPermutation(3)