This commit is contained in:
Karol Idaszak 2022-04-19 21:25:16 +02:00
parent 0a03376129
commit b052bb6aa0

View File

@ -1,31 +1,32 @@
import re import re
def analizator_jezyka_naturalnego(text): hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]']
hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]'] request_name = ['imi[eę]', 'nazywasz']
request_name = ['imi[eę]', 'nazywasz'] question = ['\?$']
question = ['\?$']
acts = {'hello': [hello],
acts = {'hello': [hello], 'request(name)': [request_name, question]}
'request(name)': [request_name, question]}
text = text_preprocess(text) def analizator_jezyka_naturalnego(text):
frame = act_check(text) text = text_preprocess(text)
return frame frame = act_check(text)
return frame
def text_preprocess(text):
text = text.lower() def text_preprocess(text):
return text text = text.lower()
return text
def act_check(text):
frame = [] def act_check(text):
for act, requirements in acts.items(): frame = []
req = [check_synonyms(synonyms, text) for synonyms in requirements] for act, requirements in acts.items():
if all(req): req = [check_synonyms(synonyms, text) for synonyms in requirements]
frame.append(act) if all(req):
return frame frame.append(act)
return frame
def check_synonyms(synonyms, text):
for expression in synonyms: def check_synonyms(synonyms, text):
match = re.search(expression, text) for expression in synonyms:
if match: match = re.search(expression, text)
return True if match:
return False return True
return False