# Ignore distribution archives | |||||
/dist/ | |||||
# Ignore package metadata | |||||
*.egg-info/ |
include README.md | |||||
include LICENSE |
# Persian-Informal-Text-Detector- | |||||
# Persian-Informal-Text-Detector | |||||
Persian Informal Text Detector is a rule-based informal text detector based on regular expressions. It can be used to identify informal Persian text by detecting certain indicators such as informal words and verb formats. | |||||
## Source of Informal Text Indicators | |||||
Some of the informal text indicators, such as informal words and verb formats, are derived from [this Wikipedia page](https://fa.wikipedia.org/wiki/%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7:%D8%A7%D8%B4%D8%AA%D8%A8%D8%A7%D9%87%E2%80%8C%DB%8C%D8%A7%D8%A8/%D9%81%D9%87%D8%B1%D8%B3%D8%AA/%D8%BA%DB%8C%D8%B1%D8%B1%D8%B3%D9%85%DB%8C). | |||||
## Installation | |||||
You can install Persian Informal Text Detector using pip: | |||||
```bash | |||||
pip install informal_detector | |||||
``` | |||||
## Example Usage | |||||
```python | |||||
from informal_detector import is_informal | |||||
# Returns True since the text contains at least one informal indicator | |||||
result1 = is_informal("دلم میخواد برم خونه", threshold=1) | |||||
print(result1) # Output: True | |||||
# Returns False since the text does not contain enough informal indicators | |||||
result2 = is_informal("نباید به خانه بروم", threshold=1) | |||||
print(result2) # Output: False | |||||
``` | |||||
## The threshold Argument | |||||
The `threshold` keyword argument is crucial as it indicates how strict the detector should be. It determines the number of informal Persian indicators, such as informal words and verbs, required to classify a text as informal. | |||||
A lower threshold is suitable for smaller text files, while a higher threshold is more appropriate for larger files where some formal sentences might exist but the text should still be marked as informal if it contain a significant number of informal indicators. A threshold of 1 means that a text is considered informal if it contains at least one informal word or verb. |
from .is_informal import is_informal |
import re | |||||
# **NOTE:** The roots and some of the words used above are form this [link](https://fa.wikipedia.org/wiki/%D9%88%DB%8C%DA%A9%DB%8C%E2%80%8C%D9%BE%D8%AF%DB%8C%D8%A7:%D8%A7%D8%B4%D8%AA%D8%A8%D8%A7%D9%87%E2%80%8C%DB%8C%D8%A7%D8%A8/%D9%81%D9%87%D8%B1%D8%B3%D8%AA/%D8%BA%DB%8C%D8%B1%D8%B1%D8%B3%D9%85%DB%8C). | |||||
words = ['توش', 'آتیش', 'توی', 'همونطور', 'اگه', 'تیکه', 'یهو', 'واسه', 'واسم', 'واست', 'واسش', 'واسمون', 'واستون', 'واسشون', 'رمضون', 'دیگه', 'اینا', 'اونا', 'بهش', 'هیچی', 'برام', 'برات', 'برامون', 'براشون', 'براتون', 'براش', 'والا', 'دوس', 'ایش', 'هرچی', 'چی', 'آره', 'چطوری', 'چه\u200cطوری', 'چقد', 'یه', 'بارون', 'ازم', 'ازت', 'ازش', 'ازمون', 'ازتون', 'ازشون', 'اصن', 'اینو', 'اونو', 'اینارو', 'اونارو', 'زبون', 'بابا', 'بابام', 'بابات', 'باباش', 'بابامون', 'باباتون', 'باباشون', 'ماما', 'مامان', 'مامانم', 'مامانت', 'مامانمون', 'مامانتون', 'مامانشون', 'آسون', 'دیگه\u200cای', 'بهت', 'بهش', 'بهمون', 'بهتون', 'بهشون', 'خونه', 'جون', 'ایشالا', 'ماشالا', 'ایشون', 'اونه', 'اینجوری', 'بازم', 'باهام', 'باهات', 'باهاش', 'باهامون', 'باهاتون', 'باهاشون', 'تموم', 'چجوری', 'چیه', 'کدوم', 'آروم', 'ایرونی', 'بادمجون', 'بچگونه', 'بیابون', 'تهرون', 'دندون', 'خودتون', 'خودشون', 'خودمون', 'خودمونی', 'خیابون', 'داره', 'داروخونه', 'داغون', 'دخترونه', 'دندون', 'رودخونه', 'زمونه', 'زنونه', 'قلیون', 'مردونه', 'مهمون', 'میونه', 'میون', 'نشونه', 'نشون', 'نیستن', 'هستن', 'همزبون', 'همشون', 'پسرونه', 'کوچیک', 'تموم', 'تمومه', 'انقد'] | |||||
roots1 = 'پاشون|[یا]فشون|پرورون|پرون|پوسون|پوشون|پیچون|تابون|تازون|ترسون|ترکون|تکون|جنبون|جوشون|چپون|چربون|چرخون|چرون|چسبون|چشون|چکون|چلون|خارون|خراشون|خشکون|خندون|خوابون|خورون|خون|خیسون|درخشون|رسون|رقصون|رنجون|رون|سابون|ستون|سوزون|شورون|غلتون|فهمون|کوبون|گذرون|گردون|گریون|گسترون|گنجون|لرزون|لغزون|لمبون|مالون|نشون|وزون|تونست|دون|ش' | |||||
roots2 = 'پاشون|[یا]فشون|پرورون|پرون|پوسون|پوشون|پیچون|تابون|تازون|ترسون|ترکون|تکون|جنبون|جوشون|چپون|چربون|چرخون|چرون|چسبون|چشون|چکون|چلون|خارون|خراشون|خشکون|خندون|خوابون|خورون|خون|خیسون|درخشون|رسون|رقصون|رنجون|رون|سابون|ستون|سوزون|شورون|غلتون|فهمون|کوبون|گذرون|گردون|گریون|گسترون|گنجون|لرزون|لغزون|لمبون|مالون|وزون' | |||||
roots3 = 'خوا' | |||||
roots4 = 'مون|شین|گ' | |||||
roots5 = 'د|تون' | |||||
roots6 = 'یا' | |||||
roots7 = 'ر' | |||||
start_regex = '(?:\s|\.|\?|!|-|\+|=|\*|/|\\|\]|\[|\}|\{|"|\'|;|؛|,|#|$\|%|\(|\)|،|«|»|؟|^)' | |||||
end_regex = '(?:\s|\.|\?|!|-|\+|=|\*|/|\\|\]|\[|\}|\{|"|\'|;|؛|,|#|$\|%|\(|\)|،|«|»|؟|$)' | |||||
regexes = [ | |||||
start_regex + r'(?:' + '|'.join(re.escape(word) for word in words) + r')' + end_regex, | |||||
start_regex + r'(?:(?:ب|ن)|(?:(?:می|نمی)[\s\u200c]*))(?:' + roots1 + r')(?:م|ی|ه|یم|ید|ین|ن)' + end_regex, | |||||
start_regex + r'(?:' + roots2 + r')د(?:م|ی||یم|ید|ین|ن)(?:\b|،|«|»|؟|$)', | |||||
start_regex + r'(?:(?:ب|ن)|(?:(?:می|نمی)[\s\u200c]*))(?:' + roots3 + r')(?:م|ی|یم|ید|ین)' + end_regex, | |||||
start_regex + r'(?:ب|(?:(?:می|نمی)[\s\u200c]*))(?:' + roots4 + r')(?:م|ی|ه|یم|ید|ین|ن)' + end_regex, | |||||
start_regex + r'(?:ن|(?:(?:می|نمی)[\s\u200c]*))(?:' + roots5 + r')(?:م|ی|ه|یم|ید|ین|ن)' + end_regex, | |||||
start_regex + r'(?:ن|نمی[\s\u200c]*)(?:' + roots6 + r')(?:م|ه|یم|ید|ین|ن)' + end_regex, | |||||
start_regex + r'می[\s\u200c]*(?:' + roots7 + r')(?:م|ی|ه|یم|ید|ین|ن)' + end_regex, | |||||
] | |||||
def is_informal(text, threshold=1): | |||||
matches = 0 | |||||
for regex in regexes: | |||||
matches += len(re.findall(regex, text)) | |||||
return True if matches >= threshold else False |
from setuptools import setup, find_packages | |||||
setup( | |||||
name="informal_detector", | |||||
version="0.1.1", | |||||
description="A Python package to check if a text is informal Persian.", | |||||
long_description=open('README.md', 'r', encoding='utf-8').read(), | |||||
long_description_content_type='text/markdown', | |||||
author="Mahta Fetrat", | |||||
author_email="[email protected]", | |||||
url="https://github.com/MahtaFetrat/Persian-Informal-Text-Detector", | |||||
packages=find_packages(), | |||||
classifiers=[ | |||||
"Programming Language :: Python :: 3", | |||||
"Programming Language :: Python :: 2.7", | |||||
"License :: OSI Approved :: GNU General Public License (GPL)", | |||||
"Operating System :: OS Independent", | |||||
], | |||||
python_requires='>=2.7', | |||||
) |