I thought it was harder than I thought to introduce MeCab to Windows 7 64bit, so I will post it as a memorandum.
MeCab is a morphological analysis tool. It basically does the following: ――It divides Japanese sentences into morphemes (the smallest blocks that make sense) ――It analyzes the part of speech of morphemes
1st line: Entered text, 3rd line and below: Result
The information I referred to is below (Thank you!): -[Create an environment of 64bit Windows + python 2.7 + MeCab 0.996](http://qiita.com/h_kabocha/items/5bee9e9b852aed11411b#%E3%81%AF%E3%81%98%E3%82%81%E3 % 81% AB) -Windows 64bit, mecab-python
You can download mecab-0.996.exe, mecab-0.996.tar.gz, mecab-python-0.996.tar.gz from here.
Execute mecab-0.996.exe and write environment variables.
C: \ Mecab \ bin
to the environment variable PATHC: \ Mecab \ etc \ mecabrc
C:
(state of C: \ Mecab \
)--At this time, create bin and sdk folders under Mecab folder -* Please check the environment variables as they may differ from one to another.
(Added on 2016/8/18) When you execute mecab-0.996.exe, a MeCab folder will be created under `C: \ Program Files (x86) \`
.
If you put that folder in ``` C: ` ``, you don't need to do number 4. I noticed while writing the article ... orz </ font>
Here, when I was looking at the information I was referring to, there was a mistake in specifying the file, and it took time to match it to my PC. (I didn't have much knowledge, so I uninstalled it twice and did it the third time lol) Expand
Makefile.msvc.in
LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X86 ADVAPI32.LIB
LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X64 ADVAPI32.LIB
Makefile.msvc.in
(Old)-DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=@DIC_VERSION@ \
(new)-DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=102 \
</ li>
Makefile.msvc.in
(Old)-DVERSION="\"@VERSION@\"" -DPACKAGE="\"mecab\"" \
(new)-DVERSION="\"0.996\"" -DPACKAGE="\"mecab\"" \
</ li>
Makefile.msvc.in
(Old)-DMECAB_DEFAULT_RC="\"c:\\Program Files\\mecab\\etc\\mecabrc\""
(new)-DMECAB_DEFAULT_RC="\"c:\\mecab\\etc\\mecabrc\""
</ li>
feature_index.cpp
(Old) case't': os_ << (size_t)path->rnode->char_type; break;
(New) case't': os_ << (unsigned int)path->rnode->char_type; break;
</ li>
writer.cpp
(Old) case'L': *os << (size_t)lattice->size(); break;
(New) case'L': *os << (unsigned int)lattice->size(); break;
</ li>
mecab.h
(Old)#ifndef SIWG
(new)#ifndef SWIG
</ li>
mecab.h
(new)#include <iterator>
</ ul>
> call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
> nmake -f Makefile.msvc.in
Please specify the directory that contains
</ ul>
C: \ Mecab \ bin
.
</ ul>
C: \ Mecab \ sdk
.
Rewrite Python for Windows, which only works on Unix. Extract
setup.py
#!/usr/bin/env python
from distutils.core import setup,Extension,os
setup(name = "mecab-python",
version = "0.996",
py_modules=["MeCab"],
ext_modules = [
Extension("_MeCab",
["MeCab_wrap.cxx",],
include_dirs=[r"C:\Mecab\sdk"],
library_dirs=[r"C:\Mecab\sdk"],
libraries=["libmecab"])
])
For the
</ li> </ ul>
> python setup.py build
</ li>
> python setup.py install
C:\Mecab\C below:\Program Files (x86)\Copy the etc and dic folders in MeCab and put them in.
That's all!
# Try out
I immediately tried it with Python.
I was able to enter the US military base at an event in Yokosuka recently, so this is the text.
#### **`text.txt`**
```txt
It was fun to visit the US military base in Yokosuka!
Python on the command prompt.
>python
Python 2.7.11
> import MeCab
> import sys
> m = MeCab.Tagger('mecabrc')
> f = open('text.txt','r')
> text = f.read().decode('utf-8')
> f.close()
> f = open('result.txt','w')
> f.write(m.parse(text.encode('utf-8')))
> f.close()
The result looks like this
Recommended Posts