diff --git a/chatterbot/preprocessors_greek.py b/chatterbot/preprocessors_greek.py new file mode 100644 index 000000000..cc8238102 --- /dev/null +++ b/chatterbot/preprocessors_greek.py @@ -0,0 +1,18 @@ +""" +Statement pre-processors for Greek language. +""" +def fix_final_sigma(statement): + ''' + If there is a word that ends with "σ" it replaces it with "ς". + ''' + + data = statement.text.split() + text = "" + + for word in data: + if word[-1]=="σ": + word = word[:-1] + "ς" + text = text + word + " " + statement.text = text + + return statement diff --git a/tests/test_preprocessors_greek.py b/tests/test_preprocessors_greek.py new file mode 100644 index 000000000..8f39c7c79 --- /dev/null +++ b/tests/test_preprocessors_greek.py @@ -0,0 +1,17 @@ +from tests.base_case import ChatBotTestCase +from chatterbot.conversation import Statement +from chatterbot import preprocessors_greek + +class PreprocessorFixFinalSigmaTestCase(ChatBotTestCase): + """ + Make sure ChatterBot's final sigma replacing preprocessor works as expected. + """ + + def test_fix_final_sigma(self): + statement = Statement(text='Γεια σασ') + + fixed = preprocessors_greek.fix_final_sigma(statement) + normalText = 'Γεια σας' + self.chatbot.preprocessors = [preprocessors.clean_whitespace] + + self.assertEqual(fixed.text, normalText)