This commit is contained in:
Iwona Christop 2022-04-19 19:09:41 +02:00
parent 1528307ac6
commit 7f57db1606
2 changed files with 27 additions and 25 deletions

View File

@ -1,27 +1,27 @@
# Iwona
from jsgf import PublicRule, Grammar
import re
class NLU:
# add slots
def get_str_cleaned(str_dirty):
punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\\\]^_`{|}~'
new_str = str_dirty.lower()
new_str = re.sub(' +', ' ', new_str)
for char in punctuation:
new_str = new_str.replace(char,'')
return new_str
userSpeechActs = {
'hello': None,
'null': None,
'inform': None,
'ack': None,
}
def getDialogAct(rule):
slots = []
return {'act': rule.grammar.name, 'slots': slots}
def getUserActs(self, userInput):
resultUserActs = []
# split user input
userInput = userInput.lower().split()
# find key words
if "cześć" in userInput:
resultUserActs.append(self.userSpeechActs[0])
if "imię" in userInput:
resultUserActs.append(self.userSpeechActs[0])
# returns user speech act
return # wyobrażam sobie to jako słownik list krotek UwU {inform:[('name','edyta'), ('age','18')], reqmore:[date,time]}
#słownik słowników???? {inform:{'name':'edyta', 'age':18}, reqmore:{'date','time'}} albo słownik słowników/zbiorów bardziej pasuje
def nlu(utterance):
hello = Grammar('hello')
hello.add_rule(PublicRule('witaj', 'cześć jak masz na imię'))
utterance = NLU.get_str_cleaned(utterance)
matched = hello.find_matching_rules(utterance)
if matched:
return NLU.getDialogAct(matched[0])
else:
return {'act': 'null', 'slots': []}

View File

@ -1,5 +1,7 @@
from components.NLU import NLU
def generate_response(input):
result = "pass"
result = NLU.nlu(input)
return result
inputText = 'Cześć, jak masz na imię?'