35 lines
889 B
Python
35 lines
889 B
Python
import re
|
|
|
|
from acts import hello_act, name_request_act
|
|
|
|
hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]']
|
|
request_name = ['imi[eę]', 'nazywasz']
|
|
question = ['\?$']
|
|
|
|
acts = {hello_act: [hello],
|
|
name_request_act: [request_name, question]}
|
|
|
|
def analizator_jezyka_naturalnego(text):
|
|
text = text_preprocess(text)
|
|
frame = act_check(text)
|
|
return frame
|
|
|
|
def text_preprocess(text):
|
|
text = text.lower()
|
|
return text
|
|
|
|
def act_check(text):
|
|
frame = []
|
|
for act, requirements in acts.items():
|
|
req = [check_synonyms(synonyms, text) for synonyms in requirements]
|
|
if all(req):
|
|
frame.append(act)
|
|
return frame
|
|
|
|
def check_synonyms(synonyms, text):
|
|
for expression in synonyms:
|
|
match = re.search(expression, text)
|
|
if match:
|
|
return True
|
|
return False
|