|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "from pythainlp.transliterate import pronunciate\n", |
| 10 | + "from pythainlp import thai_consonants" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "code", |
| 15 | + "execution_count": 2, |
| 16 | + "metadata": {}, |
| 17 | + "outputs": [ |
| 18 | + { |
| 19 | + "data": { |
| 20 | + "text/plain": [ |
| 21 | + "'พุด-ทะ'" |
| 22 | + ] |
| 23 | + }, |
| 24 | + "execution_count": 2, |
| 25 | + "metadata": {}, |
| 26 | + "output_type": "execute_result" |
| 27 | + } |
| 28 | + ], |
| 29 | + "source": [ |
| 30 | + "pronunciate(\"พุทธ\")" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": 3, |
| 36 | + "metadata": {}, |
| 37 | + "outputs": [ |
| 38 | + { |
| 39 | + "data": { |
| 40 | + "text/plain": [ |
| 41 | + "'บู-ชา'" |
| 42 | + ] |
| 43 | + }, |
| 44 | + "execution_count": 3, |
| 45 | + "metadata": {}, |
| 46 | + "output_type": "execute_result" |
| 47 | + } |
| 48 | + ], |
| 49 | + "source": [ |
| 50 | + "pronunciate(\"บูชา\")" |
| 51 | + ] |
| 52 | + }, |
| 53 | + { |
| 54 | + "cell_type": "code", |
| 55 | + "execution_count": 4, |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [ |
| 58 | + { |
| 59 | + "data": { |
| 60 | + "text/plain": [ |
| 61 | + "'อะ-นุก'" |
| 62 | + ] |
| 63 | + }, |
| 64 | + "execution_count": 4, |
| 65 | + "metadata": {}, |
| 66 | + "output_type": "execute_result" |
| 67 | + } |
| 68 | + ], |
| 69 | + "source": [ |
| 70 | + "pronunciate(\"อนุค\")" |
| 71 | + ] |
| 72 | + }, |
| 73 | + { |
| 74 | + "cell_type": "code", |
| 75 | + "execution_count": 5, |
| 76 | + "metadata": {}, |
| 77 | + "outputs": [], |
| 78 | + "source": [ |
| 79 | + "def nighit(w1,w2): # read: https://www.trueplookpanya.com/learning/detail/1180\n", |
| 80 | + " if not str(w1).endswith('ํ') and len(w1)!=2:\n", |
| 81 | + " raise NotImplementedError(f\"The function doesn't support {w1}.\")\n", |
| 82 | + " list_w1 = list(w1)\n", |
| 83 | + " list_w2 = list(w2)\n", |
| 84 | + " newword = list()\n", |
| 85 | + " newword.append(list_w1[0])\n", |
| 86 | + " newword.append(\"ั\")\n", |
| 87 | + " consonant_start = [i for i in list_w2 if i in set(thai_consonants)][0]\n", |
| 88 | + " if consonant_start in [\"ก\",\"ช\",\"ค\",\"ข\",\"ง\"]:\n", |
| 89 | + " newword.append(\"ง\")\n", |
| 90 | + " elif consonant_start in [\"จ\",\"ฉ\",\"ช\",\"ฌ\"]:\n", |
| 91 | + " newword.append(\"ญ\")\n", |
| 92 | + " elif consonant_start in [\"ฎ\",\"ฐ\",\"ฑ\",\"ณ\"]:\n", |
| 93 | + " newword.append(\"ณ\")\n", |
| 94 | + " elif consonant_start in [\"ด\",\"ถ\",\"ท\",\"ธ\",\"น\"]:\n", |
| 95 | + " newword.append(\"น\")\n", |
| 96 | + " elif consonant_start in [\"ป\",\"ผ\",\"พ\",\"ภ\"]:\n", |
| 97 | + " newword.append(\"ม\")\n", |
| 98 | + " elif consonant_start in [\"ย\",\"ร\",\"ล\",\"ฬ\",\"ว\",\"ศ\",\"ษ\",\"ส\",\"ห\"]:\n", |
| 99 | + " newword.append(\"ง\")\n", |
| 100 | + " else:\n", |
| 101 | + " raise NotImplementedError(f\"The function doesn't support {w1} and {w2}.\")\n", |
| 102 | + " newword.extend(list_w2)\n", |
| 103 | + " return ''.join(newword)" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "code", |
| 108 | + "execution_count": 6, |
| 109 | + "metadata": {}, |
| 110 | + "outputs": [], |
| 111 | + "source": [ |
| 112 | + "assert nighit(\"สํ\",\"คีต\")==\"สังคีต\"\n", |
| 113 | + "assert nighit(\"สํ\",\"จร\")==\"สัญจร\"\n", |
| 114 | + "assert nighit(\"สํ\",\"ฐาน\")==\"สัณฐาน\"\n", |
| 115 | + "assert nighit(\"สํ\",\"นิษฐาน\")==\"สันนิษฐาน\"\n", |
| 116 | + "assert nighit(\"สํ\",\"ปทา\")==\"สัมปทา\"\n", |
| 117 | + "assert nighit(\"สํ\",\"โยค\")==\"สังโยค\"" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": null, |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [], |
| 125 | + "source": [] |
| 126 | + } |
| 127 | + ], |
| 128 | + "metadata": { |
| 129 | + "kernelspec": { |
| 130 | + "display_name": "Python 3.8.13 ('base')", |
| 131 | + "language": "python", |
| 132 | + "name": "python3" |
| 133 | + }, |
| 134 | + "language_info": { |
| 135 | + "codemirror_mode": { |
| 136 | + "name": "ipython", |
| 137 | + "version": 3 |
| 138 | + }, |
| 139 | + "file_extension": ".py", |
| 140 | + "mimetype": "text/x-python", |
| 141 | + "name": "python", |
| 142 | + "nbconvert_exporter": "python", |
| 143 | + "pygments_lexer": "ipython3", |
| 144 | + "version": "3.8.13" |
| 145 | + }, |
| 146 | + "orig_nbformat": 4, |
| 147 | + "vscode": { |
| 148 | + "interpreter": { |
| 149 | + "hash": "a1d6ff38954a1cdba4cf61ffa51e42f4658fc35985cd256cd89123cae8466a39" |
| 150 | + } |
| 151 | + } |
| 152 | + }, |
| 153 | + "nbformat": 4, |
| 154 | + "nbformat_minor": 2 |
| 155 | +} |
0 commit comments