clean-text المحتوى الذي تم إنشاؤه بواسطة المستخدم على الويب وفي وسائل التواصل الاجتماعي غالبًا ما يكون قذرًا. المعالجة المسبقة لبياناتك المكثفة مع clean-text لإنشاء تمثيل نص طبيعي. على سبيل المثال ، أدر هذا المدخلات التالفة:
A bunch of \u2018new\u2019 references, including [Moana](https://en.wikipedia.org/wiki/Moana_%282016_film%29).
»Yóù àré rïght <3!«في هذا الناتج النظيف:
A bunch of 'new' references, including [moana](<URL>).
"you are right <3!" يستخدم clean-text ، FTFY ، Unidecode والعديد من القواعد المصنوعة يدويًا ، أي Regex.
لتثبيت الحزمة المرخصة من GPL Unidecode جنبًا إلى جنب:
pip install clean-text[gpl]قد ترغب في الامتناع عن GPL:
pip install clean-text NB: تم تسمية هذه الحزمة clean-text وليس cleantext .
إذا لم يكن UniDecode متاحًا ، فسيتم اللجوء إلى clean-text إلى Unicodedata. يتضمن الترجمة إلى أقرب رموز ASCII التعيينات يدويًا ، ê ، إلى e . رسم خرائط unidecode هو Superiour لكن Unicodedata كافي. ومع ذلك ، قد ترغب في تعطيل هذه الميزة تمامًا حسب بياناتك واستخدام الحالة.
لتوضيح ذلك: هناك تناقضات بين معالجة النص مع أو بدون unidecode .
from cleantext import clean
clean ( "some input" ,
fix_unicode = True , # fix various unicode errors
to_ascii = True , # transliterate to closest ASCII representation
lower = True , # lowercase text
no_line_breaks = False , # fully strip line breaks as opposed to only normalizing them
no_urls = False , # replace all URLs with a special token
no_emails = False , # replace all email addresses with a special token
no_phone_numbers = False , # replace all phone numbers with a special token
no_numbers = False , # replace all numbers with a special token
no_digits = False , # replace all digits with a special token
no_currency_symbols = False , # replace all currency symbols with a special token
no_punct = False , # remove punctuations
replace_with_punct = "" , # instead of removing punctuations you may replace them
replace_with_url = "<URL>" ,
replace_with_email = "<EMAIL>" ,
replace_with_phone_number = "<PHONE>" ,
replace_with_number = "<NUMBER>" ,
replace_with_digit = "0" ,
replace_with_currency_symbol = "<CUR>" ,
lang = "en" # set to 'de' for German special handling
)اختر بعناية الوسائط التي تناسب مهمتك. يتم سرد المعلمات الافتراضية أعلاه.
يمكنك أيضًا استخدام وظائف محددة للتنظيف فقط. لهذا ، ألق نظرة على رمز المصدر.
حتى الآن ، يتم دعم اللغة الإنجليزية والألمانية فقط بالكامل. يجب أن تعمل لغالبية اللغات الغربية. إذا كنت بحاجة إلى بعض المعالجة الخاصة بلغتك ، فلا تتردد في المساهمة. ؟
clean-text مع scikit-learnهناك أيضًا واجهة برمجة تطبيقات متوافقة مع Scikit-Learn لاستخدامها في خطوط الأنابيب الخاصة بك. جميع المعلمات أعلاه تعمل هنا أيضًا.
pip install clean-text[gpl,sklearn]
pip install clean-text[sklearn] from cleantext . sklearn import CleanTransformer
cleaner = CleanTransformer ( no_punct = False , lower = False )
cleaner . transform ([ 'Happily clean your text!' , 'Another Input' ])استخدم الشعر.
إذا كان لديك سؤال أو العثور على خطأ أو ترغب في اقتراح ميزة جديدة ، فقم بإلقاء نظرة على صفحة المشكلات.
يتم الترحيب بطلبات السحب بشكل خاص عند إصلاح الأخطاء أو تحسين جودة الكود.
إذا كنت لا تحب إخراج clean-text ، ففكر في إضافة اختبار مع الإدخال المحدد والإخراج المطلوب.
بنيت على العمل من قبل بيرتون Dewilde للنص.
أباتشي