-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammarchecker.py
181 lines (161 loc) · 10.2 KB
/
grammarchecker.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import sys
import re
PUNCT = [".", ",", "¿", "?", "¡", "!"]
alltags = ["ADJ", "ADP", "ADV", "AUX", "CCONJ", "DET", "INTJ", "NOUN", "NUM", "PART", "PRON", "PROPN", "PUNCT", "SCONJ", "SYM", "VERB", "X"]
presente = open("lists/conjugaciones/presente_ind.txt", "r")
imperfecto_ind = open("lists/conjugaciones/imperfecto_ind.txt", "r")
preterito = open("lists/conjugaciones/preterito.txt", "r")
futuro = open("lists/conjugaciones/futuro.txt", "r")
condicional = open("lists/conjugaciones/condicional.txt", "r")
ser_estar = open("lists/conjugaciones/ser_estar.txt", "r")
# KNOWN ISSUES:
# Sometimes, when the parser outputs more than one possible tag for a single token,
# it can print the results for every tag.
# -
# This code could probably be improved with a stemmer and reducing the number of "if" statement.
# -
print("---------------------------------------------------------------")
with open('outputmorpho.txt', 'r') as f:
for line in f:
if line[0] == ";":
continue
elif line[0] == "\"":
print(line[2:-3])
elif line[0] == "\t":
# Analyze NOUNs
if re.findall('NOUN', line):
print("<NOUN>")
if re.findall('Gender=Masc', line) and re.findall('Number=Sing', line):
print("\tMasculino Singular")
if re.findall('Gender=Fem', line) and re.findall('Number=Sing', line):
print("\tFemenino Singular")
if re.findall('Gender=Masc', line) and re.findall('Number=Plur', line):
print("\tMasculino Plural")
if re.findall('Gender=Fem', line) and re.findall('Number=Plur', line):
print("\tFemenino Plural")
print("\tDon't forget to check the agreement between the determiner (DETERMINER) \n\tand the adjective (ADJECTIVE) that may go with this noun!")
print("------------------------")
# Analyze DETs
if re.findall('DET', line):
print("<DETERMINER>")
if re.findall('Gender=Masc', line) and re.findall('Number=Sing', line):
print("\tMasculino Singular")
if re.findall('Gender=Fem', line) and re.findall('Number=Sing', line):
print("\tFemenino Singular")
if re.findall('Gender=Masc', line) and re.findall('Number=Plur', line):
print("\tMasculino Plural")
if re.findall('Gender=Fem', line) and re.findall('Number=Plur', line):
print("\tFemenino Plural")
print("\tDon't forget to check the agreement between the noun (NOUN) \n\tand the adjective (ADJECTIVE) that may go with this determiner!")
print("------------------------")
# Analyze VERBs
if re.findall('VERB', line):
print("<VERB>")
# Present Indicative Tense
if (re.findall('Tense=Pres', line)) and (re.findall('Mood=Ind', line)):
infinitive = re.findall('\"[a-z]+\"', line)
print(presente.read() + "\n")
print("La conjugación para el verbo", infinitive[0], "es:")
for i in infinitive:
if re.findall('\"ser\"', line):
print("\tsoy\n\teres\n\tes\n\tsomos\n\tsois\n\tson\n")
print(ser_estar.read() + "\n")
print("------------------------")
elif re.findall('\"estar\"', line):
print("\testoy\n\testás\n\testá\n\testamos\n\testáis\n\testán\n")
print(ser_estar.read() + "\n")
print("------------------------")
else:
if i[-3:-1] == "ar":
print("\t",i[1:-3] + "o\n" + "\t",i[1:-3] + "as\n" + "\t",i[1:-3] + "a\n" + "\t",i[1:-3] + "amos\n" + "\t",i[1:-3] + "áis\n" + "\t",i[1:-3] + "an\n")
print("------------------------")
elif i[-3:-1] == "er" or "ir":
print("------------------------")
print("\t",i[1:-3] + "o\n" + "\t",i[1:-3] + "es\n" + "\t",i[1:-3] + "e\n" + "\t",i[1:-3] + "emos\n" + "\t",i[1:-3] + "éis\n" + "\t",i[1:-3] + "en\n")
# Imperfect Indicative Tense
if (re.findall('Tense=Imp', line)) and (re.findall('Mood=Ind', line)):
infinitive = re.findall('\"[a-z]+\"', line)
print(imperfecto_ind.read() + "\n")
print("La conjugación para el verbo", infinitive[0], "es:")
for i in infinitive:
if re.findall('\"ser\"', line):
print("\tera\n\teras\n\tera\n\téramos\n\térais\n\teran\n")
print("\t",ser_estar.read() + "\n")
print("------------------------")
elif re.findall('\"estar\"', line):
print("\testaba\n\testabas\n\testaba\n\testábamos\n\testabais\n\testaban\n")
print("\t",ser_estar.read() + "\n")
print("------------------------")
else:
if i[-3:-1] == "ar":
print("\t",i[1:-3] + "aba\n" + "\t",i[1:-3] + "abas\n" + "\t",i[1:-3] + "aba\n" + "\t",i[1:-3] + "ábamos\n" + "\t",i[1:-3] + "abais\n" + "\t",i[1:-3] + "aban\n")
print("------------------------")
elif i[-3:-1] == "er" or "ir":
print("\t",i[1:-3] + "ía\n" + "\t",i[1:-3] + "ías\n" + "\t",i[1:-3] + "ía\n" + "\t",i[1:-3] + "íamos\n" + "\t",i[1:-3] + "íais\n" + "\t",i[1:-3] + "ían\n")
print("------------------------")
# Preterit Indicative Tense
if (re.findall('Tense=Past', line)) and (re.findall('Mood=Ind', line)):
infinitive = re.findall('\"[a-z]+\"', line)
print(preterito.read() + "\n")
print("La conjugación para el verbo", infinitive[0], "es:")
for i in infinitive:
if re.findall('\"ser\"', line):
print("\tfui\n\tfuiste\n\tfue\n\tfuimos\n\tfuisteis\n\tfueron\n")
print("\t",ser_estar.read() + "\n")
print("------------------------")
elif re.findall('\"estar\"', line):
print("\testuve\n\testuviste\n\testuvo\n\testuvimos\n\testuvisteis\n\testuvieron\n")
print("\t",ser_estar.read() + "\n")
print("------------------------")
else:
if i[-3:-1] == "ar":
print("\t",i[1:-3] + "é\n" + "\t",i[1:-3] + "aste\n" + "\t",i[1:-3] + "ó\n" + "\t",i[1:-3] + "amos\n" + "\t",i[1:-3] + "asteis\n" + "\t",i[1:-3] + "aron\n")
print("------------------------")
elif i[-3:-1] == "er" or "ir":
print("\t",i[1:-3] + "í\n" + "\t",i[1:-3] + "iste\n" + "\t",i[1:-3] + "ió\n" + "\t",i[1:-3] + "imos\n" + "\t",i[1:-3] + "isteis\n" + "\t",i[1:-3] + "ieron\n")
print("------------------------")
# Simple Conditional Tense
if (re.findall('Mood=Cnd', line)):
infinitive = re.findall('\"[a-z]+\"', line)
print("\t",condicional.read() + "\n")
print("La conjugación para el verbo", infinitive[0], "es:")
for i in infinitive:
print("\t",i[1:-1] + "ía\n" + "\t",i[1:-1] + "ías\n" + "\t",i[1:-1] + "ía\n" + "\t",i[1:-1] + "íamos\n" + "\t",i[1:-1] + "íais\n" + "\t",i[1:-1] + "ían\n")
print("------------------------")
# Simple Future Tense
if (re.findall('Tense=Fut', line)) and (re.findall('Mood=Ind', line)):
infinitive = re.findall('\"[a-z]+\"', line)
print("\t",futuro.read() + "\n")
print("La conjugación para el verbo", infinitive[0], "es:")
for i in infinitive:
print("\t",i[1:-1] + "é\n" + "\t",i[1:-1] + "ás\n" + "\t",i[1:-1] + "á\n" + "\t",i[1:-1] + "emos\n" + "\t",i[1:-1] + "éis\n" + "\t",i[1:-1] + "án\n")
print("------------------------")
# Analyze ADJs
if re.findall('ADJ', line):
print("<ADJECTIVE>")
if re.findall('Gender=Masc', line) and re.findall('Number=Sing', line):
print("\tMasculino Singular")
if re.findall('Gender=Fem', line) and re.findall('Number=Sing', line):
print("\tFemenino Singular")
if re.findall('Gender=Masc', line) and re.findall('Number=Plur', line):
print("\tMasculino Plural")
if re.findall('Gender=Fem', line) and re.findall('Number=Plur', line):
print("\tFemenino Plural")
print("\tDon't forget to check the agreement between the determiner (DETERMINER) \n\tand the noun (NOUN) that may go with this adjective!")
print("------------------------")
# Analyze PROPNs
if re.findall('PROPN', line):
if re.findall('Gender=Masc', line):
print("<PROPER NOUN>")
print("\tMasculino")
print("------------------------")
if re.findall('Gender=Fem', line):
print("<PROPER NOUN>")
print("\tFemenino")
print("------------------------")
# If PUNCT, end of sentence
if re.findall('PUNCT', line):
print("---------------------------------------------------------------")
# For everything else, do not show the tags
else:
continue