# -*- coding: utf-8 -*-
from __future__ import absolute_import,division,unicode_literals,print_function
'''
ขอขอบคุณ คุณ Korakot Chaovavanich‎ สำหรับโค้ด word_frequency จาก https://www.facebook.com/photo.php?fbid=363640477387469&set=gm.434330506948445&type=3&permPage=1
'''
import re,requests
def word_frequency(word,domain='all'):
    listdomain={'all':'','imaginative':'1','natural-pure-science':'2','applied-science':'3','social-science':'4','world-affairs-history':'5','commerce-finance':'6','arts':'7','belief-thought':'8','leisure':'9','others':'0'}
    url = "http://www.arts.chula.ac.th/~ling/TNCII/corp.php"
    data = {'genre[]':'','domain[]':listdomain[domain],'sortby':'perc','p':word}
    r = requests.post(url,data=data)
    pat = re.compile('TOTAL</font>(?s).*?#ffffff">(.*?)</font>')
    n = pat.search(r.text).group(1)
    return int('0'+n.strip())
@@ -276,17 +276,24 @@
 mport re
-,
+%0Aimport 
 requests
@@ -293,16 +293,40 @@
 equests%0A
+import os%0Aimport codecs%0A
 def word
@@ -860,16 +860,16 @@
 roup(1)%0A
-
     retu
@@ -889,8 +889,871 @@
 strip())
+%0Adef get_word_frequency_all():%0A%09'''%0A%09get_word_frequency_all()%0A%09%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99%E0%B8%84%E0%B8%B3%E0%B8%AA%E0%B8%B1%E0%B9%88%E0%B8%87%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A%E0%B8%94%E0%B8%B6%E0%B8%87%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5 word frequency %E0%B8%82%E0%B8%AD%E0%B8%87 TNC %E0%B8%A1%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%87%E0%B8%B2%E0%B8%99%0A%09%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%81%E0%B8%AA%E0%B8%94%E0%B8%87%E0%B8%9C%E0%B8%A5%E0%B9%80%E0%B8%9B%E0%B9%87%E0%B8%99 %5B(word,frequency),...%5D%0A%09%E0%B8%82%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%B9%E0%B8%A5%E0%B8%88%E0%B8%B2%E0%B8%81 https://raw.githubusercontent.com/korakot/thainlp/master/tnc_freq.txt%0A%09'''%0A%09url=%22https://raw.githubusercontent.com/korakot/thainlp/master/tnc_freq.txt%22%0A%09path = os.path.join(os.path.expanduser(%22~%22), 'pythainlp-data')#os.path.join(, 'pthainlp_trie.data')%0A%09if not os.path.exists(path):%0A%09%09os.makedirs(path)%0A%09path = os.path.join(path, 'tnc_freq.txt')%0A%09if not os.path.exists(path):%0A%09%09response = requests.get(url)%0A%09%09with open(path, 'wb') as f:%0A%09%09%09f.write(response.content)%0A%09%09f.close()%0A%09with codecs.open(path, 'r',encoding='utf8') as f:%0A%09%09lines = f.read().splitlines()%0A%09f.close()%0A%09listword=%5B%5D%0A%09for x in lines:%0A%09%09listindata=x.split(%22%09%22)%0A%09%09listword.append((listindata%5B0%5D,listindata%5B1%5D))%0A%09return listword

add #59