Skip to content

Commit

Permalink
Replace KoNLPy MeCab with python-mecab-ko
Browse files Browse the repository at this point in the history
  • Loading branch information
Huffon committed Aug 3, 2020
1 parent 3e7f0d7 commit 09f80aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ That's one of the reasons your contributions are more than welcome.
## Requirements
* python >= 3.6
* jamo
* Mecab (Consult http://konlpy.org/en/latest/install/ for installation)
* [python-mecab-ko](https://github.com/jonghwanhyeon/python-mecab-ko)
* konlpy
* nltk

Expand Down
15 changes: 6 additions & 9 deletions g2pk/g2pk.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import os, re

import nltk
import mecab
from jamo import h2j
from konlpy.tag import Mecab
from nltk.corpus import cmudict

# For further info. about cmu dict, consult http://www.speech.cs.cmu.edu/cgi-bin/cmudict.
Expand All @@ -24,24 +24,21 @@


class G2p(object):
def __init__(self, dict_path=''):
self.mecab = self.get_mecab(dict_path)
def __init__(self):
self.mecab = self.get_mecab()
self.table = parse_table()

self.cmu = cmudict.dict() # for English

self.rule2text = get_rule_id2text() # for comments of main rules
self.idioms_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "idioms.txt")

def get_mecab(self, dict_path):
def get_mecab(self):
try:
if dict_path:
return Mecab(dict_path) # for annotation
else:
return Mecab()
return mecab.MeCab()
except Exception as e:
raise Exception(
'If you want to install mecab, The command is.. bash <(curl -s https://raw.githubusercontent.com/konlpy/konlpy/master/scripts/mecab.sh)'
'If you want to install mecab, The command is... pip install python-mecab-ko'
)

def idioms(self, string, descriptive=False, verbose=False):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'jamo',
'nltk',
'konlpy',
'mecab'
'python-mecab-ko',
]

setuptools.setup(
Expand Down

0 comments on commit 09f80aa

Please sign in to comment.