30 lines
787 B
Python
30 lines
787 B
Python
import nltk
|
|
from nltk.corpus import brown
|
|
import json
|
|
|
|
comm = open("common_dict.json", "r")
|
|
common_data = json.load(comm)
|
|
comm.close()
|
|
|
|
ext = open("extended_dict.json", "r")
|
|
ext_data = json.load(ext)
|
|
ext.close()
|
|
|
|
common_array = []
|
|
extended_array = []
|
|
|
|
for k in common_data:
|
|
common_array.append(k)
|
|
for k in ext_data:
|
|
extended_array.append(k)
|
|
|
|
|
|
freqs = nltk.FreqDist([w.lower() for w in brown.words()])
|
|
common_sorted = sorted(common_array, key=lambda x: freqs[x.lower()], reverse=True)
|
|
extended_sorted = sorted(extended_array, key=lambda x: freqs[x.lower()], reverse=True)
|
|
|
|
file = open("common_dict.txt", "w")
|
|
file.write('\n'.join(str(line) for line in common_sorted))
|
|
file = open("extended_dict.txt", "w")
|
|
file.write('\n'.join(str(line) for line in extended_sorted))
|
|
file.close() |