Skip to content

Commit 504f669

Browse files
committed
add Meta Sound
1 parent 94eaead commit 504f669

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Natural language processing หรือ การประมวลภาษา
3030
- รองรับ Thai Character Clusters (TCC) และ ETCC
3131
- Thai WordNet ตัวใหม่
3232
- เพิ่มหลักเกณฑ์การถอดอักษรไทยเป็นอักษรโรมัน ฉบับราชบัณฑิตยสถาน
33+
- เพิ่ม Meta Sound ภาษาไทย
3334

3435
### ความสามารถ
3536
- ตัดคำภาษาไทย

References.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# References
2+
3+
Snae & Brückner. (2009). Novel Phonetic Name Matching Algorithm with a Statistical Ontology for Analysing Names Given in Accordance with Thai Astrology. Retrieved from https://pdfs.semanticscholar.org/3983/963e87ddc6dfdbb291099aa3927a0e3e4ea6.pdf

docs/pythainlp-1-4-thai.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ grammar : คุณ Wittawat Jitkrittum (https://github.com/wittawatj/jtcc/blob/
268268
'/คืน/ความสุข'
269269
```
270270

271+
### Meta Sound ภาษาไทย
272+
273+
```
274+
Snae & Brückner. (2009). Novel Phonetic Name Matching Algorithm with a Statistical Ontology for Analysing Names Given in Accordance with Thai Astrology. Retrieved from https://pdfs.semanticscholar.org/3983/963e87ddc6dfdbb291099aa3927a0e3e4ea6.pdf
275+
```
276+
277+
**การใช้งาน**
278+
279+
```python
280+
>>> from pythainlp.MetaSound import *
281+
>>> MetaSound('คน')
282+
'15'
283+
```
284+
271285
### Sentiment analysis ภาษาไทย
272286

273287
ใช้ข้อมูลจาก https://github.com/wannaphongcom/lexicon-thai/tree/master/ข้อความ/

pythainlp/MetaSound.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'''
2+
MetaSound
3+
4+
References
5+
6+
Snae & Brückner. (2009). Novel Phonetic Name Matching Algorithm with a Statistical Ontology for Analysing Names Given in Accordance with Thai Astrology. Retrieved from https://pdfs.semanticscholar.org/3983/963e87ddc6dfdbb291099aa3927a0e3e4ea6.pdf
7+
'''
8+
import re
9+
def MetaSound(name):
10+
'''
11+
MetaSound(str)
12+
'''
13+
name1=list(name)
14+
count=len(name1)
15+
word=[]
16+
i=0
17+
while i<count:
18+
if (re.search(r'[ก-ฮ]',name1[i]),re.U):
19+
word.append(name1[i])
20+
i+=1
21+
i=0
22+
count=len(name1)
23+
while i<count:
24+
if (re.search('์',name1[i],re.U)):
25+
word[i-1]=''
26+
word[i]=''
27+
i+=1
28+
i=0
29+
while i<count:
30+
if (re.search('[กขฃคฆฅ]',word[i],re.U)):
31+
name1[i]='1'
32+
elif (re.search('[จฉชฌซฐทฒดฎตสศษ]',word[i],re.U)):
33+
name1[i]='2'
34+
elif (re.search('[ฟฝพผภบป]',word[i],re.U)):
35+
name1[i]='3'
36+
elif (re.search('[ง]',word[i],re.U)):
37+
name1[i]='4'
38+
elif (re.search('[ลฬรนณฦญ]',word[i],re.U)):
39+
name1[i]='5'
40+
elif (re.search('[ม]',word[i],re.U)):
41+
name1[i]='6'
42+
elif (re.search('[ย]',word[i],re.U)):
43+
name1[i]='7'
44+
elif (re.search('[ว]',word[i],re.U)):
45+
name1[i]='8'
46+
else:
47+
name1[i]='0'
48+
i+=1
49+
return ''.join(name1)
50+
if __name__ == '__main__':
51+
print(MetaSound('รัก'))
52+
print(MetaSound('ลัก'))

pythainlp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
from pythainlp.collation import *
1818
from pythainlp.test import *
1919
from pythainlp.Text import *
20+
from pythainlp.MetaSound import *

0 commit comments

Comments
 (0)