semantic-parser added
This commit is contained in:
parent
9d3f61db38
commit
7e2e35032d
@ -2,6 +2,6 @@
|
|||||||
|
|
||||||
grammar bye;
|
grammar bye;
|
||||||
|
|
||||||
public <bey_zapytanie> = <words_bye> {words_bye};
|
public <bye> = <words_bye>;
|
||||||
|
|
||||||
<words_bye> = Do widzenia | do widzenia | cześć | na razie | hej;
|
<words_bye> = Do widzenia | do widzenia;
|
||||||
|
7
semantic_parser/gramatics/hello.jsgf
Normal file
7
semantic_parser/gramatics/hello.jsgf
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#JSGF V1.0 UTF-8 pl;
|
||||||
|
|
||||||
|
grammar hello;
|
||||||
|
|
||||||
|
public <hello> = <words_hello>;
|
||||||
|
|
||||||
|
<words_hello> = cześć | hej;
|
@ -1,5 +0,0 @@
|
|||||||
hello_act = 'hello'
|
|
||||||
name_request_act = 'request(name)'
|
|
||||||
name_response_act = 'inform(name)'
|
|
||||||
help_response_act = 'helpresponse'
|
|
||||||
unknown_act = 'null'
|
|
@ -1,18 +1,19 @@
|
|||||||
import acts as acts
|
from taktyka_dialogu import Questions
|
||||||
|
|
||||||
welcome = 'Witaj!'
|
welcome = 'Witaj!'
|
||||||
prompt = 'Zapytaj mnie o moje imię.'
|
|
||||||
resp = 'Nazywam się Dia.'
|
|
||||||
unknown = "Nie rozumiem."
|
unknown = "Nie rozumiem."
|
||||||
|
end = "Żegnaj!"
|
||||||
|
|
||||||
def generator_jezyka_nautalnego(frames):
|
def generator_jezyka_nautalnego(frame, question):
|
||||||
for frame in frames:
|
if question != Questions.NONE:
|
||||||
if frame == acts.hello_act:
|
#ask additional questions
|
||||||
print(welcome, end=" ")
|
if question == Questions.TIME:
|
||||||
elif frame == acts.name_response_act:
|
print("Z jakiego czasu?")
|
||||||
print(resp, end=" ")
|
else:
|
||||||
elif frame == acts.help_response_act:
|
#dont ask questions
|
||||||
print(prompt, end=" ")
|
if frame['act'] == "hello":
|
||||||
|
print(welcome)
|
||||||
|
elif frame['act'] == "bye":
|
||||||
|
print(end)
|
||||||
else:
|
else:
|
||||||
print(unknown, end=" ")
|
print(unknown)
|
||||||
print()
|
|
||||||
|
@ -16,7 +16,7 @@ def monitor_stanu_dialogowego(frame):
|
|||||||
|
|
||||||
def reset_state_if_needed(frame):
|
def reset_state_if_needed(frame):
|
||||||
global iterator
|
global iterator
|
||||||
if frame['act'] == "bye":
|
if frame['act'] == "hello" or frame['act'] == "bye":
|
||||||
dialogue_state.clear()
|
dialogue_state.clear()
|
||||||
iterator = 1
|
iterator = 1
|
||||||
|
|
||||||
|
@ -8,12 +8,17 @@ def main():
|
|||||||
|
|
||||||
while running:
|
while running:
|
||||||
text = input('>>>')
|
text = input('>>>')
|
||||||
|
|
||||||
frame = analizator_jezyka_naturalnego(text)
|
frame = analizator_jezyka_naturalnego(text)
|
||||||
#print("Analizator: {}".format(frame))
|
print("[INFO] - Analizator: {}".format(frame))
|
||||||
|
|
||||||
state = monitor_stanu_dialogowego(frame)
|
state = monitor_stanu_dialogowego(frame)
|
||||||
#print("Stan: {}".format(state))
|
print("[INFO] - Liczba elementów stanu: {}".format(len(state)))
|
||||||
response_frames = taktyka_dialogu(state, frame)
|
|
||||||
generator_jezyka_nautalnego(response_frames)
|
questions = taktyka_dialogu(state, frame)
|
||||||
|
print("[INFO] - Taktyka: {}".format(questions))
|
||||||
|
|
||||||
|
generator_jezyka_nautalnego(frame, questions)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -1,32 +1,22 @@
|
|||||||
from os import stat
|
from enum import Enum
|
||||||
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
|
|
||||||
|
|
||||||
|
class Questions(Enum):
|
||||||
|
TIME = "time"
|
||||||
|
REPO = "repo"
|
||||||
|
NONE = "none"
|
||||||
|
|
||||||
def taktyka_dialogu(state, frame):
|
def taktyka_dialogu(state, frame):
|
||||||
if should_respond_gently(frame):
|
return questions(frame)
|
||||||
return [hello_act, name_response_act]
|
# TODO inna taktyka
|
||||||
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):
|
def questions(frame):
|
||||||
return check_condition(state, [hello_act, name_request_act])
|
for slot in frame['slots']:
|
||||||
|
|
||||||
|
if slot[0] == "time_when" and slot[1] == None:
|
||||||
|
return Questions.TIME
|
||||||
|
|
||||||
def should_prompt(state):
|
if slot[0] == "repo" and (slot[1] == None or slot[1] == ""):
|
||||||
return check_condition(state, [hello_act], any)
|
return Questions.REPO
|
||||||
|
|
||||||
|
return Questions.NONE
|
||||||
def should_respond_cold(state):
|
|
||||||
return check_condition(state, [name_request_act])
|
|
Loading…
Reference in New Issue
Block a user