Skip to content

Commit

Permalink
Add pythainlp.g2p.ipa
Browse files Browse the repository at this point in the history
  • Loading branch information
wannaphong committed Oct 29, 2018
1 parent c148699 commit 606528e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pythainlp/corpus/wordnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
API ตัวใหม่ เริ่มใช้ตั้งแต่ PyThaiNLP 1.4 เป็นต้นไป
"""
import nltk
from nltk.corpus import wordnet

try:
nltk.data.find("corpora/omw")
Expand All @@ -12,6 +11,7 @@
nltk.download("wordnet")
nltk.download("omw")

from nltk.corpus import wordnet

def synsets(word, pos=None, lang="tha"):
return wordnet.synsets(lemma=word, pos=pos, lang=lang)
Expand Down
21 changes: 21 additions & 0 deletions pythainlp/g2p/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
try:
import epitran
except ImportError:
from pythainlp.tools import install_package

install_package("epitran")
try:
import epitran
except ImportError:
raise ImportError("ImportError: Try 'pip install epitran'")
epi = epitran.Epitran('tha-Thai')
class ipa:
def __init__(self,text=""):
self.text=text
def str(self):
return epi.transliterate(self.text)
def list(self):
return epi.trans_list(self.text)
def xsampa_list(self):
return epi.xsampa_list(self.text)
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from pythainlp.tokenize import etcc, isthai, syllable_tokenize, tcc, word_tokenize
from pythainlp.util import listtext_num2num, normalize
from pythainlp.Text import Text
from pythainlp.g2p import ipa


class TestUM(unittest.TestCase):
Expand Down Expand Up @@ -264,6 +265,12 @@ def test_ner(self):
def test_Text(self):
self.assertIsNotNone(Text("ทดสอบภาษาไทย"))

def test_ipa(self):
t=ipa("คน")
self.assertEqual(t.str(),'kʰon')
self.assertIsNotNone(t.list())
self.assertIsNotNone(t.xsampa_list())


if __name__ == "__main__":
unittest.main()

0 comments on commit 606528e

Please sign in to comment.