From b052bb6aa0dcc8f1c5cb2c67a88adfe3ac021ff2 Mon Sep 17 00:00:00 2001 From: Karol Idaszak Date: Tue, 19 Apr 2022 21:25:16 +0200 Subject: [PATCH] bugfix --- .../analizator_jezyka_naturalnego.py | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/system_mockup/analizator_jezyka_naturalnego.py b/system_mockup/analizator_jezyka_naturalnego.py index 0daff3d..bb4c032 100644 --- a/system_mockup/analizator_jezyka_naturalnego.py +++ b/system_mockup/analizator_jezyka_naturalnego.py @@ -1,31 +1,32 @@ -import re - -def analizator_jezyka_naturalnego(text): - hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]'] - request_name = ['imi[eę]', 'nazywasz'] - question = ['\?$'] - - acts = {'hello': [hello], - 'request(name)': [request_name, question]} - 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 +import re + +hello = ['dzie[ńn] dobry', 'dobry wiecz[oó]r', 'witam', 'witaj', 'siema', 'elo', 'cze[śs][ćc]'] +request_name = ['imi[eę]', 'nazywasz'] +question = ['\?$'] + +acts = {'hello': [hello], + 'request(name)': [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