From b86319c4d8155a1808c9d1e372bf26578759bb65 Mon Sep 17 00:00:00 2001 From: Amir Shokri Date: Sun, 10 Jul 2022 11:39:16 +0430 Subject: [PATCH] 1.6.1 --- PersianSwear.ipynb | 191 +++++++++------------ PersianSwear.js | 414 ++++++++++++++++++++++++++++++++++++++------- PersianSwear.php | 58 +++---- PersianSwear.py | 109 ++++++------ package.json | 2 +- 5 files changed, 515 insertions(+), 259 deletions(-) diff --git a/PersianSwear.ipynb b/PersianSwear.ipynb index 8e88568..356bd8c 100644 --- a/PersianSwear.ipynb +++ b/PersianSwear.ipynb @@ -1,73 +1,24 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "PersianSwear.ipynb", - "provenance": [], - "collapsed_sections": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { "cell_type": "code", - "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 35 - }, - "id": "7Wb8RcdDxWRz", - "outputId": "dab7c749-e24e-4c1a-f48e-ead33bb8aeff" - }, - "source": [ - "\"\"\"\n", - "PersianSwear Class\n", - "Author : Amir Shokri @amirshnll\n", - "created date : 11 October, 2021\n", - "updated date : 11 October, 2021\n", - "\"\"\"" - ], - "execution_count": 1, - "outputs": [ - { - "output_type": "execute_result", - "data": { - "application/vnd.google.colaboratory.intrinsic+json": { - "type": "string" - }, - "text/plain": [ - "'\\nPersianSwear Class\\nAuthor : Amir Shokri @amirshnll\\ncreated date : 11 October, 2021\\nupdated date : 11 October, 2021\\n'" - ] - }, - "metadata": {}, - "execution_count": 1 - } - ] - }, - { - "cell_type": "code", + "execution_count": 2, "metadata": { "id": "ajlUjU3ehD6b" }, + "outputs": [], "source": [ "import json\n", "import os.path" - ], - "execution_count": 2, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": 3, "metadata": { "id": "S1mNMY5ZiKEB" }, + "outputs": [], "source": [ "class PersianSwear(object):\n", "\tdef __init__(self):\n", @@ -118,23 +69,22 @@ "\t# return string\n", "\tdef tostring(self):\n", "\t\treturn ' - '.join(self.data['word'])" - ], - "execution_count": 3, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": 4, "metadata": { "id": "3Dbw32YXiZ65" }, + "outputs": [], "source": [ "persianswear = PersianSwear()" - ], - "execution_count": 4, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -142,22 +92,22 @@ "id": "x5-Ju8yytO9n", "outputId": "1170ff4f-b255-4651-fabf-2e8191afb498" }, - "source": [ - "print(persianswear.is_bad('خر'))" - ], - "execution_count": 5, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "True\n" ] } + ], + "source": [ + "print(persianswear.is_bad('خر'))" ] }, { "cell_type": "code", + "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -165,22 +115,22 @@ "id": "x0t4bz2UumUJ", "outputId": "64059f34-cc27-4455-fb00-dcd99fce5b03" }, - "source": [ - "print(persianswear.is_bad('امروز'))" - ], - "execution_count": 6, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "False\n" ] } + ], + "source": [ + "print(persianswear.is_bad('امروز'))" ] }, { "cell_type": "code", + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -188,22 +138,22 @@ "id": "iTSJNtP4uqbe", "outputId": "2972288e-f8ac-4091-94b1-5bdd55baf801" }, - "source": [ - "print(persianswear.is_bad('چرت و پرت'))" - ], - "execution_count": 7, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "False\n" ] } + ], + "source": [ + "print(persianswear.is_bad('چرت و پرت'))" ] }, { "cell_type": "code", + "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -211,23 +161,23 @@ "id": "rupNi8hduw43", "outputId": "c64b420c-9e50-47be-89ff-f87e44bc61ae" }, - "source": [ - "persianswear.add_word('چرت و پرت')\n", - "print(persianswear.is_bad('چرت و پرت'))" - ], - "execution_count": 8, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "True\n" ] } + ], + "source": [ + "persianswear.add_word('چرت و پرت')\n", + "print(persianswear.is_bad('چرت و پرت'))" ] }, { "cell_type": "code", + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -235,22 +185,22 @@ "id": "tOuLyR56vSYo", "outputId": "562d6bba-2d17-4fc4-c064-e23a46c70d1e" }, - "source": [ - "print(persianswear.has_swear('تو دوست من هستی'))" - ], - "execution_count": 9, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "False\n" ] } + ], + "source": [ + "print(persianswear.has_swear('تو دوست من هستی'))" ] }, { "cell_type": "code", + "execution_count": 10, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -258,22 +208,22 @@ "id": "2Nu974hvvXKw", "outputId": "fdadd1e9-b856-4002-9ab0-6ff2ea370add" }, - "source": [ - "print(persianswear.has_swear('تو هیز هستی'))" - ], - "execution_count": 10, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "True\n" ] } + ], + "source": [ + "print(persianswear.has_swear('تو هیز هستی'))" ] }, { "cell_type": "code", + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -281,22 +231,22 @@ "id": "IYMZglRHwLvl", "outputId": "f02b5253-fcf3-4fd8-c55f-81b0c0d20bd3" }, - "source": [ - "print(persianswear.filter_words('تو دوست من هستی'))" - ], - "execution_count": 11, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "تو دوست من هستی\n" ] } + ], + "source": [ + "print(persianswear.filter_words('تو دوست من هستی'))" ] }, { "cell_type": "code", + "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -304,22 +254,22 @@ "id": "veQekNghwT35", "outputId": "75ca8908-cfa6-4d90-d174-d2dd53de0103" }, - "source": [ - "print(persianswear.filter_words('تو هیز هستی'))" - ], - "execution_count": 12, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "تو * هستی\n" ] } + ], + "source": [ + "print(persianswear.filter_words('تو هیز هستی'))" ] }, { "cell_type": "code", + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -327,22 +277,22 @@ "id": "9VlNqwvJwURb", "outputId": "d2cc5db7-c131-439d-fff2-1232aca3553f" }, - "source": [ - "print(persianswear.filter_words('تو هیز هستی', '&'))" - ], - "execution_count": 13, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "تو & هستی\n" ] } + ], + "source": [ + "print(persianswear.filter_words('تو هیز هستی', '&'))" ] }, { "cell_type": "code", + "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -350,19 +300,34 @@ "id": "fsrpcX4jmFJG", "outputId": "42a2ec91-5357-468e-a948-c860b101301a" }, - "source": [ - "print(persianswear.tostring())" - ], - "execution_count": 14, "outputs": [ { - "output_type": "stream", "name": "stdout", + "output_type": "stream", "text": [ "آب کیر - آشغال - آلت تناسلی - آلت - ابله - ابن یزید - احمق - اسب - اسبی - اسکل - اسکل - اسگل - اسگول - الاغ - الاق - انگل - انی - انی - اوسکل - اوسکل - اوسگل - اوصکل - اوصگل - ب ک - باسن - بخورش - بدبخت - بمال - تخمم - کیرم - بپرروش - بپرسرش - کونی - بکارت - بکن توش - بکنش - بکنمت - خایه - بی عفت - بی غیرت - بی ناموس - بی پدر - بیابخورش - بیشعور - بیناموس - تخم سگ - تخمی - ترک - توله سگ - جاکش - جلق زدن - جنده - جنسی - جوون - جکس - جیندا - حرومزاده - حشر - حشری شدن - حشری - حیوانی - خارکس ده - خارکسده - خارکسّه - خانم جنده - خایه خور - خایه مال - خایه - خر - خرفت - خری - خز - خفه خون - خفه شو - خواهرجنده - خی کاس - داف ناز - داف - داگ استایل - دخترجنده - دخترقرتی - درازگوش - دله - دهن سرویس - گاییده - دهنت سرویس - دوجنسه - دول - دیوث - دیوس خان - دیوس - دیوص - رشتی - ریدن - ریدی - زارت - زباله - زرنزن - زن جنده - زن کاسده - زنا زاده - زنا - زنازاده - زنتو - زنشو - زنیکه - سادیسمی - ساک - ساکونی - سرخور - سرکیر - سسکی - سوراخ کون - سوراخ کون - سولاخ - سکس چت - سکس - سکسی باش - سکسی - سکسیم - سکسیی - سگ تو روحت - سگ دهن - سگ صفت - سگ پدر - سگی - سیکتیر - شاسگول - شاش - شق کردن - شل مغز - شنگول - شهوتی - صیغه ای - صیک - عرب - عرق خور - عمتو - عمه ننه - عن تر - عن - عنتر - عوضی - غرمساق - غرمصاق - فاحشه خانم - فاحشه - فارس - فاک فیس - فیلم سوپر - قرتی - قرمساق - قرمصاق - قس - لا پا - لاس - لاش گوشت - لاشی - لاکونی - لجن - لخت - لختی - لر - لز - مادر جنده - مادرجنده - مادرسگ - مادرقهوه - مادرکونی - مالوندن - ماچ کردنی - مرتیکه - مردیکه - مرض داری - مرضداری - مشروب - ملنگ - ممه خور - ممه - منگل - میخوریش - نرکده - نعشه - نکبت - نگاییدم - هیز - ولدزنا - پدر سوخته - پدر سگ - پدر صلواتی - پدرسگ - پریود - پستان - پسون - پشمام - پفیوز - پلشت - پورن - پپه - چاغال - چاقال - چس خور - چس - کاسکش - کث لیس - کث - کثافت - کثافط - کردن - کردنی - کرم - کس خل - کس خور - کس خیس - کس دادن - کس لیس - کس لیسیدن - کس ننت - کس و کیر - کس کردن - کس کش - کس - کسخل - کسشعر - کسکش - کسکیر - کص خل - کص لیس - کص - کصافت - کصافط - کصخل - کصکش - کلفت - کله کیری - کوث لیس - کوس خل - کوس خور - کوس لیس - کوس - کوص خل - کوص لیس - کوص - کون تپل - کون ده - کون سوراخ - کون پنیر - کون گنده - کون - کونده خار - کونده خوار - کونده - کونشو - کونی - کونی - کیر - کیردراز - کیردوس - کیرر - کیرمکیدن - کیرناز - کیروکس - کیروکس - کیری - گاو - گاوی - گاگول - گایدن - گایدی - گاییدن - گردن دراز - گشاد - گوز - گوزو - گوسفند - گوش دراز - گوه - گوه - گی زن - گیخوار - یبن زنا - مادرتو - ناموستو - چنده - باسنی - سیکیم - سگ ناموس - نوب - خایمال - مادر به خطا - کصلیس - بکنت - کصده - گورومساخ - پوفیوز - پدرتو - قورومساق - سیهدیر - اوبی - مادر سگ - نگایدم - چرت و پرت\n" ] } + ], + "source": [ + "print(persianswear.tostring())" ] } - ] -} \ No newline at end of file + ], + "metadata": { + "colab": { + "collapsed_sections": [], + "name": "PersianSwear.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/PersianSwear.js b/PersianSwear.js index 491be78..76fc654 100644 --- a/PersianSwear.js +++ b/PersianSwear.js @@ -1,62 +1,356 @@ -/* -* swearWords Class -* Author : Amir Shokri @amirshnll -* created date : 29 October, 2021 -* updated date : 11 October, 2021 -*/ - -var words = ["آب کیر","آشغال","آلت تناسلی","آلت","ابله","ابن یزید","احمق","اسب","اسبی","اسکل","اسکل","اسگل","اسگول","الاغ","الاق","انگل","انی","انی","اوسکل","اوسکل","اوسگل","اوصکل","اوصگل","ب ک","باسن","بخورش","بدبخت","بمال","تخمم","کیرم","بپرروش","بپرسرش","کونی","بکارت","بکن توش","بکنش","بکنمت","خایه","بی عفت","بی غیرت","بی ناموس","بی پدر","بیابخورش","بیشعور","بیناموس","تخم سگ","تخمی","ترک","توله سگ","جاکش","جلق زدن","جنده","جنسی","جوون","جکس","جیندا","حرومزاده","حشر","حشری شدن","حشری","حیوانی","خارکس ده","خارکسده","خارکسّه","خانم جنده","خایه خور","خایه مال","خایه","خر","خرفت","خری","خز","خفه خون","خفه شو","خواهرجنده","خی کاس","داف ناز","داف","داگ استایل","دخترجنده","دخترقرتی","درازگوش","دله","دهن سرویس","گاییده","دهنت سرویس","دوجنسه","دول","دیوث","دیوس خان","دیوس","دیوص","رشتی","ریدن","ریدی","زارت","زباله","زرنزن","زن جنده","زن کاسده","زنا زاده","زنا","زنازاده","زنتو","زنشو","زنیکه","سادیسمی","ساک","ساکونی","سرخور","سرکیر","سسکی","سوراخ کون","سوراخ کون","سولاخ","سکس چت","سکس","سکسی باش","سکسی","سکسیم","سکسیی","سگ تو روحت","سگ دهن","سگ صفت","سگ پدر","سگی","سیکتیر","شاسگول","شاش","شق کردن","شل مغز","شنگول","شهوتی","صیغه ای","صیک","عرب","عرق خور","عمتو","عمه ننه","عن تر","عن","عنتر","عوضی","غرمساق","غرمصاق","فاحشه خانم","فاحشه","فارس","فاک فیس","فیلم سوپر","قرتی","قرمساق","قرمصاق","قس","لا پا","لاس","لاش گوشت","لاشی","لاکونی","لجن","لخت","لختی","لر","لز","مادر جنده","مادرجنده","مادرسگ","مادرقهوه","مادرکونی","مالوندن","ماچ کردنی","مرتیکه","مردیکه","مرض داری","مرضداری","مشروب","ملنگ","ممه خور","ممه","منگل","میخوریش","نرکده","نعشه","نکبت","نگاییدم","هیز","ولدزنا","پدر سوخته","پدر سگ","پدر صلواتی","پدرسگ","پریود","پستان","پسون","پشمام","پفیوز","پلشت","پورن","پپه","چاغال","چاقال","چس خور","چس","کاسکش","کث لیس","کث","کثافت","کثافط","کردن","کردنی","کرم","کس خل","کس خور","کس خیس","کس دادن","کس لیس","کس لیسیدن","کس ننت","کس و کیر","کس کردن","کس کش","کس","کسخل","کسشعر","کسکش","کسکیر","کص خل","کص لیس","کص","کصافت","کصافط","کصخل","کصکش","کلفت","کله کیری","کوث لیس","کوس خل","کوس خور","کوس لیس","کوس","کوص خل","کوص لیس","کوص","کون تپل","کون ده","کون سوراخ","کون پنیر","کون گنده","کون","کونده خار","کونده خوار","کونده","کونشو","کونی","کونی","کیر","کیردراز","کیردوس","کیرر","کیرمکیدن","کیرناز","کیروکس","کیروکس","کیری","گاو","گاوی","گاگول","گایدن","گایدی","گاییدن","گردن دراز","گشاد","گوز","گوزو","گوسفند","گوش دراز","گوه","گوه","گی زن","گیخوار","یبن زنا","مادرتو","ناموستو","چنده","باسنی","سیکیم","سگ ناموس","نوب","خایمال","مادر به خطا","کصلیس","بکنت","کصده","گورومساخ","پوفیوز","پدرتو","قورومساق","سیهدیر","اوبی","مادر سگ","نگایدم"]; +var words = [ + "آب کیر", + "آشغال", + "آلت تناسلی", + "آلت", + "ابله", + "ابن یزید", + "احمق", + "اسب", + "اسبی", + "اسکل", + "اسکل", + "اسگل", + "اسگول", + "الاغ", + "الاق", + "انگل", + "انی", + "انی", + "اوسکل", + "اوسکل", + "اوسگل", + "اوصکل", + "اوصگل", + "ب ک", + "باسن", + "بخورش", + "بدبخت", + "بمال", + "تخمم", + "کیرم", + "بپرروش", + "بپرسرش", + "کونی", + "بکارت", + "بکن توش", + "بکنش", + "بکنمت", + "خایه", + "بی عفت", + "بی غیرت", + "بی ناموس", + "بی پدر", + "بیابخورش", + "بیشعور", + "بیناموس", + "تخم سگ", + "تخمی", + "ترک", + "توله سگ", + "جاکش", + "جلق زدن", + "جنده", + "جنسی", + "جوون", + "جکس", + "جیندا", + "حرومزاده", + "حشر", + "حشری شدن", + "حشری", + "حیوانی", + "خارکس ده", + "خارکسده", + "خارکسّه", + "خانم جنده", + "خایه خور", + "خایه مال", + "خایه", + "خر", + "خرفت", + "خری", + "خز", + "خفه خون", + "خفه شو", + "خواهرجنده", + "خی کاس", + "داف ناز", + "داف", + "داگ استایل", + "دخترجنده", + "دخترقرتی", + "درازگوش", + "دله", + "دهن سرویس", + "گاییده", + "دهنت سرویس", + "دوجنسه", + "دول", + "دیوث", + "دیوس خان", + "دیوس", + "دیوص", + "رشتی", + "ریدن", + "ریدی", + "زارت", + "زباله", + "زرنزن", + "زن جنده", + "زن کاسده", + "زنا زاده", + "زنا", + "زنازاده", + "زنتو", + "زنشو", + "زنیکه", + "سادیسمی", + "ساک", + "ساکونی", + "سرخور", + "سرکیر", + "سسکی", + "سوراخ کون", + "سوراخ کون", + "سولاخ", + "سکس چت", + "سکس", + "سکسی باش", + "سکسی", + "سکسیم", + "سکسیی", + "سگ تو روحت", + "سگ دهن", + "سگ صفت", + "سگ پدر", + "سگی", + "سیکتیر", + "شاسگول", + "شاش", + "شق کردن", + "شل مغز", + "شنگول", + "شهوتی", + "صیغه ای", + "صیک", + "عرب", + "عرق خور", + "عمتو", + "عمه ننه", + "عن تر", + "عن", + "عنتر", + "عوضی", + "غرمساق", + "غرمصاق", + "فاحشه خانم", + "فاحشه", + "فارس", + "فاک فیس", + "فیلم سوپر", + "قرتی", + "قرمساق", + "قرمصاق", + "قس", + "لا پا", + "لاس", + "لاش گوشت", + "لاشی", + "لاکونی", + "لجن", + "لخت", + "لختی", + "لر", + "لز", + "مادر جنده", + "مادرجنده", + "مادرسگ", + "مادرقهوه", + "مادرکونی", + "مالوندن", + "ماچ کردنی", + "مرتیکه", + "مردیکه", + "مرض داری", + "مرضداری", + "مشروب", + "ملنگ", + "ممه خور", + "ممه", + "منگل", + "میخوریش", + "نرکده", + "نعشه", + "نکبت", + "نگاییدم", + "هیز", + "ولدزنا", + "پدر سوخته", + "پدر سگ", + "پدر صلواتی", + "پدرسگ", + "پریود", + "پستان", + "پسون", + "پشمام", + "پفیوز", + "پلشت", + "پورن", + "پپه", + "چاغال", + "چاقال", + "چس خور", + "چس", + "کاسکش", + "کث لیس", + "کث", + "کثافت", + "کثافط", + "کردن", + "کردنی", + "کرم", + "کس خل", + "کس خور", + "کس خیس", + "کس دادن", + "کس لیس", + "کس لیسیدن", + "کس ننت", + "کس و کیر", + "کس کردن", + "کس کش", + "کس", + "کسخل", + "کسشعر", + "کسکش", + "کسکیر", + "کص خل", + "کص لیس", + "کص", + "کصافت", + "کصافط", + "کصخل", + "کصکش", + "کلفت", + "کله کیری", + "کوث لیس", + "کوس خل", + "کوس خور", + "کوس لیس", + "کوس", + "کوص خل", + "کوص لیس", + "کوص", + "کون تپل", + "کون ده", + "کون سوراخ", + "کون پنیر", + "کون گنده", + "کون", + "کونده خار", + "کونده خوار", + "کونده", + "کونشو", + "کونی", + "کونی", + "کیر", + "کیردراز", + "کیردوس", + "کیرر", + "کیرمکیدن", + "کیرناز", + "کیروکس", + "کیروکس", + "کیری", + "گاو", + "گاوی", + "گاگول", + "گایدن", + "گایدی", + "گاییدن", + "گردن دراز", + "گشاد", + "گوز", + "گوزو", + "گوسفند", + "گوش دراز", + "گوه", + "گوه", + "گی زن", + "گیخوار", + "یبن زنا", + "مادرتو", + "ناموستو", + "چنده", + "باسنی", + "سیکیم", + "سگ ناموس", + "نوب", + "خایمال", + "مادر به خطا", + "کصلیس", + "بکنت", + "کصده", + "گورومساخ", + "پوفیوز", + "پدرتو", + "قورومساق", + "سیهدیر", + "اوبی", + "مادر سگ", + "نگایدم", +]; var PersianSwear = { - initial: function() { - if(words.length==0) - PersianSwear.load_data(); - }, - load_data: function() { - var requestURL = 'data.json'; - var request = new XMLHttpRequest(); - request.open('GET', requestURL); - request.responseType = 'json'; - request.send(); - request.onload = function() { - var raw_file = request.response; - words = raw_file.word; - } - }, - add_word: function(text) { // return nothing - PersianSwear.initial(); - const found = words.find(e => e == text); - if (found == undefined) - words.push(text) - }, - remove_word: function(text) { // return nothing - PersianSwear.initial(); - words = words.filter(e => e != text); - }, - is_bad: function(text) { // return boolean - PersianSwear.initial(); - const found = words.find(e => e == text); - if (found == undefined) - return false; - return true; - }, - has_swear: function(text) { // return boolean - PersianSwear.initial(); - for (let index = 0; index < words.length; index++) - if (text.includes(words[index])) - return true; - return false; - }, - filter_words: function(text,symbol="*") { // return string - var text_result = ""; - var text_splited = text.split(" "); - for (var i = 0; i < text_splited.length; i++) { - if(PersianSwear.is_bad(text_splited[i])) - text_result += symbol; - else - text_result += text_splited[i]; - text_result += " "; - } - - return text_result; + initial: function () { + if (words.length == 0) PersianSwear.load_data(); + }, + load_data: function () { + var requestURL = "data.json"; + var request = new XMLHttpRequest(); + request.open("GET", requestURL); + request.responseType = "json"; + request.send(); + request.onload = function () { + var raw_file = request.response; + words = raw_file.word; + }; + }, + add_word: function (text) { + // return nothing + PersianSwear.initial(); + const found = words.find((e) => e == text); + if (found == undefined) words.push(text); + }, + remove_word: function (text) { + // return nothing + PersianSwear.initial(); + words = words.filter((e) => e != text); + }, + is_bad: function (text) { + // return boolean + PersianSwear.initial(); + const found = words.find((e) => e == text); + if (found == undefined) return false; + return true; + }, + has_swear: function (text) { + // return boolean + PersianSwear.initial(); + for (let index = 0; index < words.length; index++) + if (text.includes(words[index])) return true; + return false; + }, + filter_words: function (text, symbol = "*") { + // return string + var text_result = ""; + var text_splited = text.split(" "); + for (var i = 0; i < text_splited.length; i++) { + if (PersianSwear.is_bad(text_splited[i])) text_result += symbol; + else text_result += text_splited[i]; + text_result += " "; } -} \ No newline at end of file + + return text_result; + }, +}; diff --git a/PersianSwear.php b/PersianSwear.php index b571d90..bfa1194 100644 --- a/PersianSwear.php +++ b/PersianSwear.php @@ -1,19 +1,13 @@ data = file_get_contents('data.json'); $this->data_encoded = json_decode($this->data, true); $this->words = $this->data_encoded['word']; @@ -22,58 +16,64 @@ public function __construct() { } // return boolean - public function is_empty() { - if(count($this->words) < 1) + public function is_empty() + { + if (count($this->words) < 1) return true; return false; } // return string - public function filter_words($text, $symbol = "*") { - if($this->is_empty()) + public function filter_words($text, $symbol = "*") + { + if ($this->is_empty()) return $text; - + $filterCount = sizeof((array) $this->words); for ($i = 0; $i < $filterCount; $i++) { - $text = preg_replace('['.$this->words[$i].']', str_repeat($symbol, strlen('$0')), $text); + $text = preg_replace('[' . $this->words[$i] . ']', str_repeat($symbol, strlen('$0')), $text); } return $text; } // return nothing - public function add_word($text) { + public function add_word($text) + { $this->words[count($this->words)] = ltrim(rtrim($text)); } // return nothing - public function remove_word($text) { + public function remove_word($text) + { $text = ltrim(rtrim($text)); - for ($i=0; $i <= count($this->words) - 1; $i++) - if($this->words[$i] == $text) + for ($i = 0; $i <= count($this->words) - 1; $i++) + if ($this->words[$i] == $text) $this->words[$i] = null; } // return boolean - public function is_bad($text) { - if(empty(ltrim(rtrim($this->filter_words($text,""))))) + public function is_bad($text) + { + if (empty(ltrim(rtrim($this->filter_words($text, ""))))) return true; return false; } // return boolean - public function has_swear($text) { + public function has_swear($text) + { $text_splited = str_split(ltrim(rtrim($text, " "))); foreach ($text_splited as $key => $val) { - if($this->is_bad($val)) + if ($this->is_bad($val)) return true; } return false; } // return string - public function tostring() { - return implode(" ",(array) $this->data); + public function tostring() + { + return implode(" ", (array) $this->data); } - -} \ No newline at end of file +} diff --git a/PersianSwear.py b/PersianSwear.py index eb2eec4..afb4909 100644 --- a/PersianSwear.py +++ b/PersianSwear.py @@ -1,70 +1,67 @@ -""" -swearWords Class -Author : Sorosh Safari @coci -created date : 7 October, 2021 -updated date : 11 October, 2021 -""" import json from string import punctuation + + class PersianSwear(object): - def __init__(self): - self.data = json.load(open('data.json')) + def __init__(self): + self.data = json.load(open('data.json')) + + # Rmove punctuation characters from text + # return string + def ignoreSY(self, text): + for i in punctuation: + if i in text: + text = text.replace(i, '') + return text + # return string - #Rmove punctuation characters from text - # return string - def ignoreSY(self, text): - for i in punctuation: - if i in text: - text=text.replace(i,'') - return text - # return string - def filter_words(self, text , symbol="*" , ignoreOT=False): - if(self.is_empty()): - return text + def filter_words(self, text, symbol="*", ignoreOT=False): + if(self.is_empty()): + return text - text = text.split() - for i in range(len(text)): - if text[i] in self.data['word'] or (ignoreOT and self.ignoreSY(text[i]) in self.data['word']): - text[i] = symbol + text = text.split() + for i in range(len(text)): + if text[i] in self.data['word'] or (ignoreOT and self.ignoreSY(text[i]) in self.data['word']): + text[i] = symbol - return " ".join(text) + return " ".join(text) - # return boolean - def is_empty(self): - if(len(self.data['word'])<1): - return True; - return False; + # return boolean + def is_empty(self): + if(len(self.data['word']) < 1): + return True + return False - # return nothing - def add_word(self, text): - self.data['word'].append(text) + # return nothing + def add_word(self, text): + self.data['word'].append(text) - # return nothing - def remove_word(self, text): - self.data['word'].remove(text) + # return nothing + def remove_word(self, text): + self.data['word'].remove(text) - # return boolean - def is_bad(self, text , ignoreOT=False): - if ignoreOT: - text=self.ignoreSY(text) - text=text.replace("\u200c","") - return text in self.data['word'] + # return boolean + def is_bad(self, text, ignoreOT=False): + if ignoreOT: + text = self.ignoreSY(text) + text = text.replace("\u200c", "") + return text in self.data['word'] - # return boolean - def has_swear(self, text , ignoreOT=False): - if ignoreOT: - text=self.ignoreSY(text) - text=text.replace("\u200c","") - if(self.is_empty()): - return text + # return boolean + def has_swear(self, text, ignoreOT=False): + if ignoreOT: + text = self.ignoreSY(text) + text = text.replace("\u200c", "") + if(self.is_empty()): + return text - text = text.split() - for i in range(len(text)): - if text[i] in self.data['word']: - return True + text = text.split() + for i in range(len(text)): + if text[i] in self.data['word']: + return True - return False + return False - # return string - def tostring(self): - return ' - '.join(self.data['word']) + # return string + def tostring(self): + return ' - '.join(self.data['word']) diff --git a/package.json b/package.json index 95ef6c4..51f0504 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "persian-swear-words", - "version": "1.3.0", + "version": "1.6.1", "description": "unwanted content. Wordlist is available in JSON format and there is also a helper function written in JavaScript to assist you how to use this datas.", "main": "PersianSwear.js", "scripts": {