{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:15:36.279765Z",
     "start_time": "2019-10-12T01:15:36.262227Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['buckwalter', 'iso233-2', 'asmo449']"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from cltk.phonology.arabic.romanization import available_transliterate_systems\n",
    "available_transliterate_systems()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:16:42.250735Z",
     "start_time": "2019-10-12T01:16:42.204725Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'bisomi Allhi Alra~Hom`ni Alra~Hiyomi'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from cltk.phonology.arabic.romanization import transliterate\n",
    "mode = 'buckwalter'\n",
    "ar_string = 'بِسْمِ اللهِ الرَّحْمٰنِ الرَّحِيْمِ' # translate in English: In the name of Allah, the Most Merciful, the Most Compassionate\n",
    "ignore = '' # this is for ignore an arabic char from transliterate operation\n",
    "reverse = True # true means transliteration from arabic native script to roman script such as Buckwalter\n",
    "transliterate(mode, ar_string, ignore, reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:20:01.341830Z",
     "start_time": "2019-10-12T01:20:01.332686Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\u202b>nA w>nt\\u202c'"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "transliterate(mode, '‫أنا وأنت‬', ignore, reverse)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:21:15.876522Z",
     "start_time": "2019-10-12T01:21:14.811348Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['\\u202b', 'أنا', 'وأنت', '\\u202c']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from cltk.tokenize.word import WordTokenizer\n",
    "word_tokenizer = WordTokenizer('arabic')\n",
    "word_tokenizer.tokenize('‫أنا وأنت‬')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:31:02.882099Z",
     "start_time": "2019-10-12T01:31:02.877511Z"
    }
   },
   "outputs": [],
   "source": [
    "# import pyarabic.trans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:38:47.459524Z",
     "start_time": "2019-10-12T01:38:47.436358Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "An AlqrAc yqrcwn AlqrAn qrAco jmylo\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "def translitArabic(text):\n",
    "    buckwalterMod = {\n",
    "        'ء': 'c', 'ا': 'A', 'إ': 'A',\n",
    "        'أ': 'A', 'آ': 'A', 'ب': 'b',\n",
    "        'ة': 'o', 'ت': 't', 'ث': 'v',\n",
    "        'ج': 'j', 'ح': 'H', 'خ': 'x',\n",
    "        'د': 'd', 'ذ': 'V', 'ر': 'r',\n",
    "        'ز': 'z', 'س': 's', 'ش': 'E',\n",
    "        'ص': 'S', 'ض': 'D', 'ط': 'T',\n",
    "        'ظ': 'Z', 'ع': 'C', 'غ': 'g',\n",
    "        'ف': 'f', 'ق': 'q', 'ك': 'k',\n",
    "        'ل': 'l', 'م': 'm', 'ن': 'n',\n",
    "        'ه': 'h', 'ؤ': 'c', 'و': 'w',\n",
    "        'ى': 'y', 'ئ': 'c', 'ي': 'y',\n",
    "        }\n",
    "    for k, v in buckwalterMod.items():\n",
    "        text = re.sub(k, v, text)\n",
    "    return(text)\n",
    "testLine = \"إن القراء يقرؤون القرآن قراءة جميلة\"\n",
    "print(translitArabic(testLine))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-10-12T01:39:11.229594Z",
     "start_time": "2019-10-12T01:39:11.201755Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\u202bAnA wAnt\\u202c'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "translitArabic('‫أنا وأنت‬')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
