-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkgrammar.py
43 lines (30 loc) · 1004 Bytes
/
checkgrammar.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
from pattern.en import conjugate, lemma, lexeme,PRESENT,SG
#print(lemma('making'))
#print(lexeme('making'))
#print (conjugate(verb='made',tense=PRESENT,number=SG)) # he / she / it
verb = ['VB','VBD','VBG','VBN','VBP','VBP','VBZ']
def intersection(a, b):
c = [value for value in a if value in b]
return c
def checkgrammar(tokens,postags,posarray,bigram,flag):
new_sent = str(' '.join(tokens))
#self.tokens = tokens
#self.posarray = posarray
#self.bigram = bigram
#print(tokens)
#print(postags)
#print(posarray)
#print(bigram)
if ('VB','VBG') in bigram:
print("Wrong grammar")
i = posarray.index('VBG')
word = tokens[i]
print(tokens[i])
new_word = lemma(word)
print(new_word)
tokens[i] = new_word
new_sent = str(' '.join(tokens))
print(new_sent)
return(new_sent, 0)
else:
return(new_sent, 1)