123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
- [[analysis-nori]]
- === Korean (nori) Analysis Plugin
- The Korean (nori) Analysis plugin integrates Lucene nori analysis
- module into elasticsearch. It uses the https://bitbucket.org/eunjeon/mecab-ko-dic[mecab-ko-dic dictionary]
- to perform morphological analysis of Korean texts.
- :plugin_name: analysis-nori
- include::install_remove.asciidoc[]
- [[analysis-nori-analyzer]]
- ==== `nori` analyzer
- The `nori` analyzer consists of the following tokenizer and token filters:
- * <<analysis-nori-tokenizer,`nori_tokenizer`>>
- * <<analysis-nori-speech,`nori_part_of_speech`>> token filter
- * <<analysis-nori-readingform,`nori_readingform`>> token filter
- * {ref}/analysis-lowercase-tokenfilter.html[`lowercase`] token filter
- It supports the `decompound_mode` and `user_dictionary` settings from
- <<analysis-nori-tokenizer,`nori_tokenizer`>> and the `stoptags` setting from
- <<analysis-nori-speech,`nori_part_of_speech`>>.
- [[analysis-nori-tokenizer]]
- ==== `nori_tokenizer`
- The `nori_tokenizer` accepts the following settings:
- `decompound_mode`::
- +
- --
- The decompound mode determines how the tokenizer handles compound tokens.
- It can be set to:
- `none`::
- No decomposition for compounds. Example output:
- 가거도항
- 가곡역
- `discard`::
- Decomposes compounds and discards the original form (*default*). Example output:
- 가곡역 => 가곡, 역
- `mixed`::
- Decomposes compounds and keeps the original form. Example output:
- 가곡역 => 가곡역, 가곡, 역
- --
- `user_dictionary`::
- +
- --
- The Nori tokenizer uses the https://bitbucket.org/eunjeon/mecab-ko-dic[mecab-ko-dic dictionary] by default.
- A `user_dictionary` with custom nouns (`NNG`) may be appended to the default dictionary.
- The dictionary should have the following format:
- [source,txt]
- -----------------------
- <token> [<token 1> ... <token n>]
- -----------------------
- The first token is mandatory and represents the custom noun that should be added in
- the dictionary. For compound nouns the custom segmentation can be provided
- after the first token (`[<token 1> ... <token n>]`). The segmentation of the
- custom compound nouns is controlled by the `decompound_mode` setting.
- As a demonstration of how the user dictionary can be used, save the following
- dictionary to `$ES_HOME/config/userdict_ko.txt`:
- [source,txt]
- -----------------------
- c++ <1>
- C샤프
- 세종
- 세종시 세종 시 <2>
- -----------------------
- <1> A simple noun
- <2> A compound noun (`세종시`) followed by its decomposition: `세종` and `시`.
- Then create an analyzer as follows:
- [source,js]
- --------------------------------------------------
- PUT nori_sample
- {
- "settings": {
- "index": {
- "analysis": {
- "tokenizer": {
- "nori_user_dict": {
- "type": "nori_tokenizer",
- "decompound_mode": "mixed",
- "user_dictionary": "userdict_ko.txt"
- }
- },
- "analyzer": {
- "my_analyzer": {
- "type": "custom",
- "tokenizer": "nori_user_dict"
- }
- }
- }
- }
- }
- }
- GET nori_sample/_analyze
- {
- "analyzer": "my_analyzer",
- "text": "세종시" <1>
- }
- --------------------------------------------------
- // CONSOLE
- <1> Sejong city
- The above `analyze` request returns the following:
- [source,js]
- --------------------------------------------------
- {
- "tokens" : [ {
- "token" : "세종시",
- "start_offset" : 0,
- "end_offset" : 3,
- "type" : "word",
- "position" : 0,
- "positionLength" : 2 <1>
- }, {
- "token" : "세종",
- "start_offset" : 0,
- "end_offset" : 2,
- "type" : "word",
- "position" : 0
- }, {
- "token" : "시",
- "start_offset" : 2,
- "end_offset" : 3,
- "type" : "word",
- "position" : 1
- }]
- }
- --------------------------------------------------
- // TESTRESPONSE
- <1> This is a compound token that spans two positions (`mixed` mode).
- --
- `user_dictionary_rules`::
- +
- --
- You can also inline the rules directly in the tokenizer definition using
- the `user_dictionary_rules` option:
- [source,js]
- --------------------------------------------------
- PUT nori_sample
- {
- "settings": {
- "index": {
- "analysis": {
- "tokenizer": {
- "nori_user_dict": {
- "type": "nori_tokenizer",
- "decompound_mode": "mixed",
- "user_dictionary_rules": ["c++", "C샤프", "세종", "세종시 세종 시"]
- }
- },
- "analyzer": {
- "my_analyzer": {
- "type": "custom",
- "tokenizer": "nori_user_dict"
- }
- }
- }
- }
- }
- }
- --------------------------------------------------
- // CONSOLE
- --
- The `nori_tokenizer` sets a number of additional attributes per token that are used by token filters
- to modify the stream.
- You can view all these additional attributes with the following request:
- [source,js]
- --------------------------------------------------
- GET _analyze
- {
- "tokenizer": "nori_tokenizer",
- "text": "뿌리가 깊은 나무는", <1>
- "attributes" : ["posType", "leftPOS", "rightPOS", "morphemes", "reading"],
- "explain": true
- }
- --------------------------------------------------
- // CONSOLE
- <1> A tree with deep roots
- Which responds with:
- [source,js]
- --------------------------------------------------
- {
- "detail": {
- "custom_analyzer": true,
- "charfilters": [],
- "tokenizer": {
- "name": "nori_tokenizer",
- "tokens": [
- {
- "token": "뿌리",
- "start_offset": 0,
- "end_offset": 2,
- "type": "word",
- "position": 0,
- "leftPOS": "NNG(General Noun)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "NNG(General Noun)"
- },
- {
- "token": "가",
- "start_offset": 2,
- "end_offset": 3,
- "type": "word",
- "position": 1,
- "leftPOS": "J(Ending Particle)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "J(Ending Particle)"
- },
- {
- "token": "깊",
- "start_offset": 4,
- "end_offset": 5,
- "type": "word",
- "position": 2,
- "leftPOS": "VA(Adjective)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "VA(Adjective)"
- },
- {
- "token": "은",
- "start_offset": 5,
- "end_offset": 6,
- "type": "word",
- "position": 3,
- "leftPOS": "E(Verbal endings)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "E(Verbal endings)"
- },
- {
- "token": "나무",
- "start_offset": 7,
- "end_offset": 9,
- "type": "word",
- "position": 4,
- "leftPOS": "NNG(General Noun)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "NNG(General Noun)"
- },
- {
- "token": "는",
- "start_offset": 9,
- "end_offset": 10,
- "type": "word",
- "position": 5,
- "leftPOS": "J(Ending Particle)",
- "morphemes": null,
- "posType": "MORPHEME",
- "reading": null,
- "rightPOS": "J(Ending Particle)"
- }
- ]
- },
- "tokenfilters": []
- }
- }
- --------------------------------------------------
- // TESTRESPONSE
- [[analysis-nori-speech]]
- ==== `nori_part_of_speech` token filter
- The `nori_part_of_speech` token filter removes tokens that match a set of
- part-of-speech tags. The list of supported tags and their meanings can be found here:
- {lucene-core-javadoc}/../analyzers-nori/org/apache/lucene/analysis/ko/POS.Tag.html[Part of speech tags]
- It accepts the following setting:
- `stoptags`::
- An array of part-of-speech tags that should be removed.
- and defaults to:
- [source,js]
- --------------------------------------------------
- "stoptags": [
- "E",
- "IC",
- "J",
- "MAG", "MAJ", "MM",
- "SP", "SSC", "SSO", "SC", "SE",
- "XPN", "XSA", "XSN", "XSV",
- "UNA", "NA", "VSV"
- ]
- --------------------------------------------------
- // NOTCONSOLE
- For example:
- [source,js]
- --------------------------------------------------
- PUT nori_sample
- {
- "settings": {
- "index": {
- "analysis": {
- "analyzer": {
- "my_analyzer": {
- "tokenizer": "nori_tokenizer",
- "filter": [
- "my_posfilter"
- ]
- }
- },
- "filter": {
- "my_posfilter": {
- "type": "nori_part_of_speech",
- "stoptags": [
- "NR" <1>
- ]
- }
- }
- }
- }
- }
- }
- GET nori_sample/_analyze
- {
- "analyzer": "my_analyzer",
- "text": "여섯 용이" <2>
- }
- --------------------------------------------------
- // CONSOLE
- <1> Korean numerals should be removed (`NR`)
- <2> Six dragons
- Which responds with:
- [source,js]
- --------------------------------------------------
- {
- "tokens" : [ {
- "token" : "용",
- "start_offset" : 3,
- "end_offset" : 4,
- "type" : "word",
- "position" : 1
- }, {
- "token" : "이",
- "start_offset" : 4,
- "end_offset" : 5,
- "type" : "word",
- "position" : 2
- } ]
- }
- --------------------------------------------------
- // TESTRESPONSE
- [[analysis-nori-readingform]]
- ==== `nori_readingform` token filter
- The `nori_readingform` token filter rewrites tokens written in Hanja to their Hangul form.
- [source,js]
- --------------------------------------------------
- PUT nori_sample
- {
- "settings": {
- "index":{
- "analysis":{
- "analyzer" : {
- "my_analyzer" : {
- "tokenizer" : "nori_tokenizer",
- "filter" : ["nori_readingform"]
- }
- }
- }
- }
- }
- }
- GET nori_sample/_analyze
- {
- "analyzer": "my_analyzer",
- "text": "鄕歌" <1>
- }
- --------------------------------------------------
- // CONSOLE
- <1> A token written in Hanja: Hyangga
- Which responds with:
- [source,js]
- --------------------------------------------------
- {
- "tokens" : [ {
- "token" : "향가", <1>
- "start_offset" : 0,
- "end_offset" : 2,
- "type" : "word",
- "position" : 0
- }]
- }
- --------------------------------------------------
- // TESTRESPONSE
- <1> The Hanja form is replaced by the Hangul translation.
|