Corpus-Cypher-Executable/cce/necessary files/sorter.py

30 lines
787 B
Python
Raw Normal View History

2022-04-19 12:42:29 +00:00
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()