Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,19 +69,27 @@ def correct_tense_errors(text):
|
|
| 69 |
def correct_singular_plural_errors(text):
|
| 70 |
doc = nlp(text)
|
| 71 |
corrected_text = []
|
|
|
|
| 72 |
for token in doc:
|
| 73 |
-
if token.pos_ == "NOUN"
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
else:
|
| 82 |
corrected_text.append(token.text)
|
| 83 |
else:
|
| 84 |
corrected_text.append(token.text)
|
|
|
|
| 85 |
return ' '.join(corrected_text)
|
| 86 |
|
| 87 |
# Function to check and correct article errors
|
|
@@ -129,23 +137,22 @@ def paraphrase_with_spacy_nltk(text):
|
|
| 129 |
# Join the words back into a sentence
|
| 130 |
paraphrased_sentence = ' '.join(paraphrased_words)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
corrected_text = capitalize_sentences_and_nouns(paraphrased_sentence)
|
| 134 |
-
|
| 135 |
-
return corrected_text
|
| 136 |
|
| 137 |
-
# Combined function: Paraphrase ->
|
| 138 |
def paraphrase_and_correct(text):
|
| 139 |
-
|
| 140 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
| 141 |
|
| 142 |
# Step 2: Apply grammatical corrections on the paraphrased text
|
| 143 |
corrected_text = correct_article_errors(paraphrased_text)
|
| 144 |
-
|
|
|
|
|
|
|
| 145 |
corrected_text = correct_singular_plural_errors(corrected_text)
|
| 146 |
|
| 147 |
# Step 3: Capitalize sentences and proper nouns (final correction step)
|
| 148 |
-
final_text =
|
| 149 |
|
| 150 |
return final_text
|
| 151 |
|
|
|
|
| 69 |
def correct_singular_plural_errors(text):
|
| 70 |
doc = nlp(text)
|
| 71 |
corrected_text = []
|
| 72 |
+
|
| 73 |
for token in doc:
|
| 74 |
+
if token.pos_ == "NOUN":
|
| 75 |
+
# Check if the noun is singular or plural
|
| 76 |
+
if token.tag_ == "NN": # Singular noun
|
| 77 |
+
# Look for determiners like "many" to correct to plural
|
| 78 |
+
if any(child.text.lower() in ['many', 'several', 'few'] for child in token.head.children):
|
| 79 |
+
corrected_text.append(token.lemma_ + 's')
|
| 80 |
+
else:
|
| 81 |
+
corrected_text.append(token.text)
|
| 82 |
+
elif token.tag_ == "NNS": # Plural noun
|
| 83 |
+
# Look for determiners like "a", "one" to correct to singular
|
| 84 |
+
if any(child.text.lower() in ['a', 'one'] for child in token.head.children):
|
| 85 |
+
corrected_text.append(token.lemma_)
|
| 86 |
+
else:
|
| 87 |
+
corrected_text.append(token.text)
|
| 88 |
else:
|
| 89 |
corrected_text.append(token.text)
|
| 90 |
else:
|
| 91 |
corrected_text.append(token.text)
|
| 92 |
+
|
| 93 |
return ' '.join(corrected_text)
|
| 94 |
|
| 95 |
# Function to check and correct article errors
|
|
|
|
| 137 |
# Join the words back into a sentence
|
| 138 |
paraphrased_sentence = ' '.join(paraphrased_words)
|
| 139 |
|
| 140 |
+
return paraphrased_sentence
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
+
# Combined function: Paraphrase -> Grammar Correction -> Capitalization (Humanifier)
|
| 143 |
def paraphrase_and_correct(text):
|
| 144 |
+
# Step 1: Paraphrase the text
|
| 145 |
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
| 146 |
|
| 147 |
# Step 2: Apply grammatical corrections on the paraphrased text
|
| 148 |
corrected_text = correct_article_errors(paraphrased_text)
|
| 149 |
+
|
| 150 |
+
corrected_text = capitalize_sentences_and_nouns(corrected_text)
|
| 151 |
+
|
| 152 |
corrected_text = correct_singular_plural_errors(corrected_text)
|
| 153 |
|
| 154 |
# Step 3: Capitalize sentences and proper nouns (final correction step)
|
| 155 |
+
final_text = correct_tense_errors(corrected_text)
|
| 156 |
|
| 157 |
return final_text
|
| 158 |
|