Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,6 +37,13 @@ def get_synonyms_nltk(word, pos):
|
|
| 37 |
return [lemma.name() for lemma in lemmas]
|
| 38 |
return []
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Function to capitalize the first letter of sentences and proper nouns
|
| 41 |
def capitalize_sentences_and_nouns(text):
|
| 42 |
doc = nlp(text)
|
|
@@ -61,7 +68,6 @@ def correct_tense_errors(text):
|
|
| 61 |
corrected_text = []
|
| 62 |
for token in doc:
|
| 63 |
if token.pos_ == "VERB" and token.dep_ in {"aux", "auxpass"}:
|
| 64 |
-
# Replace with appropriate verb form
|
| 65 |
lemma = wordnet.morphy(token.text, wordnet.VERB) or token.text
|
| 66 |
corrected_text.append(lemma)
|
| 67 |
else:
|
|
@@ -161,11 +167,7 @@ def correct_spelling(text):
|
|
| 161 |
words = text.split()
|
| 162 |
corrected_words = []
|
| 163 |
for word in words:
|
| 164 |
-
|
| 165 |
-
if candidates:
|
| 166 |
-
corrected_word = spell.candidates(word).pop()
|
| 167 |
-
else:
|
| 168 |
-
corrected_word = word
|
| 169 |
corrected_words.append(corrected_word)
|
| 170 |
return ' '.join(corrected_words)
|
| 171 |
|
|
@@ -206,9 +208,13 @@ def rephrase_with_synonyms(text):
|
|
| 206 |
|
| 207 |
return ' '.join(rephrased_text)
|
| 208 |
|
| 209 |
-
# Function to paraphrase and correct grammar
|
| 210 |
def paraphrase_and_correct(text):
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
# Apply grammatical corrections
|
| 214 |
paraphrased_text = correct_article_errors(paraphrased_text)
|
|
|
|
| 37 |
return [lemma.name() for lemma in lemmas]
|
| 38 |
return []
|
| 39 |
|
| 40 |
+
# Function to remove redundant and meaningless words
|
| 41 |
+
def remove_redundant_words(text):
|
| 42 |
+
doc = nlp(text)
|
| 43 |
+
meaningless_words = {"actually", "basically", "literally", "really", "very", "just"}
|
| 44 |
+
filtered_text = [token.text for token in doc if token.text.lower() not in meaningless_words]
|
| 45 |
+
return ' '.join(filtered_text)
|
| 46 |
+
|
| 47 |
# Function to capitalize the first letter of sentences and proper nouns
|
| 48 |
def capitalize_sentences_and_nouns(text):
|
| 49 |
doc = nlp(text)
|
|
|
|
| 68 |
corrected_text = []
|
| 69 |
for token in doc:
|
| 70 |
if token.pos_ == "VERB" and token.dep_ in {"aux", "auxpass"}:
|
|
|
|
| 71 |
lemma = wordnet.morphy(token.text, wordnet.VERB) or token.text
|
| 72 |
corrected_text.append(lemma)
|
| 73 |
else:
|
|
|
|
| 167 |
words = text.split()
|
| 168 |
corrected_words = []
|
| 169 |
for word in words:
|
| 170 |
+
corrected_word = spell.correction(word)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
corrected_words.append(corrected_word)
|
| 172 |
return ' '.join(corrected_words)
|
| 173 |
|
|
|
|
| 208 |
|
| 209 |
return ' '.join(rephrased_text)
|
| 210 |
|
| 211 |
+
# Function to paraphrase and correct grammar with enhanced accuracy
|
| 212 |
def paraphrase_and_correct(text):
|
| 213 |
+
# Remove meaningless or redundant words first
|
| 214 |
+
cleaned_text = remove_redundant_words(text)
|
| 215 |
+
|
| 216 |
+
# Capitalize sentences and nouns
|
| 217 |
+
paraphrased_text = capitalize_sentences_and_nouns(cleaned_text)
|
| 218 |
|
| 219 |
# Apply grammatical corrections
|
| 220 |
paraphrased_text = correct_article_errors(paraphrased_text)
|