mockup #7
@ -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
|
|
||||||
userInput = userInput.lower().split()
|
utterance = NLU.get_str_cleaned(utterance)
|
||||||
|
|
||||||
# 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
|
|
@ -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ę?'
|
||||||
|
Loading…
Reference in New Issue
Block a user