mockup #7
@ -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 = []
|
||||
def nlu(utterance):
|
||||
hello = Grammar('hello')
|
||||
hello.add_rule(PublicRule('witaj', 'cześć jak masz na imię'))
|
||||
|
||||
# split user input
|
||||
userInput = userInput.lower().split()
|
||||
utterance = NLU.get_str_cleaned(utterance)
|
||||
|
||||
# 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
|
||||
matched = hello.find_matching_rules(utterance)
|
||||
if matched:
|
||||
return NLU.getDialogAct(matched[0])
|
||||
else:
|
||||
return {'act': 'null', 'slots': []}
|
@ -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ę?'
|
||||
|
Loading…
Reference in New Issue
Block a user