-
Notifications
You must be signed in to change notification settings - Fork 0
/
frequency_list_2_teste.py
66 lines (37 loc) · 1.12 KB
/
frequency_list_2_teste.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
from collections import defaultdict
import nltk
from nltk.tokenize import word_tokenize
import re
import os
import sys
from pathlib import Path
def frequency_list():
while True:
try:
file_to_open =Path(input("\nPlease, insert your file path: "))
with open(file_to_open) as f:
freq = word_tokenize(f.read().lower())
break
except FileNotFoundError:
print("\nFile not found. Better try again")
except IsADirectoryError:
print("\nIncorrect Directory path.Try again")
with open ('Fr-dictionary2.txt') as fr:
dic = word_tokenize(fr.read().lower())
errors=[ ]
d=defaultdict(int)
for w in freq:
if w not in dic:
errors.append(w)
else:
d[w]+=1
for w in sorted(d, key=d.get):
print(w, d[w])
print("errors found:", errors)
frequency_list()
#count=frequency.get(word,0)
#frequency[word] = count+1
#print(errors)
#frequency_list=sorted(frequency.keys())
#for words in frequency_list:
#print (words, frequency[words])