Skip to content
Snippets Groups Projects
Commit 536e4e6b authored by Heiko Raible's avatar Heiko Raible
Browse files

Upload New File

parent 8c4cc887
Branches
No related tags found
1 merge request!14Upload New File
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment