Last active
February 4, 2017 03:59
-
-
Save wannaphong/c8a966b59df639d871201fbd2efae95e to your computer and use it in GitHub Desktop.
เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์ ใช้ประกอบบทความ https://python3.wannaphong.com/2017/02/wordnet-ภาษาไทยกับ-python.html โดยใช้ฐานข้อมูล Thai WordNet โหลดได้ที่ https://sourceforge.net/projects/thwnsqlite/files/thwnsqlite-201405121006.tar.bz2/download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# อ่านบทความได้ที่ https://python3.wannaphong.com/2017/02/wordnet-ภาษาไทยกับ-python.html | |
from __future__ import print_function | |
import sqlite3 | |
from collections import namedtuple | |
conn = sqlite3.connect('tha-wn.db') | |
Word = namedtuple('Word', 'synsetid li') | |
Synset = namedtuple('Synset', 'synset li') | |
def getWords(wordid): | |
words = [] | |
cur = conn.execute("select * from word_synset where synsetid=?", (wordid,)) | |
row = cur.fetchone() | |
return Word(*cur.fetchone()) | |
def getSynset(synset): | |
cursor=conn.execute("select * from word_synset where li=?",(synset,)) | |
row=cursor.fetchone() | |
if row: | |
return Synset(*row) | |
else: | |
return None | |
print(getSynset("ผลักดันกลับ")) | |
print(getWords("02503365-v")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment