|
import re |
|
import string |
|
import unicodedata |
|
from utils import notification_queue, log_print |
|
|
|
def spell_grammer(text): |
|
try: |
|
|
|
text = text.strip() |
|
text = re.sub(r'\s+', ' ', text) |
|
|
|
|
|
text = ''.join(c for c in text if c.isalnum() or c.isspace() or c in string.punctuation) |
|
|
|
|
|
text = unicodedata.normalize('NFKC', text) |
|
|
|
|
|
text = re.sub(r'\s+([.,!?])', r'\1', text) |
|
text = re.sub(r'([.,!?])\s*([A-Z])', r'\1 \2', text) |
|
|
|
|
|
sentences = re.split(r'([.!?]+)', text) |
|
text = '' |
|
for i in range(0, len(sentences)-1, 2): |
|
text += sentences[i].strip().capitalize() + sentences[i+1] + ' ' |
|
if len(sentences) % 2: |
|
text += sentences[-1].strip().capitalize() |
|
|
|
return text.strip() |
|
|
|
except Exception as e: |
|
error_msg = str(e) |
|
notification_queue.put({ |
|
"type": "error", |
|
"message": f"Error in spell checking: {error_msg}" |
|
}) |
|
return text |