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

Commit db4f7ce

Browse files
author
Cipher
committed
Prepare for v0.0.5 release
1 parent de19d13 commit db4f7ce

File tree

12 files changed

+303
-6
lines changed

12 files changed

+303
-6
lines changed

Janex.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: Janex
3-
Version: 0.0.4b0
3+
Version: 0.0.5
44
Home-page: https://github.com/Cipher58
55
Download-URL: https://github.com/Cipher58/Janex/archive/refs/tags/v0.0.2-beta.tar.gz
66
Author: Cipher58

Janex.egg-info/SOURCES.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ LICENSE
22
README.md
33
Setup.py
44
setup.py
5-
Janex/Janex.py
65
Janex/__init__.py
76
Janex/chat.py
87
Janex.egg-info/PKG-INFO

Janex/.DS_Store

0 Bytes
Binary file not shown.

Janex/__init__.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import json
2+
3+
class IntentMatcher:
4+
def __init__(self, intents_file_path):
5+
self.intents_file_path = intents_file_path
6+
self.intents = self.train()
7+
8+
def tokenize(self, input_string):
9+
processed_string = input_string.lower().strip().replace(r"[^\w\s]|_", "").replace(r"\s+", " ")
10+
words = processed_string.split(" ")
11+
12+
words = self.stem_list(words)
13+
14+
return words
15+
16+
def tokenize_list(self, input_list):
17+
token_words = []
18+
for word in input_list:
19+
token = self.tokenize(word)
20+
token_words.append(token)
21+
22+
return token_words
23+
24+
def train(self):
25+
with open(self.intents_file_path, "r") as file:
26+
intents = json.load(file)
27+
return intents
28+
29+
def pattern_compare(self, input_string):
30+
input_string_lower = input_string.lower()
31+
highest_similarity = 0
32+
most_similar_pattern = None
33+
similarity_percentage = 0
34+
35+
for intent_class in self.intents["intents"]:
36+
overall_word_list = []
37+
similarity = 0
38+
39+
for pattern in intent_class["patterns"]:
40+
word_list = []
41+
pattern_lower = pattern.lower()
42+
word_list = self.tokenize(pattern_lower)
43+
overall_word_list.append(word_list)
44+
new_list = []
45+
new_bag = []
46+
47+
for word in word_list:
48+
word = self.stem(word)
49+
new_list.append(word)
50+
51+
word_list_2 = self.tokenize(input_string_lower)
52+
for word in word_list_2:
53+
word = self.stem(word)
54+
new_bag.append(word)
55+
56+
word_list = new_list
57+
word_list_2 = new_bag
58+
59+
for word in word_list_2:
60+
if word in word_list:
61+
similarity += 1
62+
63+
if similarity > highest_similarity:
64+
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
65+
highest_similarity = similarity
66+
most_similar_pattern = intent_class
67+
68+
print(f"Similarity: {similarity_percentage:.2%}")
69+
70+
if most_similar_pattern:
71+
return most_similar_pattern
72+
else:
73+
raise ValueError("No matching intent class found.")
74+
75+
def response_compare(self, input_string, intent_class):
76+
input_string_lower = input_string.lower()
77+
highest_similarity = 0
78+
similarity_percentage = 0
79+
most_similar_response = None
80+
81+
responses = intent_class["responses"] if intent_class else []
82+
83+
for response in responses:
84+
similarity = 0
85+
response_lower = response.lower()
86+
word_list = self.tokenize(response_lower)
87+
new_list = []
88+
new_bag = []
89+
90+
for word in word_list:
91+
word = self.stem(word)
92+
new_list.append(word)
93+
94+
word_list_2 = self.tokenize(input_string_lower)
95+
for word in word_list_2:
96+
word = self.stem(word)
97+
new_bag.append(word)
98+
99+
word_list = new_list
100+
word_list_2 = new_bag
101+
overall_word_list = word_list + word_list_2
102+
103+
for word in word_list_2:
104+
if word in word_list:
105+
similarity += 1
106+
107+
if similarity > highest_similarity:
108+
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
109+
highest_similarity = similarity
110+
most_similar_response = response
111+
112+
print(f"Similarity: {similarity_percentage:.2%}")
113+
114+
# Convert most_similar_response back into the original string
115+
for response in responses:
116+
low_response_list = []
117+
low_response = response.lower()
118+
low_response_list = self.stem_sentence(low_response)
119+
120+
for low_response_word in low_response_list:
121+
if low_response_word == most_similar_response:
122+
most_similar_response = response
123+
124+
return most_similar_response
125+
126+
def stem(self, input_word):
127+
suffixes = ["ing", "ly", "ed", "es", "'s", "er", "est", "y", "ily", "able", "ful", "ness", "less", "ment", "ive", "ize", "ous"]
128+
for suffix in suffixes:
129+
if input_word.endswith(suffix):
130+
input_word = input_word[:-len(suffix)]
131+
break
132+
return input_word
133+
134+
def stem_sentence(self, input_string):
135+
word_list = input_string.split(" ")
136+
stemmed_words = []
137+
for input_word in word_list:
138+
word = self.stem(input_word)
139+
stemmed_words.append(word)
140+
141+
return stemmed_words
142+
143+
def stem_list(self, input_list):
144+
stemmed_words = []
145+
for word in input_list:
146+
stemmed_word = self.stem(word)
147+
stemmed_words.append(stemmed_word)
148+
149+
return stemmed_words

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ Released under the **new** Free Lily License 1.0, Janex will improve and become
1313

1414
<h5> Adding to your project </h5>
1515

16-
Firstly, clone the git repository to the local directory of your project.
16+
Firstly, if you want to use this from source, clone the git repository to the local directory of your project.
1717

1818
```
1919
cd /path/to/your/project/directory
2020
2121
gh repo clone Cipher58/Janex
2222
```
2323

24-
Secondly, import the Janex toolkit into your code by adding this line
24+
Secondly, even if you are just using the library, import the Janex toolkit into your code by adding this line
2525

2626
```
2727
from Janex import *
@@ -84,7 +84,7 @@ print(output)
8484

8585
<h3> Functionality </h3>
8686

87-
<h4>Version 0.0.2-Gamma</h4>
87+
<h4>Version 0.0.5</h4>
8888

8989
- Word tokenizer ✓
9090
- Intent classifier ✓

Setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
name="Janex",
99

1010
# version of the module
11-
version="0.0.4.beta",
11+
version="0.0.5",
1212

1313
# Name of Author
1414
author="Cipher58",
File renamed without changes.

build/lib/Janex/__init__.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import json
2+
3+
class IntentMatcher:
4+
def __init__(self, intents_file_path):
5+
self.intents_file_path = intents_file_path
6+
self.intents = self.train()
7+
8+
def tokenize(self, input_string):
9+
processed_string = input_string.lower().strip().replace(r"[^\w\s]|_", "").replace(r"\s+", " ")
10+
words = processed_string.split(" ")
11+
12+
words = self.stem_list(words)
13+
14+
return words
15+
16+
def tokenize_list(self, input_list):
17+
token_words = []
18+
for word in input_list:
19+
token = self.tokenize(word)
20+
token_words.append(token)
21+
22+
return token_words
23+
24+
def train(self):
25+
with open(self.intents_file_path, "r") as file:
26+
intents = json.load(file)
27+
return intents
28+
29+
def pattern_compare(self, input_string):
30+
input_string_lower = input_string.lower()
31+
highest_similarity = 0
32+
most_similar_pattern = None
33+
similarity_percentage = 0
34+
35+
for intent_class in self.intents["intents"]:
36+
overall_word_list = []
37+
similarity = 0
38+
39+
for pattern in intent_class["patterns"]:
40+
word_list = []
41+
pattern_lower = pattern.lower()
42+
word_list = self.tokenize(pattern_lower)
43+
overall_word_list.append(word_list)
44+
new_list = []
45+
new_bag = []
46+
47+
for word in word_list:
48+
word = self.stem(word)
49+
new_list.append(word)
50+
51+
word_list_2 = self.tokenize(input_string_lower)
52+
for word in word_list_2:
53+
word = self.stem(word)
54+
new_bag.append(word)
55+
56+
word_list = new_list
57+
word_list_2 = new_bag
58+
59+
for word in word_list_2:
60+
if word in word_list:
61+
similarity += 1
62+
63+
if similarity > highest_similarity:
64+
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
65+
highest_similarity = similarity
66+
most_similar_pattern = intent_class
67+
68+
print(f"Similarity: {similarity_percentage:.2%}")
69+
70+
if most_similar_pattern:
71+
return most_similar_pattern
72+
else:
73+
raise ValueError("No matching intent class found.")
74+
75+
def response_compare(self, input_string, intent_class):
76+
input_string_lower = input_string.lower()
77+
highest_similarity = 0
78+
similarity_percentage = 0
79+
most_similar_response = None
80+
81+
responses = intent_class["responses"] if intent_class else []
82+
83+
for response in responses:
84+
similarity = 0
85+
response_lower = response.lower()
86+
word_list = self.tokenize(response_lower)
87+
new_list = []
88+
new_bag = []
89+
90+
for word in word_list:
91+
word = self.stem(word)
92+
new_list.append(word)
93+
94+
word_list_2 = self.tokenize(input_string_lower)
95+
for word in word_list_2:
96+
word = self.stem(word)
97+
new_bag.append(word)
98+
99+
word_list = new_list
100+
word_list_2 = new_bag
101+
overall_word_list = word_list + word_list_2
102+
103+
for word in word_list_2:
104+
if word in word_list:
105+
similarity += 1
106+
107+
if similarity > highest_similarity:
108+
similarity_percentage = similarity / (len(overall_word_list) + len(word_list_2))
109+
highest_similarity = similarity
110+
most_similar_response = response
111+
112+
print(f"Similarity: {similarity_percentage:.2%}")
113+
114+
# Convert most_similar_response back into the original string
115+
for response in responses:
116+
low_response_list = []
117+
low_response = response.lower()
118+
low_response_list = self.stem_sentence(low_response)
119+
120+
for low_response_word in low_response_list:
121+
if low_response_word == most_similar_response:
122+
most_similar_response = response
123+
124+
return most_similar_response
125+
126+
def stem(self, input_word):
127+
suffixes = ["ing", "ly", "ed", "es", "'s", "er", "est", "y", "ily", "able", "ful", "ness", "less", "ment", "ive", "ize", "ous"]
128+
for suffix in suffixes:
129+
if input_word.endswith(suffix):
130+
input_word = input_word[:-len(suffix)]
131+
break
132+
return input_word
133+
134+
def stem_sentence(self, input_string):
135+
word_list = input_string.split(" ")
136+
stemmed_words = []
137+
for input_word in word_list:
138+
word = self.stem(input_word)
139+
stemmed_words.append(word)
140+
141+
return stemmed_words
142+
143+
def stem_list(self, input_list):
144+
stemmed_words = []
145+
for word in input_list:
146+
stemmed_word = self.stem(word)
147+
stemmed_words.append(stemmed_word)
148+
149+
return stemmed_words

dist/Janex-0.0.4rc0-py3-none-any.whl

5.99 KB
Binary file not shown.

dist/Janex-0.0.4rc0.tar.gz

5.52 KB
Binary file not shown.

dist/Janex-0.0.5-py3-none-any.whl

6.92 KB
Binary file not shown.

dist/Janex-0.0.5.tar.gz

5.45 KB
Binary file not shown.

0 commit comments

Comments
 (0)