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

Commit 29016a8

Browse files
CipherCipher
authored andcommitted
Added distance comparison and Title comparison. Experimental, malfunctioning. Will fix tomorrow.
1 parent d9dd7e3 commit 29016a8

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Janex/main.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def response_compare(self, input_string, intent_class):
7777
input_string_lower = input_string.lower()
7878
highest_similarity = 0
7979
similarity_percentage = 0
80+
distance = 0
8081
most_similar_response = None
8182

8283
responses = intent_class["responses"] if intent_class else []
@@ -103,24 +104,26 @@ def response_compare(self, input_string, intent_class):
103104

104105
for word in word_list_2:
105106
if word in word_list:
106-
similarity += 1
107+
# Check if the word begins with a capital letter
108+
if word.istitle():
109+
similarity += 2 # Add 2 to the similarity for words with capital letters
110+
else:
111+
similarity += 1
107112

108-
if similarity > highest_similarity:
109-
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
110-
highest_similarity = similarity
111-
most_similar_response = response
113+
# Calculate the similarity percentage and the distance
114+
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
115+
distance = abs(len(response) - len(input_string))
112116

113-
print(f"Similarity: {similarity_percentage:.2%}")
117+
# Combine similarity and distance with appropriate weights
118+
# You can adjust the weights based on your preference
119+
combined_similarity = 0.2 * similarity_percentage + 0.8 * (1 - distance / max(len(response), len(input_string)))
114120

115-
# Convert most_similar_response back into the original string
116-
for response in responses:
117-
low_response_list = []
118-
low_response = response.lower()
119-
low_response_list = self.stem_sentence(low_response)
121+
if combined_similarity > highest_similarity:
122+
highest_similarity = combined_similarity
123+
most_similar_response = response
120124

121-
for low_response_word in low_response_list:
122-
if low_response_word == most_similar_response:
123-
most_similar_response = response
125+
print(f"Similarity: {highest_similarity:.2%}")
126+
print(f"Distance: {distance}")
124127

125128
return most_similar_response
126129

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ To compare the input with the patterns from your intents.json storage file, you
5656
```
5757
intents_file_path = "intents.json"
5858
59-
intent_class = matcher.pattern_compare(input_string, intents_file_path)
59+
intent_class, similarity = matcher.pattern_compare(input_string)
6060
6161
print(intent_class)
6262
```

0 commit comments

Comments
 (0)