@@ -15,6 +15,7 @@ def train(intents_file_path):
15
15
intents = json .load (json_data )
16
16
17
17
def patterncompare (input_string , intents_file_path ):
18
+ input_string = input_string .lower ()
18
19
MaxSimilarity = 0
19
20
MostSimilarPattern = None
20
21
@@ -30,6 +31,7 @@ def patterncompare(input_string, intents_file_path):
30
31
31
32
patterns = intent_class .get ('patterns' )
32
33
for pattern in patterns :
34
+ pattern = pattern .lower ()
33
35
WordList = Tokenize (pattern )
34
36
Similarity = len (set (BagOfWords ) & set (WordList )) / len (set (BagOfWords + WordList ))
35
37
SimilarityPercentage = Similarity * 100
@@ -45,6 +47,7 @@ def patterncompare(input_string, intents_file_path):
45
47
raise NoMatchingIntentError ("No matching intent class found." )
46
48
47
49
def responsecompare (input_string , intents_file_path , intent_class ):
50
+ input_string = input_string .lower ()
48
51
MaxSimilarity = 0
49
52
MostSimilarResponse = None
50
53
@@ -62,19 +65,33 @@ def responsecompare(input_string, intents_file_path, intent_class):
62
65
raise NoMatchingIntentError ("No matching intent class found." )
63
66
64
67
for response in responses :
68
+ response = response .lower ()
65
69
WordList = Tokenize (response )
66
- Similarity = len (set (BagOfWords ) & set (WordList )) / len (set (BagOfWords + WordList ))
67
- SimilarityPercentage = Similarity * 100
70
+
71
+ for InputWord in BagOfWords :
72
+ for OutputWord in WordList :
73
+ # print(InputWord)
74
+ # print(OutputWord)
75
+ if InputWord == OutputWord :
76
+ Similarity = Similarity + 1
77
+ print ("Match found!" )
68
78
69
79
if Similarity > MaxSimilarity :
80
+ OutofHundred = len (input_string )
81
+ Hundred = len (BagOfWords + WordList )
82
+
83
+ SimilarityPercentage = OutofHundred / Hundred * 100
84
+
70
85
print (f"Similarity: { SimilarityPercentage :.2f} %" )
71
86
MaxSimilarity = Similarity
72
87
MostSimilarResponse = response
73
-
74
- if MostSimilarResponse :
88
+
89
+ # Convert MSR back into original string
75
90
76
- return MostSimilarResponse
77
-
78
- else :
91
+ for response in responses :
92
+ lowresponse = response .lower ()
79
93
80
- raise NoMatchingIntentError ("No matching response found." )
94
+ if lowresponse == MostSimilarResponse :
95
+ MostSimilarResponse = response
96
+
97
+ return MostSimilarResponse
0 commit comments