This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
chatscriptJenkins.py
113 lines (98 loc) · 4.19 KB
/
chatscriptJenkins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import csv
import pandas as pd
import fileinput
import os
import codecs
line_indexes = []
# Specify if you've created a default rasa instance or not
# If not, will use nlu/stories data as per the repo
rasainit = False
if rasainit == True:
print("Rasa init")
with open("domain.yml", "r+", encoding="utf-8") as myfile: # Working to modify specific portions
contents = myfile.readlines()
lines = []
for i, line2 in enumerate(contents):
print(i, line2)
if "Responses:" in line2:
contents.insert((i - 1), "entities:" + '\n' + "Slots:")
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
break
if "session_config:" in line2:
contents.insert((i - 1), "actions:" + '\n' + "forms:")
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
break
with open("newfaq.md", encoding="utf-8") as file_in:
lines = []
for line in file_in:
if "### " in line:
question = line
chatquestion = question.replace('### ','')
with open("faq.mdx", "a+") as myfile:
if chatquestion not in open('faq.mdx').read():
myfile.write("\n")
myfile.write("\n" + question)
if "intent" in line:
intent = line
chatintent = intent.replace('intent: ','')
with open("./data/nlu.md", "a+", encoding="utf-8") as myfile:
if chatintent not in open('./data/nlu.md', encoding="utf-8").read():
myfile.write("\n")
myfile.write("\n" + "## intent:" + chatintent.replace(" ", "_"))
myfile.write("- " + chatquestion) # This is working as expected, probably appending to the row below the latest
with open("domain.yml", "r+", encoding="utf-8") as myfile:
contents = myfile.readlines()
for i, line2 in enumerate(contents):
if "entities:" in line2 and "_entities:" not in line2 and chatintent not in contents[i - 1]:
contents.insert(i, "- " + chatintent)
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
break
if "altquestion:" in line:
altquestion = line
altquestion2 = altquestion.replace('altquestion:','-')
with open("./data/nlu.md", "a+", encoding="utf-8") as myfile:
if altquestion2 not in open('./data/nlu.md', encoding="utf-8").read():
myfile.write(altquestion2)
if "answer: " in line:
answer = line
answer2 = answer.replace('answer: ','').rstrip()
with open("faq.mdx", "a+") as myfile:
if answer2.rstrip() not in open('faq.mdx').read():
myfile.write("\n" + answer2.rstrip())
with open("domain.yml", "r+", encoding="utf-8") as myfile:
contents = myfile.readlines()
noforms = True
for i, line2 in enumerate(contents):
if "actions:" in line2 and answer2 not in contents[i - 1]:
contents.insert(i, " - text: " + answer2 + "\n")
contents.insert(i, " utter_" + chatintent.rstrip() + ":\n")
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
if "forms:" in line2 and chatintent not in contents[i - 1]:
noforms = False
contents.insert(i, "- utter_" + chatintent.rstrip() + "\n")
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
if "forms" in line2:
noforms = False
if noforms:
contents.append("\n- utter_" + chatintent.rstrip())
myfile.seek(0)
myfile.writelines(contents)
myfile.truncate()
with open("./data/stories.md", "a+", encoding="utf-8") as myfile:
intent2 = intent.replace('intent: ','').rstrip()
if chatintent not in open('./data/stories.md', encoding="utf-8").read():
myfile.write("\n\n## " + intent2)
myfile.write("\n" + "* " + chatintent.rstrip())
myfile.write("\n" + " - utter_" + chatintent.rstrip())
myfile.write("\n" + " - action_restart")
print("Script Finished Successfully")