ierhon commited on
Commit
ee96a26
1 Parent(s): c1e0363

Move todset function to the main file

Browse files
Files changed (1) hide show
  1. chatbot_constructor.py +15 -0
chatbot_constructor.py CHANGED
@@ -12,6 +12,21 @@ import keras
12
 
13
  os.mkdir("cache")
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def hash_str(data: str):
16
  return hashlib.md5(data.encode('utf-8')).hexdigest()
17
 
 
12
 
13
  os.mkdir("cache")
14
 
15
+ def todset(text: str):
16
+ lines = [x.rstrip("\n").lower().split("→") for x in text.split("\n")]
17
+ lines = [(x[0].replace("\\n", "\n"), x[1].replace("\\n", "\n")) for x in lines]
18
+
19
+ responses = []
20
+ for i in lines:
21
+ if i[1] not in responses:
22
+ responses.append(i[1])
23
+
24
+ dset = {}
25
+ for sample in lines:
26
+ dset[sample[0]] = responses.index(sample[1])
27
+
28
+ return (dset, responses)
29
+
30
  def hash_str(data: str):
31
  return hashlib.md5(data.encode('utf-8')).hexdigest()
32