2021年5月22日土曜日

【85】番外編、AtoMへのsudachiインストール更新

以前、Kuromojiよりも語彙や分割能力に優れた形態素解析器sudachiをAtoM2.6に導入できた事例を報告しました。

http://irisawadojo.blogspot.com/search/label/Sudachi

これが全く無効となったことが判明しました。sudachiのバージョンが古くなったためか、git hub上でproject not foundとなって引退です。

https://github.com/WorksApplications/elasticsearch-sudachi/tree/v5.6.16-2.0.2

お疲れ様でした。

というわけで、現行最新ver. AtoM2.6.4のために使っているElasticsearchに、プラグインelasticsearch-sudachiをインストールするための手続きを新たに紹介します。以前より簡単になりました。参照したサイトはhttps://github.com/WorksApplications/elasticsearch-sudachi/blob/develop/docs/tutorial.mdhttps://js-challenge.dev/posts/elasticsearch-install-sudachi/です。

最初にElastic Search (ES)のバージョンを念のため確認。

VMなんかにAtoMをインストールした初期状態では、curlできないのでインストール。

$ sudo apt install curl

$ curl http://localhost:9200

そうしたら、

"version" : {

    "number" : "5.6.16",

    .........

と出ます(AtoM2.6.4)。

ここからSudachiをいれていきます。ESのプラグインであるanalysis-sudachiをインストールします。

めんどいのでrootユーザーになります。

$ sudo su

ES 5.6にあったバージョンのanalysis-sudachiをとってくる。

$ /usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/WorksApplications/elasticsearch-sudachi/releases/download/v2.1.0-es5.6/analysis-sudachi-5.6.16-2.1.0.zip

本当に入ったかを確認。

$ /usr/share/elasticsearch/bin/elasticsearch-plugin list

analysis-sudachi

と表示されていたらOK。

次に辞書を入れます。

/etc/elasticsearch/sudachi/ を作成し、そこにsystem_core.dicという名前で辞書を配置します。

$ mkdir /etc/elasticsearch/sudachi

$ cd /etc/elasticsearch/sudachi

最新の辞書のコア版を入れます。フルの辞書が欲しい人は、以下coreのところをfullに書き換えてください。

$ wget https://object-storage.tyo2.conoha.io/v1/nc_2520839e1f9641b08211a5c85243124a/sudachi/sudachi-dictionary-latest-core.zip

うまくいくはずがなぜか拒否されたので、次のページ(http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/)からダウンロード。

$ wget http://sudachi.s3-website-ap-northeast-1.amazonaws.com/sudachidict/sudachi-dictionary-20201223-core.zip

$ unzip sudachi-dictionary-20201223-core.zip

$ cp sudachi-dictionary-*/system_core.dic .

Elasticsearchを起動

$ sudo /etc/init.d/elasticsearch restart

次のコマンドでanalysis-sudachiが "plugins”に入っていればOK.

$ curl -X GET 'http://localhost:9200/_nodes/plugins?pretty'

.........

 "plugins" : [

        {

          "name" : "analysis-sudachi",

          "version" : "2.1.0",

          "description" : "The Japanese (Sudachi) Analysis plugin integrates Lucene Sudachi analysis module into elasticsearch.",

          "classname" : "com.worksap.nlp.elasticsearch.sudachi.plugin.AnalysisSudachiPlugin",

          "has_native_controller" : false

        }

      ],

.........

上記のように入っていることを確認。

最後にAtoMの設定ファイルを変更。

$ sudo nano /usr/share/nginx/atom/plugins/arElasticSearchPlugin/config/search.yml

もちろん、nanoじゃなくてviでもいい。

italian:

  tokenizer: standard

  filter: [lowercase, italian_stop, preserved_asciifolding]

の下に

japanese:

  tokenizer: sudachi_tokenizer

  filter: [sudachi_baseform, sudachi_normalizedform]

を挿入。インデントを他の行とずれないように注意。

今回入れたfilterは、sudachi_baseformが形容詞と動詞を終止形にして検索。sudachi_normalizedformが、異体字などを統制して検索してくれる。

filterについては色々あるので、以下を参照。

https://github.com/WorksApplications/elasticsearch-sudachi/blob/develop/docs/tutorial.mdのフィルター説明。

https://www.ai-shift.co.jp/techblog/168 はtoken filterのところ。

https://qiita.com/sorami/items/99604ef105f13d2d472b は様々なフィルターのところ。

$ sudo nano /usr/share/nginx/atom/plugins/arElasticSearchPlugin/lib/arElasticSearchMapping.class.php 

'it' => 'italian’, の下に
'ja' => 'japanese’, を記入。こちらもインデントを他の行とずれないように注意。

Nginxを再起動し、インデックスの再読み込み。

$ sudo systemctl restart nginx

$ sudo php /usr/share/nginx/atom/symfony search:populate

これにて終了。

最近の投稿

【108】Archives in the Digital Age: The use of AI and machine learning in the Swedish archival sectorを読む

 Gijs Aangenendt氏の修士論文、Archives in the Digital Age: The use of AI and machine learning in the Swedish archival sectorを半分読みました。 前半は、AIを扱ったアーカ...

人気の投稿