Skip to content

Instantly share code, notes, and snippets.

@wannaphong
Last active February 4, 2017 03:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wannaphong/c8a966b59df639d871201fbd2efae95e to your computer and use it in GitHub Desktop.
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
# -*- 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