Debian Codegraph @

doc/source/reference/commands/tokenize.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: commands_tokenize
5
6 ``tokenize``
7 ============
8
9 Summary
10 -------
11
12 ``tokenize`` command tokenizes text by the specified tokenizer.
13 It is useful to debug tokenization.
14
15 Syntax
16 ------
17
18 This command takes many parameters.
19
20 ``tokenizer`` and ``string`` are required parameters. Others are
21 optional::
22
23 tokenize tokenizer
24 string
25 [normalizer=null]
26 [flags=NONE]
27 [mode=ADD]
28 [token_filters=NONE]
29 [output_style=full]
30
31 Usage
32 -----
33
34 Here is a simple example.
35
36 .. groonga-command
37 .. include:: ../../example/reference/commands/tokenize/simple_example.log
38 .. tokenize TokenBigram "Fulltext Search"
39
40 It has only required parameters. ``tokenizer`` is ``TokenBigram`` and
41 ``string`` is ``"Fulltext Search"``. It returns tokens that is
42 generated by tokenizing ``"Fulltext Search"`` with ``TokenBigram``
43 tokenizer. It doesn't normalize ``"Fulltext Search"``.
44
45 Parameters
46 ----------
47
48 This section describes all parameters. Parameters are categorized.
49
50 Required parameters
51 ^^^^^^^^^^^^^^^^^^^
52
53 There are required parameters, ``tokenizer`` and ``string``.
54
55 .. _tokenize-tokenizer:
56
57 ``tokenizer``
58 """""""""""""
59
60 Specifies the tokenizer name. ``tokenize`` command uses the
61 tokenizer that is named ``tokenizer``.
62
63 See :doc:`/reference/tokenizers` about built-in tokenizers.
64
65 Here is an example to use built-in ``TokenTrigram`` tokenizer.
66
67 .. groonga-command
68 .. include:: ../../example/reference/commands/tokenize/tokenizer_token_trigram.log
69 .. tokenize TokenTrigram "Fulltext Search"
70
71 If you want to use other tokenizers, you need to register additional
72 tokenizer plugin by :doc:`register` command. For example, you can use
73 `KyTea <http://www.phontron.com/kytea/>`_ based tokenizer by
74 registering ``tokenizers/kytea``.
75
76 .. _tokenize-string:
77
78 ``string``
79 """"""""""
80
81 Specifies any string which you want to tokenize.
82
83 If you want to include spaces in ``string``, you need to quote
84 ``string`` by single quotation (``'``) or double quotation (``"``).
85
86 Here is an example to use spaces in ``string``.
87
88 .. groonga-command
89 .. include:: ../../example/reference/commands/tokenize/string_include_spaces.log
90 .. tokenize TokenBigram "Groonga is a fast fulltext earch engine!"
91
92 Optional parameters
93 ^^^^^^^^^^^^^^^^^^^
94
95 There are optional parameters.
96
97 .. _tokenize-normalizer:
98
99 ``normalizer``
100 """"""""""""""
101
102 Specifies the normalizer name. ``tokenize`` command uses the
103 normalizer that is named ``normalizer``. Normalizer is important for
104 N-gram family tokenizers such as ``TokenBigram``.
105
106 Normalizer detects character type for each character while
107 normalizing. N-gram family tokenizers use character types while
108 tokenizing.
109
110 Here is an example that doesn't use normalizer.
111
112 .. groonga-command
113 .. include:: ../../example/reference/commands/tokenize/normalizer_none.log
114 .. tokenize TokenBigram "Fulltext Search"
115
116 All alphabets are tokenized by two characters. For example, ``Fu`` is
117 a token.
118
119 Here is an example that uses normalizer.
120
121 .. groonga-command
122 .. include:: ../../example/reference/commands/tokenize/normalizer_use.log
123 .. tokenize TokenBigram "Fulltext Search" NormalizerAuto
124
125 Continuous alphabets are tokenized as one token. For example,
126 ``fulltext`` is a token.
127
128 If you want to tokenize by two characters with normalizer, use
129 ``TokenBigramSplitSymbolAlpha``.
130
131 .. groonga-command
132 .. include:: ../../example/reference/commands/tokenize/normalizer_use_with_split_symbol_alpha.log
133 .. tokenize TokenBigramSplitSymbolAlpha "Fulltext Search" NormalizerAuto
134
135 All alphabets are tokenized by two characters. And they are normalized
136 to lower case characters. For example, ``fu`` is a token.
137
138 .. _tokenize-flags:
139
140 ``flags``
141 """""""""
142
143 Specifies a tokenization customize options. You can specify
144 multiple options separated by "``|``". For example,
145 ``NONE|ENABLE_TOKENIZED_DELIMITER``.
146
147 Here are available flags.
148
149 .. list-table::
150 :header-rows: 1
151
152 * - Flag
153 - Description
154 * - ``NONE``
155 - Just ignored.
156 * - ``ENABLE_TOKENIZED_DELIMITER``
157 - Enables tokenized delimiter. See :doc:`/reference/tokenizers` about
158 tokenized delimiter details.
159
160 Here is an example that uses ``ENABLE_TOKENIZED_DELIMITER``.
161
162 .. groonga-command
163 .. include:: ../../example/reference/commands/tokenize/flags_enable_tokenized_delimiter.log
164 .. tokenize TokenDelimit "Full￾text Sea￾crch" NormalizerAuto ENABLE_TOKENIZED_DELIMITER
165
166 ``TokenDelimit`` tokenizer is one of tokenized delimiter supported
167 tokenizer. ``ENABLE_TOKENIZED_DELIMITER`` enables tokenized delimiter.
168 Tokenized delimiter is special character that indicates token
169 border. It is ``U+FFFE``. The character is not assigned any
170 character. It means that the character is not appeared in normal
171 string. So the character is good character for this purpose. If
172 ``ENABLE_TOKENIZED_DELIMITER`` is enabled, the target string is
173 treated as already tokenized string. Tokenizer just tokenizes by
174 tokenized delimiter.
175
176 .. _tokenize-mode:
177
178 ``mode``
179 """"""""
180
181 Specifies a tokenize mode. If the mode is specified ``ADD``, the text
182 is tokenized by the rule that adding a document. If the mode is specified
183 ``GET``, the text is tokenized by the rule that searching a document. If
184 the mode is omitted, the text is tokenized by the ``ADD`` mode.
185
186 The default mode is ``ADD``.
187
188 Here is an example to the ``ADD`` mode.
189
190 .. groonga-command
191 .. include:: ../../example/reference/commands/tokenize/add_mode.log
192 .. tokenize TokenBigram "Fulltext Search" --mode ADD
193
194 The last alphabet is tokenized by one character.
195
196 Here is an example to the ``GET`` mode.
197
198 .. groonga-command
199 .. include:: ../../example/reference/commands/tokenize/get_mode.log
200 .. tokenize TokenBigram "Fulltext Search" --mode GET
201
202 The last alphabet is tokenized by two characters.
203
204 .. _tokenize-token-filters:
205
206 ``token_filters``
207 """""""""""""""""
208
209 Specifies the token filter names. ``tokenize`` command uses the
210 tokenizer that is named ``token_filters``.
211
212 See :doc:`/reference/token_filters` about token filters.
213
214 .. _tokenize-output-style:
215
216 ``output_style``
217 """"""""""""""""
218
219 .. versionadded:: 15.0.9
220
221 Specifies the output style of the ``tokenize`` command.
222
223 .. list-table::
224 :header-rows: 1
225
226 * - Style
227 - Description
228 * - ``full``
229 - This is the default output style. Returns an array of objects with full
230 token attributes (value, position, flags, etc.) as usual.
231 * - ``simple``
232 - Shows only the token values for readability. Returns an array of
233 tokens like ``["We", "are", …]``.
234
235 Here is an example with ``full`` (default) output sytle.
236
237 .. groonga-command
238 .. include:: ../../example/reference/commands/tokenize/output_style/full.log
239 .. tokenize TokenNgram "Fulltext Search" --output_style full
240
241 And here is the same command with ``simple`` output style.
242
243 .. groonga-command
244 .. include:: ../../example/reference/commands/tokenize/output_style/simple.log
245 .. tokenize TokenNgram "Fulltext Search" --output_style simple
246
247 .. _tokenize-return-value:
248
249 Return value
250 ------------
251
252 ``tokenize`` command returns tokenized tokens. Each token has some
253 attributes except token itself. The attributes will be increased in
254 the feature::
255
256 [HEADER, tokens]
257
258 ``HEADER``
259
260 See :doc:`/reference/command/output_format` about ``HEADER``.
261
262 ``tokens``
263
264 ``tokens`` is an array of token. Token is an object that has the following
265 attributes.
266
267 .. list-table::
268 :header-rows: 1
269
270 * - Name
271 - Description
272 * - ``value``
273 - Token itself.
274 * - ``position``
275 - The N-th token.
276
277 See also
278 --------
279
280 * :doc:`/reference/tokenizers`