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

Commit 7f9b7c3

Browse files
CipherCipher
authored andcommitted
Pyc
2 parents 50024ae + b8be33d commit 7f9b7c3

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

Janex.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def train(intents_file_path):
1616

1717
def patterncompare(input_string, intents_file_path):
1818
input_string = input_string.lower()
19-
MaxSimilarity = 0
19+
HighestSimilarity = 0
2020
MostSimilarPattern = None
2121
SimilarityPercentage = 0
2222

@@ -26,37 +26,40 @@ def patterncompare(input_string, intents_file_path):
2626
with open(intents_file_path, 'r') as json_data:
2727
intents = json.load(json_data)
2828

29-
BagOfWords = Tokenize(input_string)
29+
WordList2 = Tokenize(input_string)
3030

3131
for intent_class in intents['intents']:
32+
OverallWordList = []
33+
Similarity = 0
3234

3335
patterns = intent_class.get('patterns')
3436
for pattern in patterns:
35-
Similarity = 0
37+
WordList = []
3638
pattern = pattern.lower()
3739
WordList = Tokenize(pattern)
40+
OverallWordList.append(WordList)
3841
NewList = []
3942
NewBag = []
4043

4144
for word in WordList:
4245
word = stem(word)
4346
NewList.append(word)
4447

45-
for word in BagOfWords:
48+
for word in WordList2:
4649
word = stem(word)
4750
NewBag.append(word)
4851

4952
WordList = NewList
50-
BagOfWords = NewBag
53+
WordList2 = NewBag
5154

52-
for word in BagOfWords:
55+
for word in WordList2:
5356
if word in WordList:
54-
Similarity = (Similarity+1/len(WordList + BagOfWords))
57+
Similarity = Similarity + 1
5558

56-
if Similarity > MaxSimilarity:
57-
SimilarityPercentage = Similarity * 100
58-
MaxSimilarity = Similarity
59-
MostSimilarPattern = intent_class
59+
if Similarity > HighestSimilarity:
60+
SimilarityPercentage = Similarity / len(OverallWordList + WordList2)
61+
HighestSimilarity = Similarity
62+
MostSimilarPattern = intent_class
6063

6164
print(f"Similarity: {SimilarityPercentage:.2f}%")
6265

@@ -67,7 +70,7 @@ def patterncompare(input_string, intents_file_path):
6770

6871
def responsecompare(input_string, intents_file_path, intent_class):
6972
input_string = input_string.lower()
70-
MaxSimilarity = 0
73+
HighestSimilarity = 0
7174
SimilarityPercentage = 0
7275
MostSimilarResponse = None
7376

@@ -77,7 +80,7 @@ def responsecompare(input_string, intents_file_path, intent_class):
7780
with open(intents_file_path, 'r') as json_data:
7881
intents = json.load(json_data)
7982

80-
BagOfWords = Tokenize(input_string)
83+
WordList2 = Tokenize(input_string)
8184

8285
if intent_class is not None:
8386
responses = intent_class.get('responses')
@@ -96,20 +99,20 @@ def responsecompare(input_string, intents_file_path, intent_class):
9699
word = stem(word)
97100
NewList.append(word)
98101

99-
for word in BagOfWords:
102+
for word in WordList2:
100103
word = stem(word)
101104
NewBag.append(word)
102105

103106
WordList = NewList
104-
BagOfWords = NewBag
107+
WordList2 = NewBag
105108

106-
for word in BagOfWords:
109+
for word in WordList2:
107110
if word in WordList:
108-
Similarity = (Similarity+1/len(WordList + BagOfWords))
111+
Similarity = (Similarity+1/len(WordList + WordList2))
109112

110-
if Similarity > MaxSimilarity:
113+
if Similarity > HighestSimilarity:
111114
SimilarityPercentage = Similarity * 100
112-
MaxSimilarity = Similarity
115+
HighestSimilarity = Similarity
113116
MostSimilarResponse = response
114117

115118
print(f"Similarity: {SimilarityPercentage:.2f}%")

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,5 @@ print(BestResponse)
7070

7171
- Word tokenizer ✓
7272
- Intent classifier ✓
73-
- Language Model Builder (TBD)
73+
- Word Stemmer ✓
7474
- Support for Darwin, Unix-like and Windows ✓

0 commit comments

Comments
 (0)