{ "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 }