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

Commit babb3c8

Browse files
CipherCipher
authored andcommitted
Fixed percentage buildup
1 parent 627b732 commit babb3c8

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

Janex.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def patterncompare(input_string, intents_file_path):
1818
input_string = input_string.lower()
1919
MaxSimilarity = 0
2020
MostSimilarPattern = None
21+
SimilarityPercentage = 0
2122

2223
patterns = []
2324
Similarity = 0
@@ -28,21 +29,19 @@ def patterncompare(input_string, intents_file_path):
2829
BagOfWords = Tokenize(input_string)
2930

3031
for intent_class in intents['intents']:
31-
32+
3233
patterns = intent_class.get('patterns')
3334
for pattern in patterns:
35+
Similarity = 0
3436
pattern = pattern.lower()
3537
WordList = Tokenize(pattern)
3638
Similarity = len(set(BagOfWords) & set(WordList)) / len(set(BagOfWords + WordList))
37-
SimilarityPercentage = Similarity * 100
3839

3940
if Similarity > MaxSimilarity:
41+
SimilarityPercentage = Similarity * 100
4042
MaxSimilarity = Similarity
4143
MostSimilarPattern = intent_class
42-
43-
if SimilarityPercentage > 100:
44-
SimilarityPercentage = SimilarityPercentage/100
45-
44+
4645
print(f"Similarity: {SimilarityPercentage:.2f}%")
4746

4847
if MostSimilarPattern:
@@ -53,6 +52,7 @@ def patterncompare(input_string, intents_file_path):
5352
def responsecompare(input_string, intents_file_path, intent_class):
5453
input_string = input_string.lower()
5554
MaxSimilarity = 0
55+
SimilarityPercentage = 0
5656
MostSimilarResponse = None
5757

5858
responses = []
@@ -69,6 +69,7 @@ def responsecompare(input_string, intents_file_path, intent_class):
6969
raise NoMatchingIntentError("No matching intent class found.")
7070

7171
for response in responses:
72+
Similarity = 0
7273
response = response.lower()
7374
WordList = Tokenize(response)
7475

@@ -81,22 +82,17 @@ def responsecompare(input_string, intents_file_path, intent_class):
8182
OutofHundred = len(BagOfWords) # Total number of words in the input
8283
Hundred = len(BagOfWords + WordList) # Total number of words in both input and pattern
8384

84-
SimilarityPercentage = (Similarity / Hundred) * 100 # Corrected calculation
85-
8685
if Similarity > MaxSimilarity:
86+
SimilarityPercentage = (Similarity / Hundred) * 100
8787
MaxSimilarity = Similarity
8888
MostSimilarResponse = response
89-
90-
if SimilarityPercentage > 100:
91-
SimilarityPercentage = SimilarityPercentage/100
92-
89+
9390
print(f"Similarity: {SimilarityPercentage:.2f}%")
94-
91+
9592
# Convert MSR back into original string
9693
for response in responses:
9794
lowresponse = response.lower()
9895
if lowresponse == MostSimilarResponse:
9996
MostSimilarResponse = response
100-
101-
return MostSimilarResponse
10297

98+
return MostSimilarResponse

__pycache__/Janex.cpython-311.pyc

-56 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)