| 140 | |
| 141 | |
| 142 | class Model(_MeCab.Model): |
| 143 | def __init__(self, rawargs="", error_check=False): |
| 144 | # Note this is the same as the code for the Tagger. |
| 145 | unidicdir = try_import_unidic() |
| 146 | args = rawargs |
| 147 | if unidicdir: |
| 148 | mecabrc = os.path.join(unidicdir, 'mecabrc') |
| 149 | args = '-r "{}" -d "{}" '.format(mecabrc, unidicdir) + args |
| 150 | args = ['', '-C'] + shlex.split(args) |
| 151 | args = [x.encode('utf-8') for x in args] |
| 152 | |
| 153 | try: |
| 154 | super(Model, self).__init__(args) |
| 155 | except RuntimeError as ee: |
| 156 | if not error_check: |
| 157 | raise RuntimeError(error_info(rawargs)) from ee |
| 158 | else: |
| 159 | raise |
| 160 | |
| 161 | |
| 162 | __all__.append("Model") |