Juman++ V2 を m1 macにインストール


Juman++ V2 を m1 macにインストール

Juman++ Version: 2.0.0-rc3を m1 mac にインストールする

基本的には、githubの手順に従ってインストールすれば良いが、そのままではコンパイルできないので、一部を変更する必要がある

具体的には

  • backward.hppのソースコードを一部m1に合わせて変更
  • catch.hppを最新のものに更新

を実施した

作業ディレクトリの作成

作業ディレクトリとしては適当なディレクトリを作成すれば良い、ここではホームディレクトリの下にwork/jumanppを作成する事とした

$ export JUMANPP="${HOME}/work/jumanpp"
$ mkdir ${JUMANPP}
$ cd ${JUMANPP}

ソースファイルのダウンロードして展開

$ curl -LO https://github.com/ku-nlp/jumanpp/releases/download/v2.0.0-rc3/jumanpp-2.0.0-rc3.tar.xz
$ tar -xf jumanpp-2.0.0-rc3.tar.xz
$ cd jumanpp-2.0.0-rc3

ビルドする

ビルド用ディレクトリの作成

$ mkdir build
$ cd build

ビルドのためにcmakeが必要なので、もしインストールされていなければcmakeをHomebrewを利用してインストール

もし、brewコマンドがインストールされていなければ、Homebrewをインストールしてから下記のコマンドを実行

$ brew update
$ brew install cmake

cmakeの実行

cmakeでインストール先は、ここでは${JUMANPP}="${HOME}/work/jumanpp"を指定する事にする

jumandic.config の保存先を${JUMANPP}にするためJPP_DEFAULT_CONFIG_DIRも指定する

$ cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${JUMANPP} \
-DJPP_DEFAULT_CONFIG_DIR=${JUMANPP}

Jumanppをコンパイル (ただし、失敗する)

$ make -j10
In file included from /Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/src/util/assert.cc:5:
/Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/libs/backward.hpp:2268:59: error: member reference type 'struct __darwin_mcontext64 *' is a pointer; did you mean to use '->'?
    error_addr = reinterpret_cast<void*>(uctx->uc_mcontext.pc);
                                         ~~~~~~~~~~~~~~~~~^
                                                          ->
/Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/libs/backward.hpp:2268:60: error: no member named 'pc' in '__darwin_mcontext64'
    error_addr = reinterpret_cast<void*>(uctx->uc_mcontext.pc);
                                         ~~~~~~~~~~~~~~~~~ ^
2 errors generated.
make[2]: *** [src/util/CMakeFiles/jpp_util.dir/assert.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[  9%] Linking CXX static library libpathie.a
[  9%] Built target pathie
make[1]: *** [src/util/CMakeFiles/jpp_util.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
In file included from /Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/src/testing/catch_main.cc:6:
/Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/libs/catch.hpp:4151:13: error: unrecognized instruction mnemonic, did you mean: bit, cnt, hint, ins, not?
            CATCH_BREAK_INTO_DEBUGGER();
            ^
/Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/libs/catch.hpp:1388:71: note: expanded from macro 'CATCH_BREAK_INTO_DEBUGGER'
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
                                                                      ^
/Users/percipere/work/jumanpp/jumanpp-2.0.0-rc3/libs/catch.hpp:1367:30: note: expanded from macro 'CATCH_TRAP'
#define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
                             ^
<inline asm>:1:2: note: instantiated into assembly here
        int $3
        ^
1 error generated.

m1に対応するためにソースコードを書き換え

${JUMANPP}/jumanpp-2.0.0-rc3/libs/backward.hppに次のパッチを適用

2267c2267
< #elif defined(__aarch64__) && !defined(__APPLE__)
---
> #elif defined(__aarch64__)
2273,2274d2272
< #elif defined(__APPLE__) && defined(__aarch64__)
<     error_addr = reinterpret_cast<void*>(uctx->uc_mcontext->__ss.__pc);

catchを最新版に置き換え

$ curl -LO https://github.com/catchorg/Catch2/releases/download/v2.13.8/catch.hpp
$ mv catch.hpp ../libs/

コンパイル(今度は成功)

$ make -j10
$ make install

確認

Jumanppのバージョンを確認して、Quick startの例を実行してみる

$ ${JUMANPP}/bin/jumanpp -v
Juman++ Version: 2.0.0-rc3 / Dictionary: 20190731-356e143 / LM: K:20190430-7d143fb L:20181122-b409be68 F:20171214-9d125cb

$ echo "魅力がたっぷりと詰まっている" | ${JUMANPP}/bin/jumanpp
魅力 みりょく 魅力 名詞 6 普通名詞 1 * 0 * 0 "代表表記:魅力/みりょく カテゴリ:抽象物"
が が が 助詞 9 格助詞 1 * 0 * 0 NIL
たっぷり たっぷり たっぷりだ 形容詞 3 * 0 ナノ形容詞 22 語幹 1 "代表表記:たっぷりだ/たっぷりだ"
と と と 助詞 9 格助詞 1 * 0 * 0 NIL
詰まって つまって 詰まる 動詞 2 * 0 子音動詞ラ行 10 タ系連用テ形 14 "代表表記:詰まる/つまる ドメイン:料理・食事 自他動詞:他:詰める/つめる"
いる いる いる 接尾辞 14 動詞性接尾辞 7 母音動詞 1 基本形 2 "代表表記:いる/いる"
EOS

今回はここまで