Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,6 +61,7 @@ def correct_tense_errors(text):
|
|
| 61 |
|
| 62 |
for token in doc:
|
| 63 |
if token.pos_ == "VERB":
|
|
|
|
| 64 |
if token.tag_ == "VB" and token.text.lower() not in ["be", "have", "do"]:
|
| 65 |
# Attempt to correct verb form based on sentence context
|
| 66 |
context = " ".join([t.text for t in doc if t.i != token.i])
|
|
@@ -113,10 +114,12 @@ def correct_article_errors(text):
|
|
| 113 |
for token in doc:
|
| 114 |
if token.text in ['a', 'an']:
|
| 115 |
next_token = token.nbor(1)
|
| 116 |
-
if next_token.text[0].lower() in "aeiou":
|
| 117 |
-
corrected_text.append("an"
|
|
|
|
|
|
|
| 118 |
else:
|
| 119 |
-
corrected_text.append(
|
| 120 |
else:
|
| 121 |
corrected_text.append(token.text)
|
| 122 |
return ' '.join(corrected_text)
|
|
@@ -125,7 +128,7 @@ def correct_article_errors(text):
|
|
| 125 |
def paraphrase_with_spacy_nltk(text):
|
| 126 |
doc = nlp(text)
|
| 127 |
paraphrased_words = []
|
| 128 |
-
|
| 129 |
for token in doc:
|
| 130 |
# Map SpaCy POS tags to WordNet POS tags
|
| 131 |
pos = None
|
|
@@ -137,11 +140,11 @@ def paraphrase_with_spacy_nltk(text):
|
|
| 137 |
pos = wordnet.ADJ
|
| 138 |
elif token.pos_ == "ADV":
|
| 139 |
pos = wordnet.ADV
|
| 140 |
-
|
| 141 |
synonyms = get_synonyms_nltk(token.text.lower(), pos) if pos else []
|
| 142 |
|
| 143 |
# Replace with a synonym only if it makes sense
|
| 144 |
-
if synonyms
|
| 145 |
paraphrased_words.append(synonyms[0])
|
| 146 |
else:
|
| 147 |
paraphrased_words.append(token.text)
|
|
|
|
| 61 |
|
| 62 |
for token in doc:
|
| 63 |
if token.pos_ == "VERB":
|
| 64 |
+
# Check if verb is in its base form
|
| 65 |
if token.tag_ == "VB" and token.text.lower() not in ["be", "have", "do"]:
|
| 66 |
# Attempt to correct verb form based on sentence context
|
| 67 |
context = " ".join([t.text for t in doc if t.i != token.i])
|
|
|
|
| 114 |
for token in doc:
|
| 115 |
if token.text in ['a', 'an']:
|
| 116 |
next_token = token.nbor(1)
|
| 117 |
+
if token.text == "a" and next_token.text[0].lower() in "aeiou":
|
| 118 |
+
corrected_text.append("an")
|
| 119 |
+
elif token.text == "an" and next_token.text[0].lower() not in "aeiou":
|
| 120 |
+
corrected_text.append("a")
|
| 121 |
else:
|
| 122 |
+
corrected_text.append(token.text)
|
| 123 |
else:
|
| 124 |
corrected_text.append(token.text)
|
| 125 |
return ' '.join(corrected_text)
|
|
|
|
| 128 |
def paraphrase_with_spacy_nltk(text):
|
| 129 |
doc = nlp(text)
|
| 130 |
paraphrased_words = []
|
| 131 |
+
|
| 132 |
for token in doc:
|
| 133 |
# Map SpaCy POS tags to WordNet POS tags
|
| 134 |
pos = None
|
|
|
|
| 140 |
pos = wordnet.ADJ
|
| 141 |
elif token.pos_ == "ADV":
|
| 142 |
pos = wordnet.ADV
|
| 143 |
+
|
| 144 |
synonyms = get_synonyms_nltk(token.text.lower(), pos) if pos else []
|
| 145 |
|
| 146 |
# Replace with a synonym only if it makes sense
|
| 147 |
+
if synonyms:
|
| 148 |
paraphrased_words.append(synonyms[0])
|
| 149 |
else:
|
| 150 |
paraphrased_words.append(token.text)
|