sashtech commited on
Commit
524ff09
·
verified ·
1 Parent(s): c930ce3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -49,6 +49,29 @@ def get_synonyms_nltk(word, pos):
49
  return [lemma.name() for lemma in lemmas]
50
  return []
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Function to capitalize the first letter of sentences and proper nouns
53
  def capitalize_sentences_and_nouns(text):
54
  doc = nlp(text)
@@ -105,15 +128,18 @@ def correct_grammar(text):
105
  result = parser.parse(text)
106
  return result['result']
107
 
108
- # Combined function: Paraphrase -> Capitalization -> Grammar Correction
109
  def paraphrase_and_correct(text):
110
  # Step 1: Paraphrase the text
111
  paraphrased_text = paraphrase_with_spacy_nltk(text)
112
 
113
- # Step 2: Capitalize sentences and proper nouns
114
- capitalized_text = capitalize_sentences_and_nouns(paraphrased_text)
 
 
 
115
 
116
- # Step 3: Correct grammar
117
  final_text = correct_grammar(capitalized_text)
118
 
119
  return final_text
 
49
  return [lemma.name() for lemma in lemmas]
50
  return []
51
 
52
+ # Function to check and correct tenses and verbs using spaCy
53
+ def check_tense_and_correct(text):
54
+ doc = nlp(text)
55
+ corrected_text = []
56
+
57
+ for token in doc:
58
+ # Checking for verbs and their tense
59
+ if token.pos_ == 'VERB':
60
+ tense = token.tag_ # Get the specific tense tag (e.g., VBZ, VBD, VBG, etc.)
61
+
62
+ if tense == 'VBZ': # 3rd person singular present
63
+ corrected_text.append(token.lemma_) # Replace with base form (example: goes -> go)
64
+ elif tense == 'VBD': # Past tense
65
+ corrected_text.append(token.text) # Keep past tense as is
66
+ elif tense == 'VBG': # Gerund/Present participle
67
+ corrected_text.append(token.text) # Keep it unchanged for now
68
+ else:
69
+ corrected_text.append(token.text) # For other cases, append the word as is
70
+ else:
71
+ corrected_text.append(token.text)
72
+
73
+ return ' '.join(corrected_text)
74
+
75
  # Function to capitalize the first letter of sentences and proper nouns
76
  def capitalize_sentences_and_nouns(text):
77
  doc = nlp(text)
 
128
  result = parser.parse(text)
129
  return result['result']
130
 
131
+ # Combined function: Paraphrase -> Tense Check -> Capitalization -> Grammar Correction
132
  def paraphrase_and_correct(text):
133
  # Step 1: Paraphrase the text
134
  paraphrased_text = paraphrase_with_spacy_nltk(text)
135
 
136
+ # Step 2: Check tense and verbs, and attempt correction
137
+ tense_checked_text = check_tense_and_correct(paraphrased_text)
138
+
139
+ # Step 3: Capitalize sentences and proper nouns
140
+ capitalized_text = capitalize_sentences_and_nouns(tense_checked_text)
141
 
142
+ # Step 4: Correct grammar
143
  final_text = correct_grammar(capitalized_text)
144
 
145
  return final_text