sashtech commited on
Commit
9e251df
·
verified ·
1 Parent(s): b815c8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
app.py CHANGED
@@ -5,7 +5,6 @@ import spacy
5
  import subprocess
6
  import nltk
7
  from nltk.corpus import wordnet
8
- from grammarChecker.util import check_becauseError, check_butError, check_TenseError, check_articleError
9
  from pattern.en import conjugate, tenses
10
 
11
  # Initialize the English text classification pipeline for AI detection
@@ -53,6 +52,13 @@ def capitalize_sentences_and_nouns(text):
53
 
54
  return ' '.join(corrected_text)
55
 
 
 
 
 
 
 
 
56
  # Function to check and correct tense consistency in sentences using Pattern.en
57
  def check_tense_consistency(text):
58
  doc = nlp(text)
@@ -83,14 +89,23 @@ def check_tense_consistency(text):
83
 
84
  return ' '.join(corrected_sentences)
85
 
86
- # Function to perform grammar and structure corrections using external grammar functions
87
- def grammar_correction(text):
88
- error_count_because, corrected_text_because = check_becauseError(text)
89
- error_count_but, corrected_text_but = check_butError(corrected_text_because)
90
- error_count_tense, corrected_text_tense = check_TenseError(corrected_text_but)
91
- error_count_article, final_corrected_text = check_articleError(corrected_text_tense)
92
-
93
- return final_corrected_text
 
 
 
 
 
 
 
 
 
94
 
95
  # Paraphrasing function using SpaCy and NLTK (Humanifier)
96
  def paraphrase_with_spacy_nltk(text):
@@ -130,13 +145,16 @@ def paraphrase_and_correct(text):
130
  # Step 1: Paraphrase the text
131
  paraphrased_text = paraphrase_with_spacy_nltk(text)
132
 
133
- # Step 2: Grammar and structure corrections
134
- grammatically_corrected_text = grammar_correction(paraphrased_text)
 
 
 
135
 
136
- # Step 3: Capitalize sentences and proper nouns
137
- capitalized_text = capitalize_sentences_and_nouns(grammatically_corrected_text)
138
 
139
- # Step 4: Check and correct tense consistency
140
  final_text = check_tense_consistency(capitalized_text)
141
 
142
  return final_text
 
5
  import subprocess
6
  import nltk
7
  from nltk.corpus import wordnet
 
8
  from pattern.en import conjugate, tenses
9
 
10
  # Initialize the English text classification pipeline for AI detection
 
52
 
53
  return ' '.join(corrected_text)
54
 
55
+ # Function to check and correct conjunction errors with 'because' and 'but'
56
+ def check_conjunction_errors(text):
57
+ # Replace misplaced 'because' and 'but'
58
+ text = text.replace("because, ", "because ")
59
+ text = text.replace("but, ", "but ")
60
+ return text
61
+
62
  # Function to check and correct tense consistency in sentences using Pattern.en
63
  def check_tense_consistency(text):
64
  doc = nlp(text)
 
89
 
90
  return ' '.join(corrected_sentences)
91
 
92
+ # Function to check and correct article usage ('a', 'an', 'the')
93
+ def check_article_usage(text):
94
+ doc = nlp(text)
95
+ corrected_text = []
96
+
97
+ for token in doc:
98
+ if token.text.lower() in ['a', 'an', 'the']:
99
+ if token.text.lower() == 'a' and token.head.pos_ in ['NOUN', 'ADJ'] and token.head.text[0] in 'aeiou':
100
+ corrected_text.append('an')
101
+ elif token.text.lower() == 'an' and token.head.pos_ in ['NOUN', 'ADJ'] and token.head.text[0] not in 'aeiou':
102
+ corrected_text.append('a')
103
+ else:
104
+ corrected_text.append(token.text)
105
+ else:
106
+ corrected_text.append(token.text)
107
+
108
+ return ' '.join(corrected_text)
109
 
110
  # Paraphrasing function using SpaCy and NLTK (Humanifier)
111
  def paraphrase_with_spacy_nltk(text):
 
145
  # Step 1: Paraphrase the text
146
  paraphrased_text = paraphrase_with_spacy_nltk(text)
147
 
148
+ # Step 2: Check and correct conjunction errors
149
+ corrected_conjunctions = check_conjunction_errors(paraphrased_text)
150
+
151
+ # Step 3: Check and correct article usage
152
+ corrected_articles = check_article_usage(corrected_conjunctions)
153
 
154
+ # Step 4: Capitalize sentences and proper nouns
155
+ capitalized_text = capitalize_sentences_and_nouns(corrected_articles)
156
 
157
+ # Step 5: Check and correct tense consistency
158
  final_text = check_tense_consistency(capitalized_text)
159
 
160
  return final_text