File size: 4,381 Bytes
e4b9a7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "70e6b5ba-063d-4e53-a312-2380b49bc3a9",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pythainlp.wsd import get_sense"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2ef43b65-5df9-42e3-a712-0e60ca64ea16",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Setting ds_accelerator to cuda (auto detect)\n",
      "[('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.09319090843200684), ('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.0974416732788086)]\n"
     ]
    }
   ],
   "source": [
    "print(get_sense(\"เขากำลังอบขนมคุกกี้\", \"คุกกี้\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6aafefdf-4658-4e35-b69f-7d2b54e34d33",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('ชื่อขนมชนิดหนึ่งจำพวกขนมเค้ก แต่ทำเป็นชิ้นเล็ก ๆ แบน ๆ แล้วอบให้กรอบ', 0.12473666667938232), ('โปรแกรมคอมพิวเตอร์ใช้ในทางอินเทอร์เน็ตสำหรับเก็บข้อมูลของผู้ใช้งาน', 0.1005704402923584)]\n"
     ]
    }
   ],
   "source": [
    "print(get_sense(\"เว็บนี้ต้องการคุกกี้ในการทำงาน\", \"คุกกี้\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b0ee35fc-f26e-4bce-b6fa-0e1efc863ae4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(get_sense(\"เว็บนี้ต้องการคุกกี้ในการทำงาน\", \"คน\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "32fa3fe9-0e1a-4176-b8f3-18d666eb3162",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pythainlp.corpus import get_corpus_path, thai_wsd_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0f88ff4c-06db-4cba-8086-4bb2160bead0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "w = thai_wsd_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "83642893-d9a6-4271-a1b7-5e57638a74d4",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['word', 'meaning'])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bb67c468-ce65-4581-adc6-832d70cfabab",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('เดิน', ['เคลื่อนไปด้วยกำลังต่าง ๆ', 'ยกเท้าก้าวไป'])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w[\"word\"][0], w[\"meaning\"][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27fbe522-019f-4157-a9a8-50ae62b50727",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}