-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (51 loc) · 1.72 KB
/
main.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
import asyncio
import json
from utils import frequency
f = open("langs.json", "r")
json = json.loads(f.read())
freq = frequency("textStatIn.txt")
async def compare(language, frequency):
total = 0
for letter in json[language]:
if letter not in frequency:
frequency[letter] = 0
total += abs(frequency[letter] - float(json[language][letter]))
return total
loop = asyncio.get_event_loop()
langs = [
"English",
"French",
"German",
"Spanish",
"Portuguese",
"Esperanto",
"Italian",
"Turkish",
"Swedish",
"Polish",
"Dutch",
"Danish",
"Icelandic",
"Finnish",
"Czech"
]
tasks = [asyncio.ensure_future(compare("English", freq)),
asyncio.ensure_future(compare("French", freq)),
asyncio.ensure_future(compare("German", freq)),
asyncio.ensure_future(compare("Spanish", freq)),
asyncio.ensure_future(compare("Portuguese", freq)),
asyncio.ensure_future(compare("Esperanto", freq)),
asyncio.ensure_future(compare("Italian", freq)),
asyncio.ensure_future(compare("Turkish", freq)),
asyncio.ensure_future(compare("Swedish", freq)),
asyncio.ensure_future(compare("Polish", freq)),
asyncio.ensure_future(compare("Dutch", freq)),
asyncio.ensure_future(compare("Danish", freq)),
asyncio.ensure_future(compare("Icelandic", freq)),
asyncio.ensure_future(compare("Finnish", freq)),
asyncio.ensure_future(compare("Czech", freq))
]
a = loop.run_until_complete(asyncio.gather(*tasks))
print(a)
print("Lingua rilevata: " + str(langs[a.index(min(a))]) + ", percentuale: " + str(min(a)))
loop.close()