Last active
December 16, 2022 22:48
-
-
Save linuxscout/79c16c3f1ff40dee663e2146b1933e0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding=utf-8 -*- | |
""" | |
An example of cleaning arabic text with PyArbic Library | |
Requirements: pip install pyarabic | |
Data: text file | |
Ouput: text file ( cleaned) | |
""" | |
import sys | |
import pyarabic.araby as araby | |
def clean_file(file_name, outfile_name): | |
# open file with unicode | |
try: | |
myfile = open(file_name, encoding="utf8") | |
except: | |
print("Can't open file ", file_name) | |
print("Exit from program ", file_name) | |
sys.exit() | |
# read lines from file: | |
lines = myfile.readlines() | |
cleaned_lines = [] | |
# for each line, we do treatment to clean text | |
for text_line in lines: | |
# conditions to make on text, keep only arabic letters and text | |
conditions = [araby.is_arabicrange,] | |
# actions to do on texts, | |
# remove tashkeel | |
# remove all kind of diacrtics like small alif, or other marks koranics for example | |
# remove tatweel | |
morphs = [araby.strip_tashkeel, araby.strip_diacritics, araby.strip_tatweel] | |
tokens = araby.tokenize(text_line,conditions= conditions, morphs= morphs) | |
# tokens is a list, join them to be a cleaned text line | |
cleaned_one_line = " ".join(tokens) + "\n" | |
# append line into a list of cleaned lines | |
cleaned_lines.append(cleaned_one_line) | |
# after treatments, write into files | |
# open destination file | |
try: | |
myoutfile = open(outfile_name, "a+", encoding="utf8",) | |
except: | |
print("Can't open file to write outputs", outfile_name) | |
print("Exit from program ", outfile_name) | |
sys.exit() | |
# write lines into file | |
myoutfile.writelines(cleaned_lines) | |
myoutfile.flush() | |
# close file | |
myoutfile.close() | |
# Main function | |
if __name__ == '__main__': | |
file_name = 'text_file.txt' | |
outfile_name = "output.txt" | |
clean_file(file_name,outfile_name) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
أذكر مشكلة كهذه اعترضتني في مشروع تعريب رسمي، وأظن عندي فكرة عن السبب لذلك يمكن أن أعلق بخصوص الموضوع. | |
ايش بدهم من الأطفال؟ شركة ملابس عالمية فارهة تعمل حملات إعلانية تتضمن إيحاءات جنسية وتقديم قرابين من الأطفال للشيطان | |
ستُغلق خدمة Revue، وهي خدمة النشرات البريدية التي استحوذ عليها تويتر ودمجها في منصته، ولن يعود بالإمكان استخدامها. | |
يبدو أن إيلون ماسك يركّز على أمور محددة فقط بعد استحواذه على تويتر ولا يريد أن يتابع كل شيء كما كان في السابق. | |
https://getrevue.co | |
في هذه الحروف فعل رباعي جميع حروفه أصلية.. ما هو؟ | |
من يريد الحصول على أول تعريب تجاري قانوني للعبة على كمبيوتر العائلة (الفاميكوم) يستطيع أن يحجز نسخته من الآن ♥ | |
بمناسبة هذا الإصدار، أود أشكر جدا @TheAdamSaeed | |
على توفيره شعارا معربا للعبة في وقت قياسي ووفق شروط تقنية دقيقة. وكذلك الناشر على السماح لنا بتعريب اسم اللعبة ♥ | |
تبعاً للخبراء: أفضل نصائح التفاوض على الراتب في مقابلات العمل | |
في فترة التضخم تكثر اتصالات بعض البنوك لمحاولة تدبيسك بقروض تكميليةبعروض مغرية | |
من اجل اخضاعك طيلة حياتك للديون | |
ستكون وليمة بالنسبة لهم ان وافقت من اجل | |
اخذ المال للكماليات الغير طارئة جدا في نفقاتك | |
الشخصية او الاسرة(سيتم التواصل معك فريق) | |
محترف بالاقناع نسائي اورجالي | |
(اسحب عليهم) | |
أذكر مشكلة كهذه اعترضتني في مشروع تعريب رسمي، وأظن عندي فكرة عن السبب لذلك يمكن أن أعلق بخصوص الموضوع. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment