mirror of
https://github.com/ltcptgeneral/cse151b-final-project.git
synced 2025-09-10 01:07:21 +00:00
still doesnt train
This commit is contained in:
27
wordle_gym/envs/strategies/utils/freq.py
Normal file
27
wordle_gym/envs/strategies/utils/freq.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from os import path
|
||||
|
||||
def get_5_letter_word_freqs():
|
||||
"""
|
||||
Returns a list of words with 5 letters.
|
||||
"""
|
||||
FILEPATH = path.join(path.dirname(path.abspath(__file__)), "data/norvig.txt")
|
||||
lines = read_file(FILEPATH)
|
||||
return {k:v for k, v in get_freq(lines).items() if len(k) == 5}
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
"""
|
||||
Reads a file and returns a list of words and frequencies
|
||||
"""
|
||||
with open(filename, 'r') as f:
|
||||
return f.readlines()
|
||||
|
||||
|
||||
def get_freq(lines):
|
||||
"""
|
||||
Returns a dictionary of words and their frequencies
|
||||
"""
|
||||
freqs = {}
|
||||
for word, freq in map(lambda x: x.split("\t"), lines):
|
||||
freqs[word] = int(freq)
|
||||
return freqs
|
Reference in New Issue
Block a user