Skip to content

Instantly share code, notes, and snippets.

View wannaphong's full-sized avatar

Wannaphong Phatthiyaphaibun wannaphong

View GitHub Profile
@wannaphong
wannaphong / LK82.py
Last active June 29, 2017 04:29 — forked from korakot/LK82.py
Thai Soundex LK82, Udom83
# ตาม guru.sanook.com/1520
import re
t1 = str.maketrans("กขฃคฅฆงจฉชฌซศษสญยฎดฏตณนฐฑฒถทธบปผพภฝฟมรลฬฤฦวหฮอ",
"กกกกกกงจชชชซซซซยยดดตตนนททททททบปพพพฟฟมรรรรรวหหอ")
t2 = str.maketrans(
"กขฃคฅฆงจฉชซฌฎฏฐฑฒดตถทธศษสญณนรลฬฤฦบปพฟภผฝมำยวไใหฮาๅึืเแโุูอ",
"1111112333333333333333333444444445555555667777889AAABCDEEF")
def LK82(s):
res = []
def listcut(text):
'''
ใช้หาคำที่สามารถตัดได้ทั้งหมดโดยจะเป็น list โดยมี | เป็นตัวแบ่งใน list
'''
listdata = list(tcut(text))
listdata1=['']*len(listdata)
i=0
maxnum=0
numall=1
listnum=[0]*len(listdata)
@wannaphong
wannaphong / web.py
Last active July 24, 2017 05:24
ระบบบันทึกผู้เยี่ยมชมอย่างง่าย เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์ https://python3.wannaphong.com/2017/07/สร้างเว็บด้วย-bottle-ตอนที่-3.html
# -*- coding: utf-8 -*-
from bottle import route, run, template,get, post, request
import csv
import codecs
@route('/')
def home():
return '''
<!DOCTYPE html>
@wannaphong
wannaphong / RegexpParser.py
Created August 8, 2017 12:49
ทดลองทำ Regexp Parser ภาษาไทย
from pythainlp.tokenize import word_tokenize # ใช้ในการตัดคำ
from pythainlp.tag import pos_tag
from nltk import RegexpParser
chunker = RegexpParser("""
Bank:
{<NCMN>+}
""")
text='ธนาคารบัวเทพร่วมมือกันแก้ไขปัญหาทางการเงินของไทย'
a=word_tokenize(text,engine='mm')
b=pos_tag(a,engine='artagger')
# -*- coding: utf-8 -*-
def arrUnicode(myArr):
uniStr = [unicode(i, encoding='UTF-8') if isinstance(i, basestring) else i for i in myArr]
s = repr(uniStr).decode('unicode_escape').encode('utf-8')
if s.startswith("[u'"):
s2 = s.replace("u'", "'")
elif s.startswith('[u"'):
s2 = s.replace('u"', '"')
else:
>>> import nlpnet
>>> path="ที่ตั้งโฟลเดอร์ที่เก็บไฟล์train"
>>> nlpnet.set_data_dir(path)
>>> tagger = nlpnet.POSTagger()
# โหลดฟังก์ชัน arrUnicode แสดงผลภาษาไทยใน Python 2.7 ได้จาก https://gist.github.com/wannaphongcom/266e340b80b0b21e11f4f768965fe8b0
>>> print arrUnicode(tagger.tag('คุณ เป็น ครู ภาษาไทย ใช่ไหม'))
[[(u'คุณ', u'JSBR'), (u'เป็น', u'VSTA'), (u'ครู', u'NCMN'), (u'ภาษาไทย', u'VATT'), (u'ใช่ไหม', u'NCMN')]]
>>> print arrUnicode(tagger.tag('คุณ เป็น คุณครู ภาษาไทย ใช่ไหม'))
[[(u'คุณ', u'JSBR'), (u'เป็น', u'VSTA'), (u'คุณครู', u'NCMN'), (u'ภาษาไทย', u'NCMN'), (u'ใช่ไหม', u'NCMN')]]
>>> print arrUnicode(tagger.tag('สวัสดี ครับ ทุกคน สบายดี กัน ไหม ครับ ตอนนี้ ผม ง่วง นอน มาก เลย แล ค ล่ะ'))
# -*- coding: utf-8 -*-
"""
โค้ดทดสอบก่อนถูกนำไปรวมกับ PyThaiNLP
ใช้ Apache License 2.0
เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์
"""
import re
"""
หลักการทำงาน
-----------
# -*- coding: utf-8 -*-
"""
โค้ดทดสอบก่อนถูกนำไปรวมกับ PyThaiNLP
ใช้ Apache License 2.0
เขียนโดย นาย วรรณพงษ์ ภัททิยไพบูลย์
"""
import re
"""
หลักการทำงาน
-----------
@wannaphong
wannaphong / ngrams.py
Last active September 8, 2017 07:59 — forked from benhoyt/ngrams.py
Print most frequent N-grams in given file
# -*- coding: utf-8 -*-
"""Print most frequent N-grams in given file.
Usage: python ngrams.py filename
Problem description: Build a tool which receives a corpus of text,
analyses it and reports the top 10 most frequent bigrams, trigrams,
four-grams (i.e. most frequently occurring two, three and four word
consecutive combinations).
@wannaphong
wannaphong / test.py
Created September 20, 2017 16:34
ทดลอง spacy กับภาษาไทย https://github.com/wannaphongcom/spaCy
>>> import spacy
>>> th_nlp = spacy.load('th')
>>> text="คุณรักผมไหม"
>>> a= th_nlp(text)
>>> a
คุณรักผมไหม
>>> list(a)
[คุณ, รัก, ผม, ไหม]