linuxscout/pyarabic

Add a new function to correct punctuation on joined tokens

Closed this issue · 0 comments

I want to Add a function to correct punctuation for joined texts

example :

def fix_punct(text):
    fix_spaces = re.compile(r'\s*([?؟!.,،]+(?:\s+[?؟!.,،]+)*)\s*', re.UNICODE)
    text = fix_spaces.sub(lambda x: "{} ".format(x.group(1).replace(" ", "")), text)
    return text.strip()
fixed = fix_punct(u"كل فرد في الأمة مجند لمعركة المصير : الفلاح في حقله ، والعامل في مصنعه ، والطالب في معهده ، والموظف في ديوانه ")
print(fixed)
>>> 
كل فرد في الأمة مجند لمعركة المصير : الفلاح في حقله، والعامل في مصنعه، والطالب في معهده، والموظف في ديوانه...