Debian Codegraph @

doc/source/reference/tokenizers/token_mecab.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: tokenizers_mecab
5
6 .. _token-mecab:
7
8 ``TokenMecab``
9 ================
10
11 Summary
12 -------
13
14 ``TokenMecab`` is a tokenizer based on `MeCab
15 <https://taku910.github.io/mecab/>`_ part-of-speech and
16 morphological analyzer.
17
18 MeCab doesn't depend on Japanese. You can use MeCab for other
19 languages by creating dictionary for the languages. You can use `NAIST
20 Japanese Dictionary <http://osdn.jp/projects/naist-jdic/>`_
21 for Japanese.
22
23 You need to install an additional package to using TokenMecab.
24 For more detail of how to installing an additional package, see :doc:`/install` .
25
26 ``TokenMecab`` is good for precision rather than recall. You can find
27 ``東京都`` and ``京都`` texts by ``京都`` query with
28 :ref:`token-bigram` but ``東京都`` isn't expected. You can find only
29 ``京都`` text by ``京都`` query with ``TokenMecab``.
30
31 If you want to support neologisms, you need to keep updating your
32 MeCab dictionary. It needs maintain cost. (:ref:`token-bigram` doesn't
33 require dictionary maintenance because :ref:`token-bigram` doesn't use
34 dictionary.) `mecab-ipadic-NEologd : Neologism dictionary for MeCab
35 <https://github.com/neologd/mecab-ipadic-neologd>`_ may help you.
36
37 Syntax
38 ------
39
40 ``TokenMecab`` has optional parameter.
41
42 No options::
43
44 TokenMecab
45
46 Specify option::
47
48 TokenMecab("include_class", true)
49
50 TokenMecab("target_class", "a_part_of_speech")
51
52 TokenMecab("include_reading", true)
53
54 TokenMecab("include_form", true)
55
56 TokenMecab("use_reading", true)
57
58 Specify multiple options::
59
60 TokenMecab("target_class", "名詞", "include_reading", true)
61
62 ``TokenMecab`` also specify multiple options as above.
63 You can also specify mingle multiple options except above example.
64
65 Usage
66 -----
67
68 Simple usage
69 ------------
70
71 Here is an example of ``TokenMeCab``. ``東京都`` is tokenized to ``東京``
72 and ``都``. They don't include ``京都``:
73
74 .. groonga-command
75 .. include:: ../../example/reference/tokenizers/token-mecab.log
76 .. tokenize TokenMecab "東京都"
77
78 ``TokenMecab`` can also specify options.
79 ``TokenMecab`` has ``target_class`` option, ``include_class`` option,
80 ``include_reading`` option, ``include_form`` option and ``use_reading`` option.
81
82 ``target_class`` option searches a token of specifying a part-of-speech.
83 For example, you can search only a noun as below.
84
85 .. groonga-command
86 .. include:: ../../example/reference/tokenizers/token-mecab-target-class-option.log
87 .. tokenize 'TokenMecab("target_class", "名詞")' '彼の名前は山田さんのはずです。'
88
89 ``include_class`` option outputs class and subclass in MeCab's metadata as below.
90
91 .. groonga-command
92 .. include:: ../../example/reference/tokenizers/token-mecab-include-class-option.log
93 .. tokenize 'TokenMecab("include_class", true)' '彼の名前は山田さんのはずです。'
94
95 You can exclude needless token with ``target_class`` and class and sub class of this option outputs.
96
97 ``include_reading`` outputs reading in MeCab's metadata as below.
98
99 .. groonga-command
100 .. include:: ../../example/reference/tokenizers/token-mecab-include-reading-option.log
101 .. tokenize 'TokenMecab("include_reading", true)' '彼の名前は山田さんのはずです。'
102
103 You can get reading of a token with this option.
104
105 ``include_form`` outputs inflected_type, inflected_form and base_form in MeCab's metadata as below.
106
107 .. groonga-command
108 .. include:: ../../example/reference/tokenizers/token-mecab-include-form-option.log
109 .. tokenize 'TokenMecab("include_form", true)' '彼の名前は山田さんのはずです。'
110
111 ``use_reading`` supports a search by kana.
112 This option is useful for countermeasure of orthographical variants because it searches with kana.
113
114 .. groonga-command
115 .. include:: ../../example/reference/tokenizers/token-mecab-use-reading-option.log
116 .. tokenize 'TokenMecab("use_reading", true)' '彼の名前は山田さんのはずです。'
117
118 Advanced usage
119 --------------
120
121 ``target_class`` option can also specify subclasses and exclude or add specific
122 part-of-speech of specific using + or -.
123 So, you can also search a noun with excluding non-independent word and suffix of
124 person name as below.
125
126 In this way you can search exclude the noise of token.
127
128 .. groonga-command
129 .. include:: ../../example/reference/tokenizers/token-mecab-target-class-option-complex.log
130 .. tokenize 'TokenMecab("target_class", "-名詞/非自立", "target_class", "-名詞/接尾/人名", "target_class", "名詞")' '彼の名前は山田さんのはずです。'
131
132 In addition, you can get reading of a token that exclude the noise with ``include_reading`` option as below.
133
134 .. groonga-command
135 .. include:: ../../example/reference/tokenizers/token-mecab-target-class-and-include-class-option.log
136 .. tokenize 'TokenMecab("target_class", "-名詞/非自立", "target_class", "-名詞/接尾/人名", "target_class", "名詞", "include_reading", true)' '彼の名前は山田さんのはずです。'
137
138 Parameters
139 ----------
140
141 Optional parameter
142 ^^^^^^^^^^^^^^^^^^
143
144 There are four optional parameters ``include_class`` , ``target_class`` , ``include_form`` and ``use_reading`` .
145
146 ``include_class``
147 """""""""""""""""
148
149 Outputs class and subclass in MeCab's metadata.
150
151 ``target_class``
152 """"""""""""""""
153
154 Outputs a token of specifying a part-of-speech.
155
156 ``include_reading``
157 """""""""""""""""""
158
159 Outputs reading in MeCab's metadata.
160
161 ``include_form``
162 """"""""""""""""
163
164 Outputs inflected_type, inflected_form and base_form in MeCab's metadata.
165
166 ``use_reading``
167 """""""""""""""
168
169 Outputs reading of token.
170
171 See also
172 ----------
173
174 * :doc:`../commands/tokenize`