File size: 1,131 Bytes
c5f913a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from nltk import corpus


def get_word_list()->list:

    return [ i for i in corpus.words.words() if len(i) == 5]



class Metrics:
    def __init__(self):
        self.score_dict = {
            "not_present" : 0,
            "wrong_pos" : 1,
            "right" : 2
        }
        self.word_list = get_word_list()

    def check_word(self,ref_word:str)->bool:
        """
        Returns True/False based on it's presence.
        """
        return ref_word in self.word_list
    
    def __call__(self,ref_word:str,pred_word:str)->dict:
        """
        Returns the position level score based on the comparison
        """
        score_dict = {}

        for letter_idx in range(5):
            pred_letter = pred_word[letter_idx]
            if pred_letter == ref_word[letter_idx]:
                score_dict[pred_letter] = 2
            elif pred_letter in ref_word:
                score_dict[pred_letter] = 1
            else:
                score_dict[pred_letter] = 0

        return score_dict

if __name__ == "__main__":
    print(len(get_word_list()))
    metric = Metrics()
    print(metric("apple","aplep"))