semantic-parser added
This commit is contained in:
parent
9d3f61db38
commit
7e2e35032d
@ -2,6 +2,6 @@
|
||||
|
||||
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!'
|
||||
prompt = 'Zapytaj mnie o moje imię.'
|
||||
resp = 'Nazywam się Dia.'
|
||||
unknown = "Nie rozumiem."
|
||||
end = "Żegnaj!"
|
||||
|
||||
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=" ")
|
||||
def generator_jezyka_nautalnego(frame, question):
|
||||
if question != Questions.NONE:
|
||||
#ask additional questions
|
||||
if question == Questions.TIME:
|
||||
print("Z jakiego czasu?")
|
||||
else:
|
||||
#dont ask questions
|
||||
if frame['act'] == "hello":
|
||||
print(welcome)
|
||||
elif frame['act'] == "bye":
|
||||
print(end)
|
||||
else:
|
||||
print(unknown, end=" ")
|
||||
print()
|
||||
print(unknown)
|
||||
|
@ -16,7 +16,7 @@ def monitor_stanu_dialogowego(frame):
|
||||
|
||||
def reset_state_if_needed(frame):
|
||||
global iterator
|
||||
if frame['act'] == "bye":
|
||||
if frame['act'] == "hello" or frame['act'] == "bye":
|
||||
dialogue_state.clear()
|
||||
iterator = 1
|
||||
|
||||
|
@ -8,12 +8,17 @@ def main():
|
||||
|
||||
while running:
|
||||
text = input('>>>')
|
||||
|
||||
frame = analizator_jezyka_naturalnego(text)
|
||||
#print("Analizator: {}".format(frame))
|
||||
print("[INFO] - Analizator: {}".format(frame))
|
||||
|
||||
state = monitor_stanu_dialogowego(frame)
|
||||
#print("Stan: {}".format(state))
|
||||
response_frames = taktyka_dialogu(state, frame)
|
||||
generator_jezyka_nautalnego(response_frames)
|
||||
print("[INFO] - Liczba elementów stanu: {}".format(len(state)))
|
||||
|
||||
questions = taktyka_dialogu(state, frame)
|
||||
print("[INFO] - Taktyka: {}".format(questions))
|
||||
|
||||
generator_jezyka_nautalnego(frame, questions)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -1,32 +1,22 @@
|
||||
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
|
||||
from enum import Enum
|
||||
|
||||
class Questions(Enum):
|
||||
TIME = "time"
|
||||
REPO = "repo"
|
||||
NONE = "none"
|
||||
|
||||
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]
|
||||
return questions(frame)
|
||||
# TODO inna taktyka
|
||||
|
||||
|
||||
def should_respond_gently(state):
|
||||
return check_condition(state, [hello_act, name_request_act])
|
||||
def questions(frame):
|
||||
for slot in frame['slots']:
|
||||
|
||||
if slot[0] == "time_when" and slot[1] == None:
|
||||
return Questions.TIME
|
||||
|
||||
def should_prompt(state):
|
||||
return check_condition(state, [hello_act], any)
|
||||
if slot[0] == "repo" and (slot[1] == None or slot[1] == ""):
|
||||
return Questions.REPO
|
||||
|
||||
|
||||
def should_respond_cold(state):
|
||||
return check_condition(state, [name_request_act])
|
||||
return Questions.NONE
|
Loading…
Reference in New Issue
Block a user