Debian Codegraph @

doc/source/reference/normalizers/normalizer_table.rst

raw
1 .. -*- rst -*-
2
3 .. groonga-command
4 .. database: normalisers
5
6 .. _normalizer-table:
7
8 ``NormalizerTable``
9 ===================
10
11 Summary
12 -------
13
14 .. versionadded:: 11.0.4
15
16 ``NormalizerTable`` normalizes text by user defined normalization table. User defined normalization table is just a normal table but it must satisfy some conditions. They are described later.
17
18 .. note::
19
20 The normalized text is depends on contents of user defined
21 normalization table. If you want to use this normalizer for
22 lexicon, you need to re-index when you change your user defined
23 normalization table.
24
25 Syntax
26 ------
27
28 There are required and optional parameters.
29
30 Required parameters::
31
32 NormalizerTable("normalized", "UserDefinedTable.normalized_column")
33
34 Optional parameters::
35
36 NormalizerTable("normalized", "UserDefinedTable.normalized_column",
37 "target", "target_column")
38
39 NormalizerTable("normalized", "UserDefinedTable.normalized_column",
40 "unicode_version", "13.0.0")
41
42 Usage
43 -----
44
45 .. _normalizer-table-simple-usage:
46
47 Simple usage
48 ^^^^^^^^^^^^
49
50 Here is an example of ``NormalizerTable``.
51
52 ``NormalizerTable`` normalizes text by user defined normalization table. You use the following user defined normalization table here:
53
54 * Table type must be ``TABLE_PAT_KEY``.
55
56 * Table key type must be ``ShortText``.
57
58 * Table must have at least one ``ShortText`` column.
59
60 Here are schema and data for this example:
61
62 .. groonga-command
63 .. include:: ../../example/reference/normalizers/normalizer-table-simple-usage-prepare.log
64 .. table_create Normalizations TABLE_PAT_KEY ShortText
65 .. column_create Normalizations normalized COLUMN_SCALAR ShortText
66 .. load --table Normalizations
67 .. [
68 .. {"_key": "a", "normalized": "<A>"},
69 .. {"_key": "ac", "normalized": "<AC>"}
70 .. ]
71
72 You can normalize ``a`` with ``<A>`` and ``ac`` with ``<AC>`` with this user defined normalization table. For example:
73
74 * ``Groonga`` -> ``Groong<A>``
75
76 * ``hack`` -> ``h<AC>k``
77
78 Here are examples of ``NormalizerTable`` with the user defined normalization table:
79
80 .. groonga-command
81 .. include:: ../../example/reference/normalizers/normalizer-table-simple-usage-output.log
82 .. normalize 'NormalizerTable("normalized", "Normalizations.normalized")' "Groonga"
83 .. normalize 'NormalizerTable("normalized", "Normalizations.normalized")' "hack"
84
85 .. _normalizer-table-usage-unicode-version:
86
87 Unicode version
88 ^^^^^^^^^^^^^^^
89
90 Some internal processings such as tokenization and highlight use character type. ``NormalizerTable`` provides character type based on Unicode. You can specify used Unicode version by :ref:`normalizer-table-unicode-version` option.
91
92 Here is an example to use Unicode 13.0.0:
93
94 .. groonga-command
95 .. include:: ../../example/reference/normalizers/normalizer-table-simple-usage-unicode-version.log
96 .. normalize 'NormalizerTable("normalized", "Normalizations.normalized")' "Groonga" WITH_TYPES
97
98 The default Unicode version is 5.0.0.
99
100 .. _normalizer-table-advanced-usage:
101
102 Advanced usage
103 ^^^^^^^^^^^^^^
104
105 You can put a normalized string to a column instead of ``_key``. In this case, you need to create the following index column for the column:
106
107 * Lexicon type of the index column must be ``TABLE_PAT_KEY``.
108
109 * Lexicon key type of the index column must be ``ShortText``.
110
111 * Lexicon of the index column must not have tokenizer.
112
113 You can use any table type for this usage such as ``TABLE_NO_KEY``. This is useful when you can't control table type. For example, PGroonga users can only use this usage.
114
115 Here are schema and data for this example:
116
117 .. groonga-command
118 .. include:: ../../example/reference/normalizers/normalizer-table-advanced-usage-prepare.log
119 .. table_create ColumnNormalizations TABLE_NO_KEY
120 .. column_create ColumnNormalizations target_column COLUMN_SCALAR ShortText
121 .. column_create ColumnNormalizations normalized COLUMN_SCALAR ShortText
122 ..
123 .. table_create Targets TABLE_PAT_KEY ShortText
124 .. column_create Targets column_normalizations_target_column \
125 .. COLUMN_INDEX ColumnNormalizations target_column
126 ..
127 .. load --table ColumnNormalizations
128 .. [
129 .. {"target_column": "a", "normalized": "<A>"},
130 .. {"target_column": "ac", "normalized": "<AC>"}
131 .. ]
132
133 You need to use :ref:`normalizer-table-target` option to use the user defined normalization table. The above schema uses ``target_column`` for explanation. Generally, ``_column`` in ``target_column`` is redundant but it's added for easy to distinct parameter name and parameter value.
134
135 Here are examples of ``NormalizerTable`` with the user defined normalization table:
136
137 .. groonga-command
138 .. include:: ../../example/reference/normalizers/normalizer-table-simple-usage-output.log
139 .. normalize 'NormalizerTable("normalized", "ColumnNormalizations.normalized", "target", "target_column")' "Groonga"
140 .. normalize 'NormalizerTable("normalized", "ColumnNormalizations.normalized", "target", "target_column")' "hack"
141
142 Parameters
143 ----------
144
145 Required parameter
146 ^^^^^^^^^^^^^^^^^^
147
148 .. _normalizer-table-normalized:
149
150 ``normalized``
151 """"""""""""""
152
153 This option specifies a column that has normalized texts. Normalized target texts are texts in corresponding ``_key`` column or column specified by :ref:`normalizer-table-target`.
154
155 Value type of the column specified for this option must be one of ``ShortText``, ``Text`` and ``LongText``.
156
157 If you don't use :ref:`normalizer-table-target`, the table of column specified for this option must satisfy the followings:
158
159 * Table type is ``TABLE_PAT_KEY``
160
161 * Table key type is ``ShortText``
162
163 See :ref:`normalizer-table-simple-usage` for usage of this case.
164
165 Optional parameters
166 ^^^^^^^^^^^^^^^^^^^
167
168 .. _normalizer-table-target:
169
170 ``target``
171 """"""""""
172
173 This option specifies a column that has normalization target texts.
174
175 Value type of the column specified for this option must be one of ``ShortText``, ``Text`` and ``LongText``.
176
177 You must create an index column for the column specified for this option. The index column and its lexicon must satisfies the followings:
178
179 * Index column can be a single column index or a multi column index.
180
181 * Lexicon type of the index column must be ``TABLE_PAT_KEY``.
182
183 * Lexicon key type of the index column must be ``ShortText``.
184
185 * Lexicon of the index must not have tokenizer.
186
187 See :ref:`normalizer-table-advanced-usage` for usage of this case.
188
189 .. _normalizer-table-unicode-version:
190
191 ``unicode_version``
192 """""""""""""""""""
193
194 This option specifies Unicode version to use determining character type.
195
196 The default Unicode version is 5.0.0.
197
198 See :ref:`normalizer-table-usage-unicode-version` for usage.
199
200 See also
201 --------
202
203 * :doc:`../commands/normalize`