Merge branch 'system-mockup'
This commit is contained in:
commit
6b285c68f4
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
__pycache__/
|
5
system_mockup/acts.py
Normal file
5
system_mockup/acts.py
Normal file
@ -0,0 +1,5 @@
|
||||
hello_act = 'hello'
|
||||
name_request_act = 'request(name)'
|
||||
name_response_act = 'inform(name)'
|
||||
help_response_act = 'helpresponse'
|
||||
unknown_act = 'null'
|
34
system_mockup/analizator_jezyka_naturalnego.py
Normal file
34
system_mockup/analizator_jezyka_naturalnego.py
Normal file
@ -0,0 +1,34 @@
|
||||
import re
|
||||
|
||||
from acts import hello_act, name_request_act
|
||||
|
||||
hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]']
|
||||
request_name = ['imi[eę]', 'nazywasz']
|
||||
question = ['\?$']
|
||||
|
||||
acts = {hello_act: [hello],
|
||||
name_request_act: [request_name, question]}
|
||||
|
||||
def analizator_jezyka_naturalnego(text):
|
||||
text = text_preprocess(text)
|
||||
frame = act_check(text)
|
||||
return frame
|
||||
|
||||
def text_preprocess(text):
|
||||
text = text.lower()
|
||||
return text
|
||||
|
||||
def act_check(text):
|
||||
frame = []
|
||||
for act, requirements in acts.items():
|
||||
req = [check_synonyms(synonyms, text) for synonyms in requirements]
|
||||
if all(req):
|
||||
frame.append(act)
|
||||
return frame
|
||||
|
||||
def check_synonyms(synonyms, text):
|
||||
for expression in synonyms:
|
||||
match = re.search(expression, text)
|
||||
if match:
|
||||
return True
|
||||
return False
|
18
system_mockup/generator_jezyka_nautalnego.py
Normal file
18
system_mockup/generator_jezyka_nautalnego.py
Normal file
@ -0,0 +1,18 @@
|
||||
import acts as acts
|
||||
|
||||
welcome = 'Witaj!'
|
||||
prompt = 'Zapytaj mnie o moje imię.'
|
||||
resp = 'Nazywam się Dia.'
|
||||
unknown = "Nie rozumiem."
|
||||
|
||||
def generator_jezyka_nautalnego(frames):
|
||||
for frame in frames:
|
||||
if frame == acts.hello_act:
|
||||
print(welcome, end=" ")
|
||||
elif frame == acts.name_response_act:
|
||||
print(resp, end=" ")
|
||||
elif frame == acts.help_response_act:
|
||||
print(prompt, end=" ")
|
||||
else:
|
||||
print(unknown, end=" ")
|
||||
print()
|
17
system_mockup/monitor_stanu_dialogowego.py
Normal file
17
system_mockup/monitor_stanu_dialogowego.py
Normal file
@ -0,0 +1,17 @@
|
||||
from acts import hello_act
|
||||
|
||||
|
||||
dialogue_state = []
|
||||
|
||||
def monitor_stanu_dialogowego(frame):
|
||||
# Some frames can reset the dialogue state, like saying hello.
|
||||
reset_state_if_needed(frame)
|
||||
|
||||
list(map(lambda x: dialogue_state.append(x), frame))
|
||||
return dialogue_state
|
||||
|
||||
|
||||
def reset_state_if_needed(frame):
|
||||
if hello_act in frame:
|
||||
dialogue_state.clear()
|
||||
|
17
system_mockup/system_dialogowy.py
Normal file
17
system_mockup/system_dialogowy.py
Normal file
@ -0,0 +1,17 @@
|
||||
from analizator_jezyka_naturalnego import analizator_jezyka_naturalnego
|
||||
from monitor_stanu_dialogowego import monitor_stanu_dialogowego
|
||||
from taktyka_dialogu import taktyka_dialogu
|
||||
from generator_jezyka_nautalnego import generator_jezyka_nautalnego
|
||||
|
||||
def main():
|
||||
running = True
|
||||
|
||||
while running:
|
||||
text = input('>>>')
|
||||
frame = analizator_jezyka_naturalnego(text)
|
||||
state = monitor_stanu_dialogowego(frame)
|
||||
response_frames = taktyka_dialogu(state, frame)
|
||||
generator_jezyka_nautalnego(response_frames)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
32
system_mockup/taktyka_dialogu.py
Normal file
32
system_mockup/taktyka_dialogu.py
Normal file
@ -0,0 +1,32 @@
|
||||
from os import stat
|
||||
from re import S
|
||||
from acts import *
|
||||
|
||||
|
||||
def check_condition(state, conditions, type=all):
|
||||
if type(i in state for i in conditions):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def taktyka_dialogu(state, frame):
|
||||
if should_respond_gently(frame):
|
||||
return [hello_act, name_response_act]
|
||||
if should_prompt(frame):
|
||||
return [hello_act, help_response_act]
|
||||
if should_respond_cold(frame):
|
||||
return [name_response_act]
|
||||
return [unknown_act]
|
||||
|
||||
|
||||
def should_respond_gently(state):
|
||||
return check_condition(state, [hello_act, name_request_act])
|
||||
|
||||
|
||||
def should_prompt(state):
|
||||
return check_condition(state, [hello_act], any)
|
||||
|
||||
|
||||
def should_respond_cold(state):
|
||||
return check_condition(state, [name_request_act])
|
Loading…
Reference in New Issue
Block a user