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

Commit 0dacb12

Browse files
CipherCipher
authored andcommitted
Update README
1 parent 82e21e9 commit 0dacb12

37 files changed

+235
-744
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.72
3+
Version: 0.0.79
44
Home-page: https://github.com/Cipher58/Janex-Python
55
Download-URL: https://github.com/Cipher58/Janex-Python.git
66
Author: Cipher58

Janex.egg-info/SOURCES.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ README.md
33
setup.py
44
Janex/__init__.py
55
Janex/chat.py
6+
Janex/intentclassifier.py
67
Janex/main.py
8+
Janex/vectortoolkit.py
9+
Janex/word_manipulation.py
710
Janex.egg-info/PKG-INFO
811
Janex.egg-info/SOURCES.txt
912
Janex.egg-info/dependency_links.txt
1013
Janex.egg-info/requires.txt
11-
Janex.egg-info/top_level.txt
12-
Janex/JanexSub/JanexSub.py
13-
Janex/JanexSub/__init__.py
14+
Janex.egg-info/top_level.txt

Janex/.DS_Store

-6 KB
Binary file not shown.

Janex/JanexSub/.DS_Store

-6 KB
Binary file not shown.

Janex/JanexSub/JanexSub.py

Whitespace-only changes.

Janex/JanexSub/__init__.py

Whitespace-only changes.

Janex/chat.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
from main import *
1+
from intentclassifier import *
2+
import random
23

3-
intents_file_path = "./intents.json"
4-
thesaurus_file_path = "./thesaurus.json"
4+
Classifier = IntentClassifier()
55

6-
matcher = IntentMatcher(intents_file_path, thesaurus_file_path)
6+
Classifier.set_intentsfp("intents.json")
7+
Classifier.set_vectorsfp("vectors.json")
8+
Classifier.set_dimensions(300)
79

8-
input_string = input("You: ")
10+
Classifier.train_vectors()
911

10-
intent_class, percentage = matcher.pattern_compare(input_string)
11-
response = matcher.response_compare(input_string, intent_class)
12+
Input = input("You: ")
1213

13-
response = matcher.ResponseGenerator(response)
14+
classification = Classifier.classify(Input)
15+
16+
response = random.choice(classification["responses"])
1417

1518
print(response)

Janex/intentclassifier.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import json
2+
from Janex.vectortoolkit import *
3+
from Janex.word_manipulation import *
4+
5+
class IntentClassifier:
6+
def __init__(self):
7+
self.intents_file_path = None
8+
self.thesaurus_file_path = None
9+
self.vectors_file_path = None
10+
11+
def set_vectorsfp(self, vectors_file_path):
12+
self.vectors_file_path = vectors_file_path
13+
print(f"Janex: Pre-trained vector file path set to {vectors_file_path}")
14+
15+
def set_intentsfp(self, intents_file_path):
16+
self.intents_file_path = intents_file_path
17+
18+
def set_dimensions(self, dimensions):
19+
self.dimensions = dimensions
20+
21+
def load_intents(self):
22+
with open(self.intents_file_path, "r") as json_file:
23+
data = json.load(json_file)
24+
return data
25+
26+
def load_vectors(self):
27+
with open(self.vectors_file_path, "r") as json_file:
28+
data = json.load(json_file)
29+
return data
30+
31+
def train_vectors(self):
32+
vectors = {}
33+
34+
intents = self.load_intents()
35+
36+
for intent_class in intents["intents"]:
37+
for pattern in intent_class["patterns"]:
38+
if pattern is not None:
39+
pattern_tokens = tokenize(pattern)
40+
for token in pattern_tokens:
41+
token_vectors = string_vectorize(token)
42+
token_vectors = reshape_array_dimensions(token_vectors, self.dimensions)
43+
token_vectors = token_vectors.tolist()
44+
vectors[token] = token_vectors
45+
for response in intent_class["responses"]:
46+
if response is not None:
47+
response_tokens = tokenize(response)
48+
for token in response_tokens:
49+
token_vectors = string_vectorize(token)
50+
token_vectors = reshape_array_dimensions(token_vectors, self.dimensions)
51+
vectors[token] = token_vectors.tolist()
52+
53+
with open(self.vectors_file_path, "w") as vectors_file:
54+
json.dump(vectors, vectors_file)
55+
56+
def classify(self, input_string):
57+
predefined_vectors = self.load_vectors()
58+
intents = self.load_intents()
59+
60+
input_tokens = tokenize(input_string)
61+
vectors_to_classify = []
62+
highest_similarity = 0
63+
64+
for token in input_tokens:
65+
if token in predefined_vectors:
66+
token_vectors = predefined_vectors[token]
67+
else:
68+
token_vectors = string_vectorize(token)
69+
70+
token_vectors = reshape_array_dimensions(token_vectors, self.dimensions)
71+
vectors_to_classify.append(token_vectors)
72+
73+
for intent_class in intents["intents"]:
74+
intent_vectors_to_classify = []
75+
for pattern in intent_class["patterns"]:
76+
pattern_tokens = tokenize(pattern)
77+
for token in pattern_tokens:
78+
if token in predefined_vectors:
79+
pattern_token_vectors = predefined_vectors[token]
80+
intent_vectors_to_classify.append(pattern_token_vectors)
81+
82+
vectors_to_classify = reshape_array_dimensions(vectors_to_classify, self.dimensions)
83+
intent_vectors_to_classify = reshape_array_dimensions(intent_vectors_to_classify, self.dimensions)
84+
85+
similarity = calculate_cosine_similarity(vectors_to_classify, intent_vectors_to_classify)
86+
87+
if similarity > highest_similarity:
88+
highest_similarity = similarity
89+
most_similar_class = intent_class
90+
91+
if most_similar_class:
92+
return most_similar_class
93+
94+
if __name__ == "__main__":
95+
Classifer = IntentClassifier()
96+
97+
Classifier.set_intentsfp("intents.json")
98+
Classifier.set_vectorsfp("vectors.json")
99+
100+
Classifier.train_vectors()
101+
102+
Input = input("You: ")
103+
104+
classification = Classifier.classify(Input)
105+
106+
Response = random.choice(classification["responses"])
107+
108+
print(Response)

0 commit comments

Comments
 (0)