From 536e4e6b97915b1e3105eb233f98a19351cd37cb Mon Sep 17 00:00:00 2001 From: Heiko Raible <heiko.raible@stud.h-da.de> Date: Thu, 17 Feb 2022 17:40:16 +0000 Subject: [PATCH] Upload New File --- deployment/tester.py | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 deployment/tester.py diff --git a/deployment/tester.py b/deployment/tester.py new file mode 100644 index 0000000..47b7038 --- /dev/null +++ b/deployment/tester.py @@ -0,0 +1,66 @@ +import os +import pandas as pd + + +class Sentence: + def __init__(self, text, incorrect, error_type, original): + self.text = text + self.incorrect = incorrect + self.error_type = error_type + self.original= original + + +class Tester: + def __init__(self): + # load sentences_df + sentences_df = pd.read_csv(os.path.join("testsentences.csv"), sep=";") + # get subsets of sentences_df + correct_df = sentences_df[sentences_df.Incorrect == 0] + type_1_error_df = sentences_df[(sentences_df.Incorrect == 1) & (sentences_df["Error type"] == 1)] + type_2_error_df = sentences_df[(sentences_df.Incorrect == 1) & (sentences_df["Error type"] == 2)] + type_3_error_df= sentences_df[(sentences_df.Incorrect == 1) & (sentences_df["Error type"] == 3)] + # get lists of sentence objects + self.correct_sentences = [Sentence(entry["Sentence"], entry["Incorrect"], entry["Error type"], entry["Original Sentence"]) for i, entry in correct_df.iterrows()] + self.type_1_error_sentences = [Sentence(entry["Sentence"], entry["Incorrect"], entry["Error type"], entry["Original Sentence"]) for i, entry in type_1_error_df.iterrows()] + self.type_2_error_sentences = [Sentence(entry["Sentence"], entry["Incorrect"], entry["Error type"], entry["Original Sentence"]) for i, entry in type_2_error_df.iterrows()] + self.type_3_error_sentences = [Sentence(entry["Sentence"], entry["Incorrect"], entry["Error type"], entry["Original Sentence"]) for i, entry in type_3_error_df.iterrows()] + # remember last indexes + self.correct_i = 0 + self.type_1_i = 0 + self.type_2_i = 0 + self.type_3_i = 0 + + def get_next_correct(self): + res = None + if self.correct_i < len(self.correct_sentences): + res = self.correct_sentences[self.correct_i] + self.correct_i += 1 + return res + + def get_next_type_1(self): + res = None + if self.type_1_i < len(self.type_1_error_sentences): + res = self.type_1_error_sentences[self.type_1_i] + self.type_1_i += 1 + return res + + def get_next_type_2(self): + res = None + if self.type_2_i < len(self.type_2_error_sentences): + res = self.type_2_error_sentences[self.type_2_i] + self.type_2_i += 1 + return res + + def get_next_type_3(self): + res = None + if self.type_3_i < len(self.type_3_error_sentences): + res = self.type_3_error_sentences[self.type_3_i] + self.type_3_i += 1 + return res + + +if __name__ == "__main__": + tester = Tester() + + print(tester.get_next_type_1().text) + print(tester.get_next_type_1().text) -- GitLab