Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

Commit a26edf4

Browse files
author
Cipher
committed
Fixed percentage issue
1 parent bdd2df9 commit a26edf4

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

Janex.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def train(intents_file_path):
1515
intents = json.load(json_data)
1616

1717
def patterncompare(input_string, intents_file_path):
18+
input_string = input_string.lower()
1819
MaxSimilarity = 0
1920
MostSimilarPattern = None
2021

@@ -30,6 +31,7 @@ def patterncompare(input_string, intents_file_path):
3031

3132
patterns = intent_class.get('patterns')
3233
for pattern in patterns:
34+
pattern = pattern.lower()
3335
WordList = Tokenize(pattern)
3436
Similarity = len(set(BagOfWords) & set(WordList)) / len(set(BagOfWords + WordList))
3537
SimilarityPercentage = Similarity * 100
@@ -45,6 +47,7 @@ def patterncompare(input_string, intents_file_path):
4547
raise NoMatchingIntentError("No matching intent class found.")
4648

4749
def responsecompare(input_string, intents_file_path, intent_class):
50+
input_string = input_string.lower()
4851
MaxSimilarity = 0
4952
MostSimilarResponse = None
5053

@@ -62,19 +65,33 @@ def responsecompare(input_string, intents_file_path, intent_class):
6265
raise NoMatchingIntentError("No matching intent class found.")
6366

6467
for response in responses:
68+
response = response.lower()
6569
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!")
6878

6979
if Similarity > MaxSimilarity:
80+
OutofHundred = len(input_string)
81+
Hundred = len(BagOfWords + WordList)
82+
83+
SimilarityPercentage = OutofHundred/Hundred*100
84+
7085
print(f"Similarity: {SimilarityPercentage:.2f}%")
7186
MaxSimilarity = Similarity
7287
MostSimilarResponse = response
73-
74-
if MostSimilarResponse:
88+
89+
# Convert MSR back into original string
7590

76-
return MostSimilarResponse
77-
78-
else:
91+
for response in responses:
92+
lowresponse = response.lower()
7993

80-
raise NoMatchingIntentError("No matching response found.")
94+
if lowresponse == MostSimilarResponse:
95+
MostSimilarResponse = response
96+
97+
return MostSimilarResponse

__pycache__/Janex.cpython-311.pyc

385 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)