Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)