mockup #7

Merged
s444519 merged 19 commits from mockup into master 2022-05-04 12:47:45 +02:00
2 changed files with 27 additions and 25 deletions
Showing only changes of commit 7f57db1606 - Show all commits

View File

@ -1,27 +1,27 @@
# Iwona from jsgf import PublicRule, Grammar
import re
class NLU: 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 = { def getDialogAct(rule):
'hello': None, slots = []
'null': None, return {'act': rule.grammar.name, 'slots': slots}
'inform': None,
'ack': None,
}
def getUserActs(self, userInput): def nlu(utterance):
resultUserActs = [] hello = Grammar('hello')
hello.add_rule(PublicRule('witaj', 'cześć jak masz na imię'))
# split user input utterance = NLU.get_str_cleaned(utterance)
userInput = userInput.lower().split()
# find key words matched = hello.find_matching_rules(utterance)
if "cześć" in userInput: if matched:
resultUserActs.append(self.userSpeechActs[0]) return NLU.getDialogAct(matched[0])
if "imię" in userInput: else:
resultUserActs.append(self.userSpeechActs[0]) return {'act': 'null', 'slots': []}
# 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

View File

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