| 1 | /* |
| 2 | Copyright (C) 2009-2018 Brazil |
| 3 | Copyright (C) 2018-2022 Sutou Kouhei <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #ifdef GRN_EMBEDDED |
| 21 | # define GRN_PLUGIN_FUNCTION_TAG tokenizers_mecab |
| 22 | #endif |
| 23 | |
| 24 | #include <grn_str.h>cxx . . $ `<file>/lib/grn_str.h`/ |
| 25 | |
| 26 | #include <groonga.h>cxx . . $ `<file>/include/groonga.h`/ |
| 27 | #include <groonga/tokenizer.h>cxx . . $ `<file>/include/groonga/tokenizer.h`/ |
| 28 | |
| 29 | #include <grn_encoding.h>cxx . . $ `<file>/lib/grn_encoding.h`/ |
| 30 | |
| 31 | #include <mecab.h> |
| 32 | |
| 33 | #include <stdlib.h> |
| 34 | #include <string.h> |
| 35 | #include <ctype.h> |
| 36 | |
| 37 | #ifdef _MSC_VER |
| 38 | # include <fcntl.h> |
| 39 | #endif |
| 40 | |
| 41 | typedef structcxx . . $ $anonymous_type_bf99ff9bc20f8572_0# { |
| 42 | mecab_model_tcxx . . $ mecab_model_t# *mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.; |
| 43 | mecab_tcxx . . $ mecab_t# *mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.; |
| 44 | grn_plugin_mutexcxx . . $ grn_plugin_mutex# *mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.; |
| 45 | grn_encodingcxx . . $ grn_encoding# encodingcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#encoding.; |
| 46 | } grn_mecabcxx . . $ grn_mecab#; |
| 47 | |
| 48 | static const char *grn_mecab_lattice_variable_namecxx . . $ grn_mecab_lattice_variable_name. = "TokenMecab.lattice"; |
| 49 | |
| 50 | static grn_mecabcxx . . $ grn_mecab# mecab_defaultcxx . . $ mecab_default.; |
| 51 | static grn_mecabcxx . . $ grn_mecab# mecab_newlinecxx . . $ mecab_newline.; |
| 52 | |
| 53 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! grn_mecab_chunked_tokenize_enabledcxx . . $ grn_mecab_chunked_tokenize_enabled. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 54 | static int32_tcxx . . $ int32_t# grn_mecab_chunk_size_thresholdcxx . . $ grn_mecab_chunk_size_threshold. = 8192; |
| 55 | |
| 56 | static const size_t GRN_MECAB_FEATURE_LOCATION_CLASScxx . . $ GRN_MECAB_FEATURE_LOCATION_CLASS. = 0; |
| 57 | static const size_t GRN_MECAB_FEATURE_LOCATION_SUBCLASS0cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS0. = 1; |
| 58 | static const size_t GRN_MECAB_FEATURE_LOCATION_SUBCLASS1cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS1. = 2; |
| 59 | static const size_t GRN_MECAB_FEATURE_LOCATION_SUBCLASS2cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS2. = 3; |
| 60 | static const size_t GRN_MECAB_FEATURE_LOCATION_BASE_FORMcxx . . $ GRN_MECAB_FEATURE_LOCATION_BASE_FORM. = 6; |
| 61 | static const size_t GRN_MECAB_FEATURE_LOCATION_READINGcxx . . $ GRN_MECAB_FEATURE_LOCATION_READING. = 7; |
| 62 | |
| 63 | typedef structcxx . . $ $anonymous_type_bf99ff9bc20f8572_1# { |
| 64 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! chunked_tokenizecxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunked_tokenize.; |
| 65 | int32_tcxx . . $ int32_t# chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold.; |
| 66 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class.; |
| 67 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading.; |
| 68 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form.; |
| 69 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading.; |
| 70 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form.; |
| 71 | grn_objcxx . . $ grn_obj# target_classescxx . . $ $anonymous_type_bf99ff9bc20f8572_1#target_classes.; |
| 72 | } grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options#; |
| 73 | |
| 74 | typedef structcxx . . $ $anonymous_type_bf99ff9bc20f8572_2# { |
| 75 | grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.; |
| 76 | grn_mecabcxx . . $ grn_mecab# *mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.; |
| 77 | mecab_lattice_tcxx . . $ mecab_lattice_t# *latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.; |
| 78 | grn_objcxx . . $ grn_obj# bufcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#buf.; |
| 79 | const char *nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.; |
| 80 | const char *endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end.; |
| 81 | grn_tokenizer_querycxx . . $ grn_tokenizer_query# *querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.; |
| 82 | grn_objcxx . . $ grn_obj# feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.; |
| 83 | } grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer#; |
| 84 | |
| 85 | static const char * |
| 86 | mecab_global_error_messagecxx . . $ mecab_global_error_message(33a1f659e94feb42).(void) |
| 87 | { |
| 88 | double version; |
| 89 | |
| 90 | version = atofcxx . . $ atof(9a18bdb0e56c1bc2).(mecab_versioncxx . . $ mecab_version(87c6ae427bbae0f6).()); |
| 91 | /* MeCab <= 0.993 doesn't support mecab_strerror(NULL). */ |
| 92 | if (version <= 0.993) { |
| 93 | return "Unknown"; |
| 94 | } |
| 95 | |
| 96 | return mecab_strerrorcxx . . $ mecab_strerror(616d7213919ab8c2).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 97 | } |
| 98 | |
| 99 | static grn_encodingcxx . . $ grn_encoding# |
| 100 | translate_mecab_charset_to_grn_encodingcxx . . $ translate_mecab_charset_to_grn_encoding(32570f06a4d1f2d3).(const char *charset) |
| 101 | { |
| 102 | if (grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "euc-jp") == 0) { |
| 103 | return GRN_ENC_EUC_JPcxx . . $ GRN_ENC_EUC_JP.; |
| 104 | } else if (grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "utf-8") == 0 || |
| 105 | grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "utf8") == 0) { |
| 106 | return GRN_ENC_UTF8cxx . . $ GRN_ENC_UTF8.; |
| 107 | } else if (grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "shift_jis") == 0 || |
| 108 | grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "shift-jis") == 0 || |
| 109 | grn_strcasecmpcxx . . $ `include/groonga/portability.h:120:11`!(charset, "sjis") == 0) { |
| 110 | return GRN_ENC_SJIScxx . . $ GRN_ENC_SJIS.; |
| 111 | } |
| 112 | return GRN_ENC_NONEcxx . . $ GRN_ENC_NONE.; |
| 113 | } |
| 114 | |
| 115 | static void |
| 116 | grn_mecab_initcxx . . $ grn_mecab_init(44ab20ba312e6462).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecabcxx . . $ grn_mecab# *mecab, const char *tag) |
| 117 | { |
| 118 | mecab->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 119 | mecab->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 120 | mecab->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex. = grn_plugin_mutex_opencxx . . $ grn_plugin_mutex_open(3cf2524950758967).(ctx); |
| 121 | if (!mecab->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.) { |
| 122 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 123 | GRN_NO_MEMORY_AVAILABLE, |
| 124 | "[plugin][tokenizer][mecab][init]%s " |
| 125 | "failed to initialize mutex", |
| 126 | tag); |
| 127 | return; |
| 128 | } |
| 129 | mecab->encodingcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#encoding. = GRN_ENC_NONEcxx . . $ GRN_ENC_NONE.; |
| 130 | } |
| 131 | |
| 132 | static void |
| 133 | grn_mecab_fincxx . . $ grn_mecab_fin(2579465d0ca1a570).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecabcxx . . $ grn_mecab# *mecab) |
| 134 | { |
| 135 | if (mecab->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.) { |
| 136 | mecab_destroycxx . . $ mecab_destroy(17cb9d5126145d13).(mecab->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.); |
| 137 | mecab->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 138 | } |
| 139 | if (mecab->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.) { |
| 140 | mecab_model_destroycxx . . $ mecab_model_destroy(fe4014ee76637af9).(mecab->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.); |
| 141 | mecab->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 142 | } |
| 143 | if (mecab->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.) { |
| 144 | grn_plugin_mutex_closecxx . . $ grn_plugin_mutex_close(11b54cdd75f6769c).(ctx, mecab->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.); |
| 145 | mecab->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 146 | } |
| 147 | mecab->encodingcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#encoding. = GRN_ENC_NONEcxx . . $ GRN_ENC_NONE.; |
| 148 | } |
| 149 | |
| 150 | static grn_encodingcxx . . $ grn_encoding# |
| 151 | get_mecab_encodingcxx . . $ get_mecab_encoding(90440310e88d9eb6).(mecab_tcxx . . $ mecab_t# *mecab) |
| 152 | { |
| 153 | grn_encodingcxx . . $ grn_encoding# encoding = GRN_ENC_NONEcxx . . $ GRN_ENC_NONE.; |
| 154 | const mecab_dictionary_info_tcxx . . $ mecab_dictionary_info_t# *dictionary_info; |
| 155 | dictionary_info = mecab_dictionary_infocxx . . $ mecab_dictionary_info(4a95582d8d4564f5).(mecab); |
| 156 | if (dictionary_info) { |
| 157 | const char *charset = dictionary_info->charsetcxx . . $ mecab_dictionary_info_t#charset.; |
| 158 | encoding = translate_mecab_charset_to_grn_encodingcxx . . $ translate_mecab_charset_to_grn_encoding(32570f06a4d1f2d3).(charset); |
| 159 | } |
| 160 | return encoding; |
| 161 | } |
| 162 | |
| 163 | static void |
| 164 | mecab_tokenizer_options_initcxx . . $ mecab_tokenizer_options_init(ec3794d7d0742bb).(grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *options) |
| 165 | { |
| 166 | options->chunked_tokenizecxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunked_tokenize. = grn_mecab_chunked_tokenize_enabledcxx . . $ grn_mecab_chunked_tokenize_enabled.; |
| 167 | options->chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold. = grn_mecab_chunk_size_thresholdcxx . . $ grn_mecab_chunk_size_threshold.; |
| 168 | options->include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 169 | options->include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 170 | options->include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 171 | options->use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 172 | options->use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 173 | GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&(options->target_classes), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!); |
| 174 | } |
| 175 | |
| 176 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 177 | mecab_tokenizer_options_need_default_outputcxx . . $ mecab_tokenizer_options_need_default_output(1386cf2ee849f0d4).( |
| 178 | grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *options) |
| 179 | { |
| 180 | if (!options) { |
| 181 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 182 | } |
| 183 | |
| 184 | if (options->include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class.) { |
| 185 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 186 | } |
| 187 | |
| 188 | if (options->include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading.) { |
| 189 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 190 | } |
| 191 | |
| 192 | if (options->include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form.) { |
| 193 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 194 | } |
| 195 | |
| 196 | if (options->use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading.) { |
| 197 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 198 | } |
| 199 | |
| 200 | if (options->use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form.) { |
| 201 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 202 | } |
| 203 | |
| 204 | if (grn_vector_sizecxx . . $ grn_vector_size(8dd58acc9865e889).(ctx, &(options->target_classescxx . . $ $anonymous_type_bf99ff9bc20f8572_1#target_classes.)) > 0) { |
| 205 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 206 | } |
| 207 | |
| 208 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 209 | } |
| 210 | |
| 211 | static void * |
| 212 | mecab_tokenizer_options_opencxx . . $ mecab_tokenizer_options_open(935e2583f8354665).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 213 | grn_objcxx . . $ grn_obj# *lexicon, |
| 214 | grn_objcxx . . $ grn_obj# *raw_options, |
| 215 | void *user_data) |
| 216 | { |
| 217 | grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *options; |
| 218 | |
| 219 | options = GRN_PLUGIN_MALLOCcxx . . $ `include/groonga/plugin.h:88:9`!(ctx, sizeof(grn_mecab_tokenizer_options)); |
| 220 | if (!options) { |
| 221 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 222 | GRN_NO_MEMORY_AVAILABLE, |
| 223 | "[tokenizer][mecab] " |
| 224 | "failed to allocate memory for options"); |
| 225 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 226 | } |
| 227 | |
| 228 | mecab_tokenizer_options_initcxx . . $ mecab_tokenizer_options_init(ec3794d7d0742bb).(options); |
| 229 | |
| 230 | GRN_OPTION_VALUES_EACH_BEGINcxx . . $ `include/groonga/option.h:29:9`!(ctx, raw_options, i, name, name_length) |
| 231 | { |
| 232 | grn_raw_stringcxx . . $ grn_raw_string# name_raw; |
| 233 | name_raw.valuecxx . . $ $anonymous_type_7f733dd816802915_0#value. = name; |
| 234 | name_raw.lengthcxx . . $ $anonymous_type_7f733dd816802915_0#length. = name_length; |
| 235 | |
| 236 | if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "chunked_tokenize")) { |
| 237 | options->chunked_tokenizecxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunked_tokenize. = |
| 238 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, |
| 239 | raw_options, |
| 240 | i, |
| 241 | options->chunked_tokenizecxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunked_tokenize.); |
| 242 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "chunk_size_threshold")) { |
| 243 | options->chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold. = |
| 244 | grn_vector_get_element_int32cxx . . $ grn_vector_get_element_int32(d5165b756c4d3fb2).(ctx, |
| 245 | raw_options, |
| 246 | i, |
| 247 | options->chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold.); |
| 248 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "include_class")) { |
| 249 | options->include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class. = |
| 250 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, |
| 251 | raw_options, |
| 252 | i, |
| 253 | options->include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class.); |
| 254 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "include_reading")) { |
| 255 | options->include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading. = |
| 256 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, |
| 257 | raw_options, |
| 258 | i, |
| 259 | options->include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading.); |
| 260 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "include_form")) { |
| 261 | options->include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form. = |
| 262 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, raw_options, i, options->include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form.); |
| 263 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "use_reading")) { |
| 264 | options->use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading. = |
| 265 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, raw_options, i, options->use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading.); |
| 266 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "use_base_form")) { |
| 267 | options->use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form. = |
| 268 | grn_vector_get_element_boolcxx . . $ grn_vector_get_element_bool(c757f44c94d2a098).(ctx, |
| 269 | raw_options, |
| 270 | i, |
| 271 | options->use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form.); |
| 272 | } else if (GRN_RAW_STRING_EQUAL_CSTRINGcxx . . $ `include/groonga/raw_string.h:57:9`!(name_raw, "target_class")) { |
| 273 | const char *target_class = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 274 | unsigned int target_class_length; |
| 275 | grn_idcxx . . $ grn_id# domain; |
| 276 | |
| 277 | target_class_length = grn_vector_get_elementcxx . . $ grn_vector_get_element(744613554bd9830c).(ctx, |
| 278 | raw_options, |
| 279 | i, |
| 280 | &target_class, |
| 281 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 282 | &domain); |
| 283 | if (grn_type_id_is_text_familycxx . . $ grn_type_id_is_text_family(a2a496425acc5b40).(ctx, domain) && target_class_length > 0) { |
| 284 | grn_vector_add_elementcxx . . $ grn_vector_add_element(d170aee3d3986928).(ctx, |
| 285 | &(options->target_classescxx . . $ $anonymous_type_bf99ff9bc20f8572_1#target_classes.), |
| 286 | target_class, |
| 287 | target_class_length, |
| 288 | 0, |
| 289 | GRN_DB_TEXTcxx . . $ GRN_DB_TEXT.); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | GRN_OPTION_VALUES_EACH_ENDcxx . . $ `include/groonga/option.h:55:9`!(); |
| 294 | |
| 295 | return options; |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | mecab_tokenizer_options_closecxx . . $ mecab_tokenizer_options_close(b6b6153f622d9caa).(grn_ctxcxx . . $ grn_ctx# *ctx, void *data) |
| 300 | { |
| 301 | grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *options = data; |
| 302 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(options->target_classes)); |
| 303 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, options); |
| 304 | } |
| 305 | |
| 306 | static inline boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 307 | is_delimiter_charactercxx . . $ is_delimiter_character(da3161f0ad1ba10a).(grn_ctxcxx . . $ grn_ctx# *ctx, const char *character, int character_bytes) |
| 308 | { |
| 309 | switch (character_bytes) { |
| 310 | case 1: |
| 311 | switch (character[0]) { |
| 312 | case ',': |
| 313 | case '.': |
| 314 | case '!': |
| 315 | case '?': |
| 316 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 317 | default: |
| 318 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 319 | } |
| 320 | case 3: |
| 321 | switch ((unsigned char)(character[0])) { |
| 322 | case 0xE3: |
| 323 | switch ((unsigned char)(character[1])) { |
| 324 | case 0x80: |
| 325 | switch ((unsigned char)(character[2])) { |
| 326 | case 0x81: /* U+3001 (0xE3 0x80 0x81 in UTF-8) IDEOGRAPHIC COMMA */ |
| 327 | case 0x82: /* U+3002 (0xE3 0x80 0x82 in UTF-8) IDEOGRAPHIC FULL STOP */ |
| 328 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 329 | default: |
| 330 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 331 | } |
| 332 | default: |
| 333 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 334 | } |
| 335 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 336 | case 0xEF: |
| 337 | switch ((unsigned char)(character[1])) { |
| 338 | case 0xBC: |
| 339 | switch ((unsigned char)(character[2])) { |
| 340 | case 0x81: |
| 341 | /* U+FF01 (0xEF 0xBC 0x81 in UTF-8) FULLWIDTH EXCLAMATION MARK */ |
| 342 | case 0x9F: |
| 343 | /* U+FF1F (0xEF 0xBC 0x9F in UTF-8) FULLWIDTH QUESTION MARK */ |
| 344 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 345 | default: |
| 346 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 347 | } |
| 348 | default: |
| 349 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 350 | } |
| 351 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 352 | default: |
| 353 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 354 | } |
| 355 | default: |
| 356 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 361 | chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 362 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer, |
| 363 | const char *chunk, |
| 364 | size_t chunk_bytes) |
| 365 | { |
| 366 | const char *tokenized_chunk; |
| 367 | size_t tokenized_chunk_length; |
| 368 | mecab_lattice_set_sentence2cxx . . $ mecab_lattice_set_sentence2(c49493322a3b2d5d).(tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice., chunk, chunk_bytes); |
| 369 | if (!mecab_parse_latticecxx . . $ mecab_parse_lattice(f11feb0fb0fd8f21).(tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab., tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.)) { |
| 370 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 371 | GRN_TOKENIZER_ERROR, |
| 372 | "[tokenizer][mecab][chunk] " |
| 373 | "mecab_parse_lattice() failed " |
| 374 | "len=%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " err=%s", |
| 375 | chunk_bytes, |
| 376 | mecab_lattice_strerror(tokenizer->lattice)); |
| 377 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 378 | } |
| 379 | tokenized_chunk = mecab_lattice_tostrcxx . . $ mecab_lattice_tostr(f62beac619fbc2a).(tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.); |
| 380 | if (!tokenized_chunk) { |
| 381 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 382 | GRN_TOKENIZER_ERROR, |
| 383 | "[tokenizer][mecab][chunk] " |
| 384 | "mecab_sparse_tostr2() failed " |
| 385 | "len=%" GRN_FMT_SIZEcxx . . $ `lib/grn.h:408:11`! " err=%s", |
| 386 | chunk_bytes, |
| 387 | mecab_lattice_strerror(tokenizer->lattice)); |
| 388 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 389 | } |
| 390 | |
| 391 | if (GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&(tokenizer->buf)) > 0) { |
| 392 | GRN_TEXT_PUTScxx . . $ `include/groonga/groonga.h:2781:9`!(ctx, &(tokenizer->buf), "\n"); |
| 393 | } |
| 394 | |
| 395 | tokenized_chunk_length = strlencxx . . $ strlen(751346f8406fd082).(tokenized_chunk); |
| 396 | if (tokenized_chunk_length >= 1 && |
| 397 | isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!((unsigned char)tokenized_chunk[tokenized_chunk_length - 1])) { |
| 398 | GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, |
| 399 | &(tokenizer->buf), |
| 400 | tokenized_chunk, |
| 401 | tokenized_chunk_length - 1); |
| 402 | } else { |
| 403 | GRN_TEXT_PUTcxx . . $ `include/groonga/groonga.h:2773:9`!(ctx, |
| 404 | &(tokenizer->buf), |
| 405 | tokenized_chunk, |
| 406 | tokenized_chunk_length); |
| 407 | } |
| 408 | |
| 409 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 410 | } |
| 411 | |
| 412 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 413 | chunked_tokenize_utf8cxx . . $ chunked_tokenize_utf8(7b348e27a4aaed1).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 414 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer, |
| 415 | const char *string, |
| 416 | unsigned int string_bytes) |
| 417 | { |
| 418 | const char *chunk_start; |
| 419 | const char *current; |
| 420 | const char *last_delimiter; |
| 421 | const char *string_end = string + string_bytes; |
| 422 | grn_encodingcxx . . $ grn_encoding# encoding = |
| 423 | grn_tokenizer_query_get_encodingcxx . . $ grn_tokenizer_query_get_encoding(beecbcfbc135f783).(ctx, tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.); |
| 424 | |
| 425 | if ((int32_tcxx . . $ int32_t#)string_bytes < tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold.) { |
| 426 | return chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(ctx, tokenizer, string, string_bytes); |
| 427 | } |
| 428 | |
| 429 | chunk_start = current = string; |
| 430 | last_delimiter = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 431 | while (current < string_end) { |
| 432 | int space_bytes; |
| 433 | int character_bytes; |
| 434 | const char *current_character; |
| 435 | |
| 436 | space_bytes = grn_isspacecxx . . $ grn_isspace(f8f88a86d74aa1ba).(current, encoding); |
| 437 | if (space_bytes > 0) { |
| 438 | if (chunk_start != current) { |
| 439 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! succeeded = |
| 440 | chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(ctx, |
| 441 | tokenizer, |
| 442 | chunk_start, |
| 443 | (size_t)(current - chunk_start)); |
| 444 | if (!succeeded) { |
| 445 | return succeeded; |
| 446 | } |
| 447 | } |
| 448 | current += space_bytes; |
| 449 | chunk_start = current; |
| 450 | last_delimiter = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 451 | continue; |
| 452 | } |
| 453 | |
| 454 | character_bytes = grn_charlen_cxx . . $ grn_charlen_(b4b53c9e31f93d3e).(ctx, current, string_end, encoding); |
| 455 | if (character_bytes == 0) { |
| 456 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 457 | GRN_TOKENIZER_ERROR, |
| 458 | "[tokenizer][mecab][chunk] " |
| 459 | "invalid byte sequence: position=%d", |
| 460 | (int)(current - string)); |
| 461 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 462 | } |
| 463 | |
| 464 | current_character = current; |
| 465 | current += character_bytes; |
| 466 | if (is_delimiter_charactercxx . . $ is_delimiter_character(da3161f0ad1ba10a).(ctx, current_character, character_bytes)) { |
| 467 | last_delimiter = current; |
| 468 | } |
| 469 | |
| 470 | if ((current - chunk_start) >= tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->chunk_size_thresholdcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunk_size_threshold.) { |
| 471 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! succeeded; |
| 472 | if (last_delimiter) { |
| 473 | succeeded = |
| 474 | chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(ctx, |
| 475 | tokenizer, |
| 476 | chunk_start, |
| 477 | (size_t)(last_delimiter - chunk_start)); |
| 478 | chunk_start = last_delimiter; |
| 479 | } else { |
| 480 | succeeded = |
| 481 | chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(ctx, |
| 482 | tokenizer, |
| 483 | chunk_start, |
| 484 | (size_t)(current - chunk_start)); |
| 485 | chunk_start = current; |
| 486 | } |
| 487 | if (!succeeded) { |
| 488 | return succeeded; |
| 489 | } |
| 490 | last_delimiter = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if (current == chunk_start) { |
| 495 | return truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 496 | } else { |
| 497 | return chunked_tokenize_utf8_chunkcxx . . $ chunked_tokenize_utf8_chunk(84bf168ed8d04b26).(ctx, |
| 498 | tokenizer, |
| 499 | chunk_start, |
| 500 | (size_t)(current - chunk_start)); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | static mecab_model_tcxx . . $ mecab_model_t# * |
| 505 | mecab_model_createcxx . . $ mecab_model_create(d5691e33f02765fa).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecab_tokenizer_optionscxx . . $ grn_mecab_tokenizer_options# *options) |
| 506 | { |
| 507 | mecab_model_tcxx . . $ mecab_model_t# *mecab_model; |
| 508 | int argc = 0; |
| 509 | const char *argv[5]; |
| 510 | const char *tag; |
| 511 | |
| 512 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! need_default_output = |
| 513 | mecab_tokenizer_options_need_default_outputcxx . . $ mecab_tokenizer_options_need_default_output(1386cf2ee849f0d4).(ctx, options); |
| 514 | |
| 515 | if (need_default_output) { |
| 516 | tag = "[default]"; |
| 517 | } else { |
| 518 | tag = "[newline]"; |
| 519 | } |
| 520 | |
| 521 | argv[argc++] = "Groonga"; |
| 522 | if (!need_default_output) { |
| 523 | argv[argc++] = "-F%m\n"; |
| 524 | argv[argc++] = "-E\n"; |
| 525 | } |
| 526 | #ifdef GRN_WITH_BUNDLED_MECAB |
| 527 | argv[argc++] = "--rcfile"; |
| 528 | # ifdef WIN32 |
| 529 | { |
| 530 | static char windows_mecab_rc_file[PATH_MAX]; |
| 531 | const char *utf8_base_dir; |
| 532 | |
| 533 | utf8_base_dir = |
| 534 | grn_encoding_convert_to_utf8_from_locale(ctx, |
| 535 | grn_plugin_windows_base_dir(), |
| 536 | -1, |
| 537 | NULL); |
| 538 | grn_strcpy(windows_mecab_rc_file, PATH_MAX, utf8_base_dir); |
| 539 | grn_encoding_converted_free(ctx, utf8_base_dir); |
| 540 | grn_strcat(windows_mecab_rc_file, PATH_MAX, "/"); |
| 541 | grn_strcat(windows_mecab_rc_file, |
| 542 | PATH_MAX, |
| 543 | GRN_BUNDLED_MECAB_RELATIVE_RC_PATH); |
| 544 | { |
| 545 | char *c; |
| 546 | for (c = windows_mecab_rc_file; *c != '\0'; c++) { |
| 547 | if (*c == '/') { |
| 548 | *c = '\\'; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | argv[argc++] = windows_mecab_rc_file; |
| 553 | } |
| 554 | # else /* WIN32 */ |
| 555 | argv[argc++] = GRN_BUNDLED_MECAB_RC_PATH; |
| 556 | # endif /* WIN32 */ |
| 557 | #endif /* GRN_WITH_BUNDLED_MECAB */ |
| 558 | |
| 559 | #if _MSC_VER |
| 560 | /* This is a workaround for MariaDB 10.9 or later and MeCab. |
| 561 | * |
| 562 | * MariaDB 10.9 or later calls _set_fmode(_O_BINARY) in |
| 563 | * initialization process on Windows. |
| 564 | * |
| 565 | * See also: |
| 566 | * https://github.com/MariaDB/server/commit/016dd21371961700f1324f204acbc7252a8c1e76 |
| 567 | * |
| 568 | * But mecab_model_new() doesn't work with _O_BINARY on Windows |
| 569 | * because "\r" in mecab.rc is processed as a line content. This |
| 570 | * causes a parse error. |
| 571 | * |
| 572 | * We change restore the default file translation mode to _O_TEXT |
| 573 | * temporary here. But this is not safe. If some files are open in |
| 574 | * other threads, these threads open a file with _O_TEXT not |
| 575 | * _O_BINARY. |
| 576 | * |
| 577 | * MariaDB should not use _set_fmode() because it changes the |
| 578 | * default file translation mode globally. But this is the MariaDB's |
| 579 | * decision. So we need this workaround. */ |
| 580 | int current_file_translation_mode = _O_TEXT; |
| 581 | _get_fmode(¤t_file_translation_mode); |
| 582 | _set_fmode(_O_TEXT); |
| 583 | #endif |
| 584 | mecab_model = mecab_model_newcxx . . $ mecab_model_new(e86bded79974a060).(argc, (char **)argv); |
| 585 | #if __MSC_VER |
| 586 | _set_fmode(current_file_translation_mode); |
| 587 | #endif |
| 588 | |
| 589 | if (!mecab_model) { |
| 590 | #ifdef GRN_WITH_BUNDLED_MECAB |
| 591 | { |
| 592 | const char *grn_encoding_rc_file; |
| 593 | grn_encoding_rc_file = |
| 594 | grn_encoding_convert_from_locale(ctx, argv[argc - 1], -1, NULL); |
| 595 | if (need_default_output) { |
| 596 | GRN_PLUGIN_ERROR(ctx, |
| 597 | GRN_TOKENIZER_ERROR, |
| 598 | "[tokenizer][mecab][create]%s " |
| 599 | "failed to create mecab_model_t: %s: " |
| 600 | "mecab_model_new(\"%s\", \"%s\", \"%s\")", |
| 601 | tag, |
| 602 | mecab_global_error_message(), |
| 603 | argv[0], |
| 604 | argv[1], |
| 605 | grn_encoding_rc_file); |
| 606 | } else { |
| 607 | GRN_PLUGIN_ERROR(ctx, |
| 608 | GRN_TOKENIZER_ERROR, |
| 609 | "[tokenizer][mecab][create]%s " |
| 610 | "failed to create mecab_model_t: %s: " |
| 611 | "mecab_model_new(\"%s\", \"%s\", \"%s\", \"%s\")", |
| 612 | tag, |
| 613 | mecab_global_error_message(), |
| 614 | argv[0], |
| 615 | argv[1], |
| 616 | argv[2], |
| 617 | grn_encoding_rc_file); |
| 618 | } |
| 619 | grn_encoding_converted_free(ctx, grn_encoding_rc_file); |
| 620 | } |
| 621 | #else /* GRN_WITH_BUNDLED_MECAB */ |
| 622 | if (need_default_output) { |
| 623 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 624 | GRN_TOKENIZER_ERROR, |
| 625 | "[tokenizer][mecab][create]%s " |
| 626 | "failed to create mecab_model_t: %s: " |
| 627 | "mecab_model_new(\"%s\")", |
| 628 | tag, |
| 629 | mecab_global_error_message(), |
| 630 | argv[0]); |
| 631 | } else { |
| 632 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 633 | GRN_TOKENIZER_ERROR, |
| 634 | "[tokenizer][mecab][create]%s " |
| 635 | "failed to create mecab_model_t: %s: " |
| 636 | "mecab_model_new(\"%s\", \"%s\")", |
| 637 | tag, |
| 638 | mecab_global_error_message(), |
| 639 | argv[0], |
| 640 | argv[1]); |
| 641 | } |
| 642 | #endif /* GRN_WITH_BUNDLED_MECAB */ |
| 643 | } |
| 644 | |
| 645 | return mecab_model; |
| 646 | } |
| 647 | |
| 648 | static void |
| 649 | mecab_init_mecabcxx . . $ mecab_init_mecab(854c29834e16186a).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer) |
| 650 | { |
| 651 | if (mecab_tokenizer_options_need_default_outputcxx . . $ mecab_tokenizer_options_need_default_output(1386cf2ee849f0d4).(ctx, tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.)) { |
| 652 | tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab. = &mecab_defaultcxx . . $ mecab_default.; |
| 653 | } else { |
| 654 | tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab. = &mecab_newlinecxx . . $ mecab_newline.; |
| 655 | } |
| 656 | |
| 657 | if (!tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.) { |
| 658 | grn_plugin_mutex_lockcxx . . $ grn_plugin_mutex_lock(11b54cdd75f6769c).(ctx, tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.); |
| 659 | if (!tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.) { |
| 660 | tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model. = |
| 661 | mecab_model_createcxx . . $ mecab_model_create(d5691e33f02765fa).(ctx, tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.); |
| 662 | if (tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.) { |
| 663 | tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab. = |
| 664 | mecab_model_new_taggercxx . . $ mecab_model_new_tagger(1474d08a6d9c13d4).(tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.); |
| 665 | if (tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.) { |
| 666 | tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->encodingcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#encoding. = |
| 667 | get_mecab_encodingcxx . . $ get_mecab_encoding(90440310e88d9eb6).(tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.); |
| 668 | } |
| 669 | } |
| 670 | } |
| 671 | grn_plugin_mutex_unlockcxx . . $ grn_plugin_mutex_unlock(11b54cdd75f6769c).(ctx, tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mutexcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mutex.); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | static void |
| 676 | mecab_next_default_format_skip_eoscxx . . $ mecab_next_default_format_skip_eos(854c29834e16186a).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer) |
| 677 | { |
| 678 | if (tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. + 4 < tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end.) { |
| 679 | return; |
| 680 | } |
| 681 | |
| 682 | if (strncmpcxx . . $ strncmp(fd278af2f295fa2e).(tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next., "EOS", 3) == 0) { |
| 683 | const char *current = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. + 3; |
| 684 | if (current < tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. && current[0] == '\r') { |
| 685 | current++; |
| 686 | } |
| 687 | if (current < tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. && current[0] == '\n') { |
| 688 | current++; |
| 689 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = current; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | typedef structcxx . . $ $anonymous_type_bf99ff9bc20f8572_3# { |
| 695 | grn_tokencxx . . $ grn_token# *tokencxx . . $ $anonymous_type_bf99ff9bc20f8572_3#token.; |
| 696 | grn_objcxx . . $ grn_obj# *feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_3#feature_locations.; |
| 697 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! ignore_empty_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_empty_value.; |
| 698 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! ignore_asterisk_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_asterisk_value.; |
| 699 | } add_feature_datacxx . . $ add_feature_data#; |
| 700 | |
| 701 | static size_t |
| 702 | mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 703 | grn_objcxx . . $ grn_obj# *feature_locations, |
| 704 | size_t i, |
| 705 | const char **value) |
| 706 | { |
| 707 | size_t n_locations = GRN_BULK_VSIZEcxx . . $ `include/groonga/groonga.h:2642:9`!(feature_locations) / sizeof(uint64_tcxx . . $ uint64_t#); |
| 708 | const char *start; |
| 709 | const char *end; |
| 710 | |
| 711 | if (i + 2 > n_locations) { |
| 712 | *value = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | start = (const char *)(GRN_UINT64_VALUE_ATcxx . . $ `include/groonga/groonga.h:3140:9`!(feature_locations, i)); |
| 717 | end = ((const char *)(GRN_UINT64_VALUE_ATcxx . . $ `include/groonga/groonga.h:3140:9`!(feature_locations, i + 1))) - 1; |
| 718 | *value = start; |
| 719 | return (size_t)(end - start); |
| 720 | } |
| 721 | |
| 722 | static void |
| 723 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 724 | add_feature_datacxx . . $ add_feature_data# *data, |
| 725 | const char *name, |
| 726 | size_t i) |
| 727 | { |
| 728 | grn_tokencxx . . $ grn_token# *token = data->tokencxx . . $ $anonymous_type_bf99ff9bc20f8572_3#token.; |
| 729 | grn_objcxx . . $ grn_obj# *feature_locations = data->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_3#feature_locations.; |
| 730 | const char *feature = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 731 | size_t feature_length; |
| 732 | grn_objcxx . . $ grn_obj# value; |
| 733 | |
| 734 | feature_length = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, feature_locations, i, &feature); |
| 735 | if (data->ignore_empty_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_empty_value. && feature_length == 0) { |
| 736 | return; |
| 737 | } |
| 738 | if (data->ignore_asterisk_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_asterisk_value. && feature_length == 1 && feature[0] == '*') { |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&value, GRN_OBJ_DO_SHALLOW_COPYcxx . . $ `include/groonga/groonga.h:2732:9`!); |
| 743 | GRN_TEXT_SETcxx . . $ `include/groonga/groonga.h:2761:9`!(ctx, &value, feature, feature_length); |
| 744 | grn_token_metadata_addcxx . . $ grn_token_metadata_add(7fd90b291c306ffc).(ctx, |
| 745 | grn_token_get_metadatacxx . . $ grn_token_get_metadata(fa6b3ffdb9b18cb).(ctx, token), |
| 746 | name, |
| 747 | -1, |
| 748 | &value); |
| 749 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &value); |
| 750 | } |
| 751 | |
| 752 | static size_t |
| 753 | mecab_next_default_format_consume_tokencxx . . $ mecab_next_default_format_consume_token(576fce732dfc23ae).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 754 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer, |
| 755 | const char **surface_output) |
| 756 | { |
| 757 | grn_encodingcxx . . $ grn_encoding# encoding = tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.->encodingcxx . . $ _grn_tokenizer_query_deprecated#encoding.; |
| 758 | grn_objcxx . . $ grn_obj# *feature_locations = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 759 | const char *start; |
| 760 | const char *current; |
| 761 | const char *end = tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end.; |
| 762 | const char *surface = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 763 | int length = 0; |
| 764 | size_t surface_length = 0; |
| 765 | |
| 766 | if (surface_output) { |
| 767 | *surface_output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 768 | } |
| 769 | |
| 770 | GRN_BULK_REWINDcxx . . $ `include/groonga/groonga.h:2599:9`!(feature_locations); |
| 771 | mecab_next_default_format_skip_eoscxx . . $ mecab_next_default_format_skip_eos(854c29834e16186a).(ctx, tokenizer); |
| 772 | start = surface = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.; |
| 773 | for (current = start; current < end; current += length) { |
| 774 | length = grn_charlen_cxx . . $ grn_charlen_(b4b53c9e31f93d3e).(ctx, current, end, encoding); |
| 775 | if (length == 0) { |
| 776 | if (surface_output) { |
| 777 | *surface_output = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 778 | } |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | if (length == 1) { |
| 783 | if (current[0] == '\r') { |
| 784 | if (surface_length == 0) { |
| 785 | surface_length = (size_t)(current - surface); |
| 786 | } else { |
| 787 | GRN_UINT64_PUTcxx . . $ `include/groonga/groonga.h:3192:9`!(ctx, feature_locations, current); |
| 788 | } |
| 789 | current++; |
| 790 | if (current < end && grn_charlen_cxx . . $ grn_charlen_(b4b53c9e31f93d3e).(ctx, current, end, encoding) == 1 && |
| 791 | current[0] == '\n') { |
| 792 | current++; |
| 793 | } |
| 794 | break; |
| 795 | } else if (current[0] == '\n') { |
| 796 | if (surface_length == 0) { |
| 797 | surface_length = (size_t)(current - surface); |
| 798 | } else { |
| 799 | GRN_UINT64_PUTcxx . . $ `include/groonga/groonga.h:3192:9`!(ctx, feature_locations, current); |
| 800 | } |
| 801 | current++; |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | if (surface_length == 0) { |
| 807 | if (length == 1 && current[0] == '\t') { |
| 808 | surface_length = (size_t)(current - surface); |
| 809 | if (current + 1 < end) { |
| 810 | GRN_UINT64_PUTcxx . . $ `include/groonga/groonga.h:3192:9`!(ctx, feature_locations, current + 1); |
| 811 | } |
| 812 | } |
| 813 | } else { |
| 814 | if (length == 1 && current[0] == ',' && current + 1 < end) { |
| 815 | GRN_UINT64_PUTcxx . . $ `include/groonga/groonga.h:3192:9`!(ctx, feature_locations, current + 1); |
| 816 | } |
| 817 | } |
| 818 | } |
| 819 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = current; |
| 820 | mecab_next_default_format_skip_eoscxx . . $ mecab_next_default_format_skip_eos(854c29834e16186a).(ctx, tokenizer); |
| 821 | |
| 822 | if (surface_output) { |
| 823 | *surface_output = surface; |
| 824 | } |
| 825 | return surface_length; |
| 826 | } |
| 827 | |
| 828 | static boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! |
| 829 | mecab_next_default_format_match_classcxx . . $ mecab_next_default_format_match_class(955ca4c3dbafa1a7).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 830 | const char *target_class, |
| 831 | size_t target_class_length, |
| 832 | const char *class, |
| 833 | size_t class_length) |
| 834 | { |
| 835 | if (class_length == 0) { |
| 836 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 837 | } |
| 838 | |
| 839 | if (target_class_length < class_length) { |
| 840 | return falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 841 | } |
| 842 | |
| 843 | return memcmpcxx . . $ memcmp(36f949851efa3055).(target_class, class, class_length) == 0; |
| 844 | } |
| 845 | |
| 846 | static void |
| 847 | mecab_next_default_format_consume_needless_tokenscxx . . $ mecab_next_default_format_consume_needless_tokens(854c29834e16186a).( |
| 848 | grn_ctxcxx . . $ grn_ctx# *ctx, grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer) |
| 849 | { |
| 850 | grn_objcxx . . $ grn_obj# *target_classes = &(tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->target_classescxx . . $ $anonymous_type_bf99ff9bc20f8572_1#target_classes.); |
| 851 | unsigned int n_target_classes; |
| 852 | const char *last_next = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.; |
| 853 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! is_target = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 854 | |
| 855 | n_target_classes = grn_vector_sizecxx . . $ grn_vector_size(8dd58acc9865e889).(ctx, target_classes); |
| 856 | |
| 857 | if (n_target_classes == 0) { |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | while (tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. != tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. && !is_target) { |
| 862 | const char *surface = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 863 | size_t surface_length = 0; |
| 864 | unsigned int i; |
| 865 | grn_objcxx . . $ grn_obj# *feature_locations; |
| 866 | const size_t n_classes = 4; |
| 867 | const char *classes[4]; |
| 868 | size_t class_lengths[4]; |
| 869 | |
| 870 | last_next = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.; |
| 871 | surface_length = |
| 872 | mecab_next_default_format_consume_tokencxx . . $ mecab_next_default_format_consume_token(576fce732dfc23ae).(ctx, tokenizer, &surface); |
| 873 | |
| 874 | if (surface_length == 0) { |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | feature_locations = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 879 | class_lengths[0] = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 880 | feature_locations, |
| 881 | GRN_MECAB_FEATURE_LOCATION_CLASScxx . . $ GRN_MECAB_FEATURE_LOCATION_CLASS., |
| 882 | &(classes[0])); |
| 883 | class_lengths[1] = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 884 | feature_locations, |
| 885 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS0cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS0., |
| 886 | &(classes[1])); |
| 887 | class_lengths[2] = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 888 | feature_locations, |
| 889 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS1cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS1., |
| 890 | &(classes[2])); |
| 891 | class_lengths[3] = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 892 | feature_locations, |
| 893 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS2cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS2., |
| 894 | &(classes[3])); |
| 895 | for (i = 0; i < n_target_classes; i++) { |
| 896 | const char *target_class; |
| 897 | size_t target_class_length; |
| 898 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! positive = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 899 | size_t j; |
| 900 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! matched = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 901 | |
| 902 | target_class_length = grn_vector_get_elementcxx . . $ grn_vector_get_element(744613554bd9830c).(ctx, |
| 903 | target_classes, |
| 904 | i, |
| 905 | &target_class, |
| 906 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, |
| 907 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 908 | if (target_class_length > 0) { |
| 909 | switch (target_class[0]) { |
| 910 | case '+': |
| 911 | target_class++; |
| 912 | target_class_length--; |
| 913 | break; |
| 914 | case '-': |
| 915 | positive = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 916 | target_class++; |
| 917 | target_class_length--; |
| 918 | break; |
| 919 | default: |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | for (j = 0; j < n_classes; j++) { |
| 925 | const size_t class_length = class_lengths[j]; |
| 926 | |
| 927 | if (target_class_length == 0) { |
| 928 | is_target = positive; |
| 929 | matched = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 930 | break; |
| 931 | } |
| 932 | |
| 933 | if (!mecab_next_default_format_match_classcxx . . $ mecab_next_default_format_match_class(955ca4c3dbafa1a7).(ctx, |
| 934 | target_class, |
| 935 | target_class_length, |
| 936 | classes[j], |
| 937 | class_length)) { |
| 938 | break; |
| 939 | } |
| 940 | target_class += class_length; |
| 941 | target_class_length -= class_length; |
| 942 | if (target_class_length == 0) { |
| 943 | is_target = positive; |
| 944 | matched = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 945 | break; |
| 946 | } |
| 947 | if (target_class[0] != '/') { |
| 948 | break; |
| 949 | } |
| 950 | target_class++; |
| 951 | target_class_length--; |
| 952 | } |
| 953 | if (matched) { |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | if (is_target) { |
| 960 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = last_next; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | static void |
| 965 | mecab_next_default_formatcxx . . $ mecab_next_default_format(333236666ab8e12a).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 966 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer, |
| 967 | grn_tokencxx . . $ grn_token# *token) |
| 968 | { |
| 969 | const char *surface; |
| 970 | size_t surface_length = 0; |
| 971 | |
| 972 | surface_length = |
| 973 | mecab_next_default_format_consume_tokencxx . . $ mecab_next_default_format_consume_token(576fce732dfc23ae).(ctx, tokenizer, &surface); |
| 974 | if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->use_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_reading.) { |
| 975 | grn_objcxx . . $ grn_obj# *feature_locations = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 976 | const char *reading = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 977 | size_t reading_length; |
| 978 | reading_length = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 979 | feature_locations, |
| 980 | GRN_MECAB_FEATURE_LOCATION_READINGcxx . . $ GRN_MECAB_FEATURE_LOCATION_READING., |
| 981 | &reading); |
| 982 | if (reading_length > 0) { |
| 983 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, reading, (int)reading_length); |
| 984 | } else { |
| 985 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, surface, (int)surface_length); |
| 986 | } |
| 987 | } else if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->use_base_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#use_base_form.) { |
| 988 | grn_objcxx . . $ grn_obj# *feature_locations = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 989 | const char *base_form = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 990 | size_t base_form_length; |
| 991 | base_form_length = mecab_get_featurecxx . . $ mecab_get_feature(54a4ab7f248a8d73).(ctx, |
| 992 | feature_locations, |
| 993 | GRN_MECAB_FEATURE_LOCATION_BASE_FORMcxx . . $ GRN_MECAB_FEATURE_LOCATION_BASE_FORM., |
| 994 | &base_form); |
| 995 | if (base_form_length > 0) { |
| 996 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, base_form, (int)base_form_length); |
| 997 | } else { |
| 998 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, surface, (int)surface_length); |
| 999 | } |
| 1000 | } else { |
| 1001 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, surface, (int)surface_length); |
| 1002 | } |
| 1003 | if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->include_classcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_class.) { |
| 1004 | add_feature_datacxx . . $ add_feature_data# data; |
| 1005 | data.tokencxx . . $ $anonymous_type_bf99ff9bc20f8572_3#token. = token; |
| 1006 | data.feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_3#feature_locations. = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 1007 | data.ignore_empty_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_empty_value. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 1008 | data.ignore_asterisk_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_asterisk_value. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 1009 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1010 | &data, |
| 1011 | "class", |
| 1012 | GRN_MECAB_FEATURE_LOCATION_CLASScxx . . $ GRN_MECAB_FEATURE_LOCATION_CLASS.); |
| 1013 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1014 | &data, |
| 1015 | "subclass0", |
| 1016 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS0cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS0.); |
| 1017 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1018 | &data, |
| 1019 | "subclass1", |
| 1020 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS1cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS1.); |
| 1021 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1022 | &data, |
| 1023 | "subclass2", |
| 1024 | GRN_MECAB_FEATURE_LOCATION_SUBCLASS2cxx . . $ GRN_MECAB_FEATURE_LOCATION_SUBCLASS2.); |
| 1025 | } |
| 1026 | if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->include_readingcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_reading.) { |
| 1027 | add_feature_datacxx . . $ add_feature_data# data; |
| 1028 | data.tokencxx . . $ $anonymous_type_bf99ff9bc20f8572_3#token. = token; |
| 1029 | data.feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_3#feature_locations. = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 1030 | data.ignore_empty_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_empty_value. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 1031 | data.ignore_asterisk_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_asterisk_value. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 1032 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1033 | &data, |
| 1034 | "reading", |
| 1035 | GRN_MECAB_FEATURE_LOCATION_READINGcxx . . $ GRN_MECAB_FEATURE_LOCATION_READING.); |
| 1036 | } |
| 1037 | if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->include_formcxx . . $ $anonymous_type_bf99ff9bc20f8572_1#include_form.) { |
| 1038 | add_feature_datacxx . . $ add_feature_data# data; |
| 1039 | data.tokencxx . . $ $anonymous_type_bf99ff9bc20f8572_3#token. = token; |
| 1040 | data.feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_3#feature_locations. = &(tokenizer->feature_locationscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#feature_locations.); |
| 1041 | data.ignore_empty_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_empty_value. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 1042 | data.ignore_asterisk_valuecxx . . $ $anonymous_type_bf99ff9bc20f8572_3#ignore_asterisk_value. = truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!; |
| 1043 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, &data, "inflected_type", 4); |
| 1044 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, &data, "inflected_form", 5); |
| 1045 | mecab_next_default_format_add_featurecxx . . $ mecab_next_default_format_add_feature(8ea8c0d799e97da5).(ctx, |
| 1046 | &data, |
| 1047 | "base_form", |
| 1048 | GRN_MECAB_FEATURE_LOCATION_BASE_FORMcxx . . $ GRN_MECAB_FEATURE_LOCATION_BASE_FORM.); |
| 1049 | } |
| 1050 | { |
| 1051 | grn_tokenizer_statuscxx . . $ grn_tokenizer_status# status; |
| 1052 | if (surface_length == 0) { |
| 1053 | /* Error */ |
| 1054 | status = GRN_TOKEN_LASTcxx . . $ `include/groonga/token.h:82:9`!; |
| 1055 | } else { |
| 1056 | mecab_next_default_format_consume_needless_tokenscxx . . $ mecab_next_default_format_consume_needless_tokens(854c29834e16186a).(ctx, tokenizer); |
| 1057 | if (tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. == tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end.) { |
| 1058 | status = GRN_TOKEN_LASTcxx . . $ `include/groonga/token.h:82:9`!; |
| 1059 | } else { |
| 1060 | status = GRN_TOKEN_CONTINUEcxx . . $ `include/groonga/token.h:76:9`!; |
| 1061 | } |
| 1062 | } |
| 1063 | grn_token_set_statuscxx . . $ grn_token_set_status(ab0ad35a1c0de1a).(ctx, token, status); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | static void |
| 1068 | mecab_next_newline_formatcxx . . $ mecab_next_newline_format(333236666ab8e12a).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 1069 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer, |
| 1070 | grn_tokencxx . . $ grn_token# *token) |
| 1071 | { |
| 1072 | grn_encodingcxx . . $ grn_encoding# encoding = tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.->encodingcxx . . $ _grn_tokenizer_query_deprecated#encoding.; |
| 1073 | int cl; |
| 1074 | const char *p = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next., *r; |
| 1075 | const char *e = tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end.; |
| 1076 | grn_tokenizer_statuscxx . . $ grn_tokenizer_status# status; |
| 1077 | |
| 1078 | for (r = p; r < e; r += cl) { |
| 1079 | int space_len; |
| 1080 | |
| 1081 | space_len = grn_isspacecxx . . $ grn_isspace(f8f88a86d74aa1ba).(r, encoding); |
| 1082 | if (space_len > 0 && r == p) { |
| 1083 | cl = space_len; |
| 1084 | p = r + cl; |
| 1085 | continue; |
| 1086 | } |
| 1087 | |
| 1088 | if (!(cl = grn_charlen_cxx . . $ grn_charlen_(b4b53c9e31f93d3e).(ctx, r, e, encoding))) { |
| 1089 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = e; |
| 1090 | break; |
| 1091 | } |
| 1092 | |
| 1093 | if (cl == 1 && r[0] == '\n') { |
| 1094 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = r + cl; |
| 1095 | break; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | if (r == e || tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. == e) { |
| 1100 | status = GRN_TOKEN_LASTcxx . . $ `include/groonga/token.h:82:9`!; |
| 1101 | } else { |
| 1102 | status = GRN_TOKEN_CONTINUEcxx . . $ `include/groonga/token.h:76:9`!; |
| 1103 | } |
| 1104 | grn_token_set_datacxx . . $ grn_token_set_data(6ab8cb5e36c467ee).(ctx, token, p, (int)(r - p)); |
| 1105 | grn_token_set_statuscxx . . $ grn_token_set_status(ab0ad35a1c0de1a).(ctx, token, status); |
| 1106 | } |
| 1107 | |
| 1108 | static void |
| 1109 | grn_mecab_lattice_closecxx . . $ grn_mecab_lattice_close(b6b6153f622d9caa).(grn_ctxcxx . . $ grn_ctx# *ctx, void *data) |
| 1110 | { |
| 1111 | mecab_lattice_tcxx . . $ mecab_lattice_t# *lattice = data; |
| 1112 | mecab_lattice_destroycxx . . $ mecab_lattice_destroy(a1e4ed77b5a1fffe).(lattice); |
| 1113 | } |
| 1114 | |
| 1115 | /* |
| 1116 | This function is called for a full text search query or a document to be |
| 1117 | indexed. This means that both short/long strings are given. |
| 1118 | The return value of this function is ignored. When an error occurs in this |
| 1119 | function, `ctx->rc' is overwritten with an error code (not GRN_SUCCESS). |
| 1120 | */ |
| 1121 | static void * |
| 1122 | mecab_initcxx . . $ mecab_init(78928ddd02ab5cc6).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_tokenizer_querycxx . . $ grn_tokenizer_query# *query) |
| 1123 | { |
| 1124 | grn_objcxx . . $ grn_obj# *lexicon; |
| 1125 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer; |
| 1126 | |
| 1127 | lexicon = grn_tokenizer_query_get_lexiconcxx . . $ grn_tokenizer_query_get_lexicon(94bd48ba32a54cd8).(ctx, query); |
| 1128 | |
| 1129 | if (!(tokenizer = GRN_PLUGIN_MALLOCcxx . . $ `include/groonga/plugin.h:88:9`!(ctx, sizeof(grn_mecab_tokenizer)))) { |
| 1130 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 1131 | GRN_NO_MEMORY_AVAILABLE, |
| 1132 | "[tokenizer][mecab] " |
| 1133 | "memory allocation to grn_mecab_tokenizer failed"); |
| 1134 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1135 | } |
| 1136 | |
| 1137 | tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options. = |
| 1138 | grn_table_cache_default_tokenizer_optionscxx . . $ grn_table_cache_default_tokenizer_options(d2cf5c417953e151).(ctx, |
| 1139 | lexicon, |
| 1140 | mecab_tokenizer_options_opencxx . . $ mecab_tokenizer_options_open(935e2583f8354665)., |
| 1141 | mecab_tokenizer_options_closecxx . . $ mecab_tokenizer_options_close(b6b6153f622d9caa)., |
| 1142 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 1143 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 1144 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1145 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1146 | } |
| 1147 | |
| 1148 | mecab_init_mecabcxx . . $ mecab_init_mecab(854c29834e16186a).(ctx, tokenizer); |
| 1149 | if (!tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab.) { |
| 1150 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1151 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1152 | } |
| 1153 | tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice. = |
| 1154 | grn_ctx_get_variablecxx . . $ grn_ctx_get_variable(dac88c809d14bbd9).(ctx, grn_mecab_lattice_variable_namecxx . . $ grn_mecab_lattice_variable_name., -1); |
| 1155 | if (!tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.) { |
| 1156 | tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice. = mecab_model_new_latticecxx . . $ mecab_model_new_lattice(dccf9a60dce0cb44).(tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecab_modelcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab_model.); |
| 1157 | if (!tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.) { |
| 1158 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1159 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1160 | } |
| 1161 | grn_ctx_set_variablecxx . . $ grn_ctx_set_variable(509e39b87291b0ad).(ctx, |
| 1162 | grn_mecab_lattice_variable_namecxx . . $ grn_mecab_lattice_variable_name., |
| 1163 | -1, |
| 1164 | tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice., |
| 1165 | grn_mecab_lattice_closecxx . . $ grn_mecab_lattice_close(b6b6153f622d9caa).); |
| 1166 | } |
| 1167 | |
| 1168 | { |
| 1169 | grn_encodingcxx . . $ grn_encoding# encoding = grn_tokenizer_query_get_encodingcxx . . $ grn_tokenizer_query_get_encoding(beecbcfbc135f783).(ctx, query); |
| 1170 | if (encoding != tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->encodingcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#encoding.) { |
| 1171 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 1172 | GRN_TOKENIZER_ERROR, |
| 1173 | "[tokenizer][mecab] " |
| 1174 | "MeCab dictionary charset (%s) does not match " |
| 1175 | "the table encoding: <%s>", |
| 1176 | grn_encoding_to_string(tokenizer->mecab->encoding), |
| 1177 | grn_encoding_to_string(encoding)); |
| 1178 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1179 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query. = query; |
| 1184 | |
| 1185 | { |
| 1186 | grn_objcxx . . $ grn_obj# *string; |
| 1187 | const char *normalized_string; |
| 1188 | unsigned int normalized_string_length; |
| 1189 | |
| 1190 | string = grn_tokenizer_query_get_normalized_stringcxx . . $ grn_tokenizer_query_get_normalized_string(94bd48ba32a54cd8).(ctx, query); |
| 1191 | grn_string_get_normalizedcxx . . $ grn_string_get_normalized(fcb0da4d05783f05).(ctx, |
| 1192 | string, |
| 1193 | &normalized_string, |
| 1194 | &normalized_string_length, |
| 1195 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 1196 | GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(&(tokenizer->buf), 0); |
| 1197 | if (grn_tokenizer_query_have_tokenized_delimitercxx . . $ grn_tokenizer_query_have_tokenized_delimiter(625bd08e62b9d7d1).(ctx, query)) { |
| 1198 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = normalized_string; |
| 1199 | tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. + normalized_string_length; |
| 1200 | } else if (normalized_string_length == 0) { |
| 1201 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = ""; |
| 1202 | tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.; |
| 1203 | } else { |
| 1204 | if (tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.->chunked_tokenizecxx . . $ $anonymous_type_bf99ff9bc20f8572_1#chunked_tokenize. && |
| 1205 | ctx->encodingcxx . . $ _grn_ctx#encoding. == GRN_ENC_UTF8cxx . . $ GRN_ENC_UTF8.) { |
| 1206 | if (!chunked_tokenize_utf8cxx . . $ chunked_tokenize_utf8(7b348e27a4aaed1).(ctx, |
| 1207 | tokenizer, |
| 1208 | normalized_string, |
| 1209 | normalized_string_length)) { |
| 1210 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1211 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1212 | } |
| 1213 | } else { |
| 1214 | const char *s; |
| 1215 | mecab_lattice_set_sentence2cxx . . $ mecab_lattice_set_sentence2(c49493322a3b2d5d).(tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice., |
| 1216 | normalized_string, |
| 1217 | normalized_string_length); |
| 1218 | if (!mecab_parse_latticecxx . . $ mecab_parse_lattice(f11feb0fb0fd8f21).(tokenizer->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#mecab.->mecabcxx . . $ $anonymous_type_bf99ff9bc20f8572_0#mecab., tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.)) { |
| 1219 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 1220 | GRN_TOKENIZER_ERROR, |
| 1221 | "[tokenizer][mecab] " |
| 1222 | "mecab_parse_lattice() failed len=%d err=%s", |
| 1223 | normalized_string_length, |
| 1224 | mecab_lattice_strerror(tokenizer->lattice)); |
| 1225 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1226 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1227 | } |
| 1228 | s = mecab_lattice_tostrcxx . . $ mecab_lattice_tostr(f62beac619fbc2a).(tokenizer->latticecxx . . $ $anonymous_type_bf99ff9bc20f8572_2#lattice.); |
| 1229 | if (!s) { |
| 1230 | GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, |
| 1231 | GRN_TOKENIZER_ERROR, |
| 1232 | "[tokenizer][mecab] " |
| 1233 | "mecab_sparse_tostr() failed len=%d err=%s", |
| 1234 | normalized_string_length, |
| 1235 | mecab_lattice_strerror(tokenizer->lattice)); |
| 1236 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1237 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 1238 | } |
| 1239 | GRN_TEXT_PUTScxx . . $ `include/groonga/groonga.h:2781:9`!(ctx, &(tokenizer->buf), s); |
| 1240 | } |
| 1241 | if (mecab_tokenizer_options_need_default_outputcxx . . $ mecab_tokenizer_options_need_default_output(1386cf2ee849f0d4).(ctx, |
| 1242 | tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.)) { |
| 1243 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&(tokenizer->buf)); |
| 1244 | tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. = tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. + GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&(tokenizer->buf)); |
| 1245 | } else { |
| 1246 | char *buf, *p; |
| 1247 | size_t bufsize; |
| 1248 | |
| 1249 | buf = GRN_TEXT_VALUEcxx . . $ `include/groonga/groonga.h:2785:9`!(&(tokenizer->buf)); |
| 1250 | bufsize = GRN_TEXT_LENcxx . . $ `include/groonga/groonga.h:2786:9`!(&(tokenizer->buf)); |
| 1251 | /* A certain version of mecab returns trailing lf or spaces. */ |
| 1252 | for (p = buf + bufsize - 2; buf <= p && isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*(unsigned char *)p); |
| 1253 | p--) { |
| 1254 | *p = '\0'; |
| 1255 | } |
| 1256 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = buf; |
| 1257 | tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. = p + 1; |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | GRN_UINT64_INITcxx . . $ `include/groonga/groonga.h:2858:9`!(&(tokenizer->feature_locations), GRN_OBJ_VECTORcxx . . $ `include/groonga/groonga.h:2734:9`!); |
| 1263 | |
| 1264 | mecab_next_default_format_consume_needless_tokenscxx . . $ mecab_next_default_format_consume_needless_tokens(854c29834e16186a).(ctx, tokenizer); |
| 1265 | |
| 1266 | return tokenizer; |
| 1267 | } |
| 1268 | |
| 1269 | /* |
| 1270 | This function returns tokens one by one. |
| 1271 | */ |
| 1272 | static void |
| 1273 | mecab_nextcxx . . $ mecab_next(71a9f2a3a5ca0984).(grn_ctxcxx . . $ grn_ctx# *ctx, |
| 1274 | grn_tokenizer_querycxx . . $ grn_tokenizer_query# *query, |
| 1275 | grn_tokencxx . . $ grn_token# *token, |
| 1276 | void *user_data) |
| 1277 | { |
| 1278 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer = user_data; |
| 1279 | |
| 1280 | if (grn_tokenizer_query_have_tokenized_delimitercxx . . $ grn_tokenizer_query_have_tokenized_delimiter(625bd08e62b9d7d1).(ctx, tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.)) { |
| 1281 | grn_encodingcxx . . $ grn_encoding# encoding = tokenizer->querycxx . . $ $anonymous_type_bf99ff9bc20f8572_2#query.->encodingcxx . . $ _grn_tokenizer_query_deprecated#encoding.; |
| 1282 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next. = grn_tokenizer_next_by_tokenized_delimitercxx . . $ grn_tokenizer_next_by_tokenized_delimiter(eae71a273693c045).( |
| 1283 | ctx, |
| 1284 | token, |
| 1285 | tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next., |
| 1286 | (unsigned int)(tokenizer->endcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#end. - tokenizer->nextcxx . . $ $anonymous_type_bf99ff9bc20f8572_2#next.), |
| 1287 | encoding); |
| 1288 | } else if (mecab_tokenizer_options_need_default_outputcxx . . $ mecab_tokenizer_options_need_default_output(1386cf2ee849f0d4).(ctx, |
| 1289 | tokenizer->optionscxx . . $ $anonymous_type_bf99ff9bc20f8572_2#options.)) { |
| 1290 | mecab_next_default_formatcxx . . $ mecab_next_default_format(333236666ab8e12a).(ctx, tokenizer, token); |
| 1291 | } else { |
| 1292 | mecab_next_newline_formatcxx . . $ mecab_next_newline_format(333236666ab8e12a).(ctx, tokenizer, token); |
| 1293 | } |
| 1294 | } |
| 1295 | |
| 1296 | /* |
| 1297 | This function finalizes a tokenization. |
| 1298 | */ |
| 1299 | static void |
| 1300 | mecab_fincxx . . $ mecab_fin(b6b6153f622d9caa).(grn_ctxcxx . . $ grn_ctx# *ctx, void *user_data) |
| 1301 | { |
| 1302 | grn_mecab_tokenizercxx . . $ grn_mecab_tokenizer# *tokenizer = user_data; |
| 1303 | if (!tokenizer) { |
| 1304 | return; |
| 1305 | } |
| 1306 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(tokenizer->feature_locations)); |
| 1307 | GRN_OBJ_FINcxx . . $ `include/groonga/groonga.h:958:9`!(ctx, &(tokenizer->buf)); |
| 1308 | GRN_PLUGIN_FREEcxx . . $ `include/groonga/plugin.h:100:9`!(ctx, tokenizer); |
| 1309 | } |
| 1310 | |
| 1311 | static void |
| 1312 | check_mecab_dictionary_encodingcxx . . $ check_mecab_dictionary_encoding(b578cd6e53d5fe91).(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 1313 | { |
| 1314 | #ifdef HAVE_MECAB_DICTIONARY_INFO_T |
| 1315 | mecab_model_t *mecab_model; |
| 1316 | mecab_t *mecab; |
| 1317 | grn_encoding encoding; |
| 1318 | bool have_same_encoding_dictionary; |
| 1319 | |
| 1320 | mecab_model = mecab_model_create(ctx, NULL); |
| 1321 | if (!mecab_model) { |
| 1322 | return; |
| 1323 | } |
| 1324 | mecab = mecab_model_new_tagger(mecab_model); |
| 1325 | if (!mecab) { |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | encoding = GRN_CTX_GET_ENCODING(ctx); |
| 1330 | have_same_encoding_dictionary = (encoding == get_mecab_encoding(mecab)); |
| 1331 | mecab_destroy(mecab); |
| 1332 | |
| 1333 | if (!have_same_encoding_dictionary) { |
| 1334 | GRN_PLUGIN_ERROR(ctx, |
| 1335 | GRN_TOKENIZER_ERROR, |
| 1336 | "[tokenizer][mecab] " |
| 1337 | "MeCab has no dictionary that uses the context encoding" |
| 1338 | ": <%s>", |
| 1339 | grn_encoding_to_string(encoding)); |
| 1340 | } |
| 1341 | #endif |
| 1342 | } |
| 1343 | |
| 1344 | /* |
| 1345 | This function initializes a plugin. This function fails if there is no |
| 1346 | dictionary that uses the context encoding of groonga. |
| 1347 | */ |
| 1348 | grn_rccxx . . $ grn_rc# |
| 1349 | GRN_PLUGIN_INITcxx . . $ `include/groonga/plugin.h:43:9`!(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 1350 | { |
| 1351 | { |
| 1352 | char env[GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!]; |
| 1353 | |
| 1354 | grn_getenvcxx . . $ `include/groonga/portability.h:58:11`!("GRN_MECAB_CHUNKED_TOKENIZE_ENABLED", env, GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!); |
| 1355 | grn_mecab_chunked_tokenize_enabledcxx . . $ grn_mecab_chunked_tokenize_enabled. = (env[0] && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(env, "yes") == 0); |
| 1356 | } |
| 1357 | |
| 1358 | { |
| 1359 | char env[GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!]; |
| 1360 | |
| 1361 | grn_getenvcxx . . $ `include/groonga/portability.h:58:11`!("GRN_MECAB_CHUNK_SIZE_THRESHOLD", env, GRN_ENV_BUFFER_SIZEcxx . . $ `include/groonga/portability.h:42:9`!); |
| 1362 | if (env[0]) { |
| 1363 | int threshold = -1; |
| 1364 | const char *end; |
| 1365 | const char *rest; |
| 1366 | |
| 1367 | end = env + strlencxx . . $ strlen(751346f8406fd082).(env); |
| 1368 | threshold = grn_atoicxx . . $ grn_atoi(adf3ff2c2b114929).(env, end, &rest); |
| 1369 | if (end > env && end == rest) { |
| 1370 | grn_mecab_chunk_size_thresholdcxx . . $ grn_mecab_chunk_size_threshold. = threshold; |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | grn_mecab_initcxx . . $ grn_mecab_init(44ab20ba312e6462).(ctx, &mecab_defaultcxx . . $ mecab_default., "[default]"); |
| 1376 | grn_mecab_initcxx . . $ grn_mecab_init(44ab20ba312e6462).(ctx, &mecab_newlinecxx . . $ mecab_newline., "[newline]"); |
| 1377 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 1378 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1379 | } |
| 1380 | |
| 1381 | check_mecab_dictionary_encodingcxx . . $ check_mecab_dictionary_encoding(b578cd6e53d5fe91).(ctx); |
| 1382 | if (ctx->rccxx . . $ _grn_ctx#rc. != GRN_SUCCESScxx . . $ GRN_SUCCESS.) { |
| 1383 | grn_mecab_fincxx . . $ grn_mecab_fin(2579465d0ca1a570).(ctx, &mecab_defaultcxx . . $ mecab_default.); |
| 1384 | grn_mecab_fincxx . . $ grn_mecab_fin(2579465d0ca1a570).(ctx, &mecab_newlinecxx . . $ mecab_newline.); |
| 1385 | } |
| 1386 | |
| 1387 | return ctx->rccxx . . $ _grn_ctx#rc.; |
| 1388 | } |
| 1389 | |
| 1390 | /* |
| 1391 | This function registers a plugin to a database. |
| 1392 | */ |
| 1393 | grn_rccxx . . $ grn_rc# |
| 1394 | GRN_PLUGIN_REGISTERcxx . . $ `include/groonga/plugin.h:44:9`!(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 1395 | { |
| 1396 | grn_rccxx . . $ grn_rc# rc = GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1397 | grn_objcxx . . $ grn_obj# *tokenizer; |
| 1398 | |
| 1399 | tokenizer = grn_tokenizer_createcxx . . $ grn_tokenizer_create(70fde0087014f9ea).(ctx, "TokenMecab", -1); |
| 1400 | if (tokenizer) { |
| 1401 | grn_tokenizer_set_init_funccxx . . $ grn_tokenizer_set_init_func(9b546f012584c62c).(ctx, tokenizer, mecab_initcxx . . $ mecab_init(78928ddd02ab5cc6).); |
| 1402 | grn_tokenizer_set_next_funccxx . . $ grn_tokenizer_set_next_func(274c55b60b47101c).(ctx, tokenizer, mecab_nextcxx . . $ mecab_next(71a9f2a3a5ca0984).); |
| 1403 | grn_tokenizer_set_fin_funccxx . . $ grn_tokenizer_set_fin_func(638e0fa4e92f09de).(ctx, tokenizer, mecab_fincxx . . $ mecab_fin(b6b6153f622d9caa).); |
| 1404 | |
| 1405 | /* Just for backward compatibility. TokenMecab was built-in not plugin. */ |
| 1406 | if (grn_obj_idcxx . . $ grn_obj_id(8dd58acc9865e889).(ctx, tokenizer) != GRN_DB_MECABcxx . . $ GRN_DB_MECAB.) { |
| 1407 | rc = GRN_FILE_CORRUPTcxx . . $ GRN_FILE_CORRUPT.; |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | return rc; |
| 1412 | } |
| 1413 | |
| 1414 | /* |
| 1415 | This function finalizes a plugin. |
| 1416 | */ |
| 1417 | grn_rccxx . . $ grn_rc# |
| 1418 | GRN_PLUGIN_FINcxx . . $ `include/groonga/plugin.h:45:9`!(grn_ctxcxx . . $ grn_ctx# *ctx) |
| 1419 | { |
| 1420 | grn_unset_variablecxx . . $ grn_unset_variable(5bc5b8d591c99f8c).(grn_mecab_lattice_variable_namecxx . . $ grn_mecab_lattice_variable_name., -1); |
| 1421 | |
| 1422 | grn_mecab_fincxx . . $ grn_mecab_fin(2579465d0ca1a570).(ctx, &mecab_defaultcxx . . $ mecab_default.); |
| 1423 | grn_mecab_fincxx . . $ grn_mecab_fin(2579465d0ca1a570).(ctx, &mecab_newlinecxx . . $ mecab_newline.); |
| 1424 | |
| 1425 | return GRN_SUCCESScxx . . $ GRN_SUCCESS.; |
| 1426 | } |