# Kuromoji\_stemmer と kuromoji\_readingform の同時使用について

**URL:** <https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316>\
**Category:** 日本語による質問・議論はこちら\
**Created:** [May 11, 2017, 1:51am UTC](https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316 "2017-05-11T01:51:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tatsuyaoiw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tatsuyaoiw/32/18113_2.png) [@tatsuyaoiw](https://discuss.elastic.co/u/tatsuyaoiw)\
**Post date:** [May 11, 2017, 1:51am UTC](https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316/1 "2017-05-11T01:51:15Z")

</div>

Elasticsearch Version: 5.3.1

`kuromoji_stemmer` token filterと`kuromoji_readingform` token filterを使って、最後の長音の除去とカタカナ読みへの変換を同時に設定しようとしたのですが、`kuromoji_stemmer`の後に`kuromoji_readingform`を設定すると、`kuromoji_stemmer`で除去されたはずの長音が`kuromoji_readingform`で再び追加されてしまいます。

設定例:

```auto
PUT http://localhost:9200/my_index
{
	"settings": {
		"analysis": {
			"filter": {
				"katakana_readingform": {
					"type": "kuromoji_readingform",
					"use_romaji": false
				}
			},
			"analyzer": {
				"stemmer": {
					"type": "custom",
					"tokenizer": "kuromoji_tokenizer",
					"filter": [
						"kuromoji_stemmer"
					]
				},
				"reading": {
					"type": "custom",
					"tokenizer": "kuromoji_tokenizer",
					"filter": [
						"katakana_readingform"
					]
				},
				"stemmer_reading": {
					"type": "custom",
					"tokenizer": "kuromoji_tokenizer",
					"filter": [
						"kuromoji_stemmer",
						"katakana_readingform"
					]
				},
				"reading_stemmer": {
					"type": "custom",
					"tokenizer": "kuromoji_tokenizer",
					"filter": [
						"katakana_readingform",
						"kuromoji_stemmer"
					]
				}
			}
		}
	}
}

```

クエリ例:

```auto
POST http://localhost:9200/my_index/_analyze
{
	"analyzer": "stemmer_reading",
	"text": "パーカー"
}

```

クエリ結果:

```auto
{
  "tokens": [
    {
      "token": "パーカー",
      "start_offset": 0,
      "end_offset": 4,
      "type": "word",
      "position": 0
    }
  ]
}

```

クエリ例（explain=true）:

```auto
POST http://localhost:9200/my_index/_analyze
{
	"analyzer": "stemmer_reading",
	"text": "パーカー",
        "explain": true
}

```

クエリ結果（explain=true）:

```auto
{
  "detail": {
    "custom_analyzer": true,
    "charfilters": [],
    "tokenizer": {
      "name": "kuromoji_tokenizer",
      "tokens": [
        {
          "token": "パーカー",
          "start_offset": 0,
          "end_offset": 4,
          "type": "word",
          "position": 0,
          "baseForm": null,
          "bytes": "[e3 83 91 e3 83 bc e3 82 ab e3 83 bc]",
          "inflectionForm": null,
          "inflectionForm (en)": null,
          "inflectionType": null,
          "inflectionType (en)": null,
          "partOfSpeech": "名詞-一般",
          "partOfSpeech (en)": "noun-common",
          "positionLength": 1,
          "pronunciation": "パーカー",
          "pronunciation (en)": "paka",
          "reading": "パーカー",
          "reading (en)": "paka"
        }
      ]
    },
    "tokenfilters": [
      {
        "name": "kuromoji_stemmer",
        "tokens": [
          {
            "token": "パーカ",
            "start_offset": 0,
            "end_offset": 4,
            "type": "word",
            "position": 0,
            "baseForm": null,
            "bytes": "[e3 83 91 e3 83 bc e3 82 ab]",
            "inflectionForm": null,
            "inflectionForm (en)": null,
            "inflectionType": null,
            "inflectionType (en)": null,
            "keyword": false,
            "partOfSpeech": "名詞-一般",
            "partOfSpeech (en)": "noun-common",
            "positionLength": 1,
            "pronunciation": "パーカー",
            "pronunciation (en)": "paka",
            "reading": "パーカー",
            "reading (en)": "paka"
          }
        ]
      },
      {
        "name": "katakana_readingform",
        "tokens": [
          {
            "token": "パーカー",
            "start_offset": 0,
            "end_offset": 4,
            "type": "word",
            "position": 0,
            "baseForm": null,
            "bytes": "[e3 83 91 e3 83 bc e3 82 ab e3 83 bc]",
            "inflectionForm": null,
            "inflectionForm (en)": null,
            "inflectionType": null,
            "inflectionType (en)": null,
            "keyword": false,
            "partOfSpeech": "名詞-一般",
            "partOfSpeech (en)": "noun-common",
            "positionLength": 1,
            "pronunciation": "パーカー",
            "pronunciation (en)": "paka",
            "reading": "パーカー",
            "reading (en)": "paka"
          }
        ]
      }
    ]
  }
}

```

この問題は、`kuromoji_stemmer`と`kuromoji_readingform`の順番を逆にすることでひとまず回避できそうですが、もし原因がわかれば教えていただきたいです。

```auto
POST http://localhost:9200/my_index/_analyze
{
	"analyzer": "reading_stemmer",
	"text": "パーカー"
}

```

```auto
{
  "tokens": [
    {
      "token": "パーカ",
      "start_offset": 0,
      "end_offset": 4,
      "type": "word",
      "position": 0
    }
  ]
}

```

よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [May 11, 2017, 2:08am UTC](https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316/2 "2017-05-11T02:08:15Z")

</div>

順番の問題です。  
filterは指定した順番に適用されます。  
kuromoji\_stemmerはtokenに対してのみ処理を行うためです。  
kuromoji\_readingformはtokenに対してreadingにある文字列を設定し直すものになります。  
ですので、stemmerを行なった後にreadingで上書きするので、長音を消す前に戻るということです。

---

<div class="post-metadata">

**Author:** ![tatsuyaoiw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tatsuyaoiw/32/18113_2.png) [@tatsuyaoiw](https://discuss.elastic.co/u/tatsuyaoiw)\
**Post date:** [May 11, 2017, 2:18am UTC](https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316/3 "2017-05-11T02:18:29Z")

</div>

なるほど。理解しました。ありがとうございます！

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 8, 2017, 2:20am UTC](https://discuss.elastic.co/t/kuromoji-stemmer-kuromoji-readingform/85316/4 "2017-06-08T02:20:24Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
