Skip to main content

تبدیل سبک و بدون وابستگی کاراکترهای عربی (حروف و اعداد) به فارسی

Project description

persianize

کتابخونه‌ی سبک و بدون وابستگی (zero-dependency) پایتون برای تبدیل کاراکترهای عربی به معادل فارسی — هم حروف، هم اعداد.

چرا این کتابخونه؟

متن‌های فارسی‌ای که از منابع عربی، کیبوردهای عربی، یا OCR میان، معمولاً حروف و ارقام عربی توشون قاطی فارسیه (مثلاً ي به‌جای ی، یا ١٢٣ به‌جای ۱۲۳). این باعث می‌شه جست‌وجو، مقایسه‌ی رشته‌ها، یا پردازش متن (NLP) نتیجه‌ی اشتباه بده. persianize این مشکل رو با یک تابع ساده حل می‌کنه.

نصب

pip install persianize

یا برای توسعه از روی سورس:

git clone https://github.com/zigzagjimbo/persianize.git
cd persianize
pip install -e ".[dev]"

استفاده به‌عنوان کتابخونه

from persianize import normalize

text = "كتابخانة علي در سال ١٤٠٣ باز شد."
print(normalize(text))
# کتابخانه علی در سال ۱۴۰۳ باز شد.

توابع در دسترس

تابع کاربرد
normalize(text, digits=True, strip_diacritics=False) تبدیل کامل: حروف + (اختیاری) اعداد + (اختیاری) حذف اعراب
convert_letters(text) فقط تبدیل حروف عربی به فارسی
convert_digits(text) فقط تبدیل ارقام عربی به فارسی
remove_diacritics(text) حذف اعراب (فتحه، ضمه، کسره، تشدید...) و کشیده

مثال‌های بیشتر

from persianize import convert_letters, convert_digits, remove_diacritics

convert_letters("كتاب")        # 'کتاب'
convert_digits("٠١٢٣")         # '۰۱۲۳'
remove_diacritics("مُحَمَّد")     # 'محمد'

استفاده از خط فرمان (CLI)

# از آرگومان مستقیم
persianize "كتاب علي"

# از فایل
persianize -f input.txt -o output.txt

# از stdin (pipe)
echo "١٤٠٣" | persianize

# بدون تبدیل اعداد
persianize --no-digits "كتاب ١٤٠٣"

# حذف اعراب هم انجام شود
persianize --strip-diacritics "مُحَمَّد"

چه چیزی تبدیل می‌شه؟

حروف:

عربی فارسی
ي ی
ك ک
ة ه
ى ی
ؤ و
ئ ی
أ / إ ا

اعداد: ٠١٢٣٤٥٦٧٨٩۰۱۲۳۴۵۶۷۸۹

اعراب (اختیاری با strip_diacritics=True): فتحه، ضمه، کسره، تشدید، سکون، تنوین، مدّ، کشیده

اجرای تست‌ها

pip install pytest
pytest

لایسنس

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

persianize-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

persianize-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file persianize-0.1.0.tar.gz.

File metadata

  • Download URL: persianize-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for persianize-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e7a6e65730aa44cb6f3f074ed0ffeecc1aaa7c5a548151beb79a1376b2bc70c
MD5 d65d466d9b47c370bdc04f24f802b347
BLAKE2b-256 6ad390c722c430ae8dad268f5bc4a311bd6bcd6b96877f6778821e0469e8c8e9

See more details on using hashes here.

File details

Details for the file persianize-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: persianize-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for persianize-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dad0e3285658f987da86dd9fca8e39f1dc753e9a8c603df65ed8ed2040378b73
MD5 9f67f892a25ec2710127d2bb9e711550
BLAKE2b-256 3ebf0f2d95fda5e8d18758b262b5d1cd750370df1479185ef3151c0b8ec3d0d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page