-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-correction.py
69 lines (57 loc) · 1.91 KB
/
text-correction.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
from gingerit.gingerit import GingerIt
def text_checking_with_index(text,i):
result = GingerIt().parse(text)
if len(result['corrections']) == 0:
print("Statement {} is correct".format(i))
return 0
correct_text = result['result']
original_text = result['text']
print("The line number {} is incorrect.".format(i))
print("\nOriginal Text :{}".format(original_text))
print("\nCorrected Text: {}\n".format(correct_text))
def text_checking(text):
result = GingerIt().parse(text)
if len(result['corrections']) == 0:
print("Statement is correct")
return 0
correct_text = result['result']
original_text = result['text']
print("The text is incorrect.")
print("\nOriginal Text :{}".format(original_text))
print("\nCorrected Text: {}\n".format(correct_text))
def letter_counting(text):
text = text.split(" ")
count = 0
for words in text:
count+=len(words)
return count
if __name__ == '__main__':
while True:
print("""
1. Manual type text and check
2. Read text from file
3. Exit
""")
print("(Prees 1 or 2 or 3: ) ")
key = input()
if key == '1':
print("Enter the text: ",end="")
text = input()
print("The sentance has {} letters\n".format(letter_counting(text)))
text_checking(text)
elif key == '2':
print("Enter the text file path: ")
filename = input()
#try:
with open(filename) as f:
i=1
for line in f:
print("The sentance {} has {} letters\n".format(i,letter_counting(line)))
text_checking_with_index(line,i)
i+=1
#except:
# print("Enter the correct file path name.")
elif key == '3':
break
else:
print("Please press correct key\n")