-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSentence.py
executable file
·72 lines (59 loc) · 1.79 KB
/
Sentence.py
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
67
68
69
70
71
72
class Sentence:
"""Contains a list of Datums."""
def __init__(self, sentence=[]):
if(type(sentence) == type([])):
self.data = list(sentence)
else:
self.data = list(sentence.data)
def getErrorSentence(self):
"""Returns a list of strings with the sentence containing all errors."""
errorSentence = []
for datum in self.data:
if datum.hasError():
errorSentence.append(datum.error)
else:
errorSentence.append(datum.word)
return errorSentence
def getCorrectSentence(self):
"""Returns a list of strings with the sentence containing all corrections."""
correctSentence = []
for datum in self.data:
correctSentence.append(datum.word)
return correctSentence
def isCorrection(self, candidate):
"""Checks if a list of strings is a correction of this sentence."""
if len(self.data) != len(candidate):
return False
for i in range(0,len(self.data)):
if not candidate[i] == self.data[i].word:
return False
return True
def getErrorIndex(self):
for i in range(0, len(self.data)):
if self.data[i].hasError():
return i
return -1
def len(self):
return len(self.data)
def get(self, i):
return self.data[i]
def put(self, i, val):
self.data[i] = val
def cleanSentence(self):
"""Returns a new sentence with all datum's having error removed."""
sentence = Sentence()
for datum in self.data:
clean = datum.fixError()
sentence.append(clean)
return sentence
def isEmpty(self):
return len(self.data) == 0
def append(self, item):
self.data.append(item)
def __len__(self):
return len(self.data)
def __str__(self):
str_list = []
for datum in self.data:
str_list.append(str(datum))
return ' '.join(str_list)