Debian Codegraph @

lib/scorer.c

raw symbols SCIP
1 /*
2 Copyright(C) 2015-2018 Brazil
3 Copyright(C) 2020-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 #include <string.h>
21
22 #include "grn.h"cxx . . $ `<file>/lib/grn.h`/
23 #include "grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
24 #include "grn_expr.h"cxx . . $ `<file>/lib/grn_expr.h`/
25 #include "grn_scorer.h"cxx . . $ `<file>/lib/grn_scorer.h`/
26 #include <groonga/scorer.h>cxx . . $ `<file>/include/groonga/scorer.h`/
27
28 grn_objcxx . . $ grn_obj# *
29 grn_scorer_matched_record_get_tablecxx . . $ grn_scorer_matched_record_get_table(ede473f0f9e1857f).(grn_ctxcxx . . $ grn_ctx# *ctx,
30 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
31 {
32 return record->tablecxx . . $ _grn_scorer_matched_record#table.;
33 }
34
35 grn_objcxx . . $ grn_obj# *
36 grn_scorer_matched_record_get_lexiconcxx . . $ grn_scorer_matched_record_get_lexicon(ede473f0f9e1857f).(grn_ctxcxx . . $ grn_ctx# *ctx,
37 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
38 {
39 return record->lexiconcxx . . $ _grn_scorer_matched_record#lexicon.;
40 }
41
42 grn_idcxx . . $ grn_id#
43 grn_scorer_matched_record_get_idcxx . . $ grn_scorer_matched_record_get_id(b7b640a8991c71b0).(grn_ctxcxx . . $ grn_ctx# *ctx,
44 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
45 {
46 return record->idcxx . . $ _grn_scorer_matched_record#id.;
47 }
48
49 grn_objcxx . . $ grn_obj# *
50 grn_scorer_matched_record_get_termscxx . . $ grn_scorer_matched_record_get_terms(ede473f0f9e1857f).(grn_ctxcxx . . $ grn_ctx# *ctx,
51 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
52 {
53 return &(record->termscxx . . $ _grn_scorer_matched_record#terms.);
54 }
55
56 grn_objcxx . . $ grn_obj# *
57 grn_scorer_matched_record_get_term_weightscxx . . $ grn_scorer_matched_record_get_term_weights(ede473f0f9e1857f).(grn_ctxcxx . . $ grn_ctx# *ctx,
58 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
59 {
60 return &(record->term_weightscxx . . $ _grn_scorer_matched_record#term_weights.);
61 }
62
63 uint32_tcxx . . $ uint32_t#
64 grn_scorer_matched_record_get_total_term_weightscxx . . $ grn_scorer_matched_record_get_total_term_weights(b7b640a8991c71b0).(grn_ctxcxx . . $ grn_ctx# *ctx,
65 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
66 {
67 return record->total_term_weightscxx . . $ _grn_scorer_matched_record#total_term_weights.;
68 }
69
70 uint64_tcxx . . $ uint64_t#
71 grn_scorer_matched_record_get_n_documentscxx . . $ grn_scorer_matched_record_get_n_documents(876307874c9a6fa3).(grn_ctxcxx . . $ grn_ctx# *ctx,
72 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
73 {
74 return record->n_documentscxx . . $ _grn_scorer_matched_record#n_documents.;
75 }
76
77 uint32_tcxx . . $ uint32_t#
78 grn_scorer_matched_record_get_n_occurrencescxx . . $ grn_scorer_matched_record_get_n_occurrences(b7b640a8991c71b0).(grn_ctxcxx . . $ grn_ctx# *ctx,
79 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
80 {
81 return record->n_occurrencescxx . . $ _grn_scorer_matched_record#n_occurrences.;
82 }
83
84 uint64_tcxx . . $ uint64_t#
85 grn_scorer_matched_record_get_n_candidatescxx . . $ grn_scorer_matched_record_get_n_candidates(876307874c9a6fa3).(grn_ctxcxx . . $ grn_ctx# *ctx,
86 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
87 {
88 return record->n_candidatescxx . . $ _grn_scorer_matched_record#n_candidates.;
89 }
90
91 uint32_tcxx . . $ uint32_t#
92 grn_scorer_matched_record_get_n_tokenscxx . . $ grn_scorer_matched_record_get_n_tokens(b7b640a8991c71b0).(grn_ctxcxx . . $ grn_ctx# *ctx,
93 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
94 {
95 return record->n_tokenscxx . . $ _grn_scorer_matched_record#n_tokens.;
96 }
97
98 int
99 grn_scorer_matched_record_get_weightcxx . . $ grn_scorer_matched_record_get_weight(a9e2f444052d110d).(grn_ctxcxx . . $ grn_ctx# *ctx,
100 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
101 {
102 return record->weightcxx . . $ _grn_scorer_matched_record#weight.;
103 }
104
105 grn_objcxx . . $ grn_obj# *
106 grn_scorer_matched_record_get_argcxx . . $ grn_scorer_matched_record_get_arg(5a582bc68c143fb5).(grn_ctxcxx . . $ grn_ctx# *ctx,
107 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record,
108 unsigned int i)
109 {
110 grn_exprcxx . . $ grn_expr# *expr;
111 grn_expr_codecxx . . $ grn_expr_code# *codes_original;
112 uint32_tcxx . . $ uint32_t# codes_curr_original;
113 grn_objcxx . . $ grn_obj# *arg;
114
115 if (!record->args_exprcxx . . $ _grn_scorer_matched_record#args_expr.) {
116 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
117 }
118
119 expr = (grn_exprcxx . . $ grn_expr# *)(record->args_exprcxx . . $ _grn_scorer_matched_record#args_expr.);
120 /* TODO: support getting column value */
121 codes_original = expr->codescxx . . $ _grn_expr#codes.;
122 codes_curr_original = expr->codes_currcxx . . $ _grn_expr#codes_curr.;
123 expr->codescxx . . $ _grn_expr#codes. += record->args_expr_offsetcxx . . $ _grn_scorer_matched_record#args_expr_offset.;
124 expr->codes_currcxx . . $ _grn_expr#codes_curr. = 1; /* TODO: support 1 or more codes */
125 arg = grn_expr_execcxx . . $ grn_expr_exec(e5f715bd58cd6451).(ctx, (grn_objcxx . . $ grn_obj# *)expr, 0);
126 expr->codes_currcxx . . $ _grn_expr#codes_curr. = codes_curr_original;
127 expr->codescxx . . $ _grn_expr#codes. = codes_original;
128
129 return arg;
130 }
131
132 unsigned int
133 grn_scorer_matched_record_get_n_argscxx . . $ grn_scorer_matched_record_get_n_args(b7b640a8991c71b0).(grn_ctxcxx . . $ grn_ctx# *ctx,
134 grn_scorer_matched_recordcxx . . $ grn_scorer_matched_record# *record)
135 {
136 grn_exprcxx . . $ grn_expr# *expr;
137 grn_expr_codecxx . . $ grn_expr_code# *codes;
138 unsigned int n_args = 0;
139
140 if (!record->args_exprcxx . . $ _grn_scorer_matched_record#args_expr.) {
141 return 0;
142 }
143
144 expr = (grn_exprcxx . . $ grn_expr# *)(record->args_exprcxx . . $ _grn_scorer_matched_record#args_expr.);
145 codes = expr->codescxx . . $ _grn_expr#codes. + record->args_expr_offsetcxx . . $ _grn_scorer_matched_record#args_expr_offset.;
146 if (codes[0].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. == GRN_OP_CALLcxx . . $ GRN_OP_CALL.) {
147 return 0;
148 }
149
150 n_args++;
151 for (; codes[0].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. != GRN_OP_CALLcxx . . $ GRN_OP_CALL.; codes++) {
152 if (codes[0].opcxx . . $ $anonymous_type_640a68f6a3c9e981_0#op. == GRN_OP_COMMAcxx . . $ GRN_OP_COMMA.) {
153 n_args++;
154 }
155 }
156
157 return n_args;
158 }
159
160 grn_rccxx . . $ grn_rc#
161 grn_scorer_registercxx . . $ grn_scorer_register(e334657bb5aaacf).(grn_ctxcxx . . $ grn_ctx# *ctx,
162 const char *scorer_name_ptr,
163 int scorer_name_length,
164 grn_scorer_score_funccxx . . $ grn_scorer_score_func# *score)
165 {
166 if (scorer_name_length == -1) {
167 scorer_name_length = (int)strlencxx . . $ strlen(751346f8406fd082).(scorer_name_ptr);
168 }
169
170 {
171 grn_objcxx . . $ grn_obj# *scorer_object = grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx,
172 scorer_name_ptr,
173 scorer_name_length,
174 GRN_PROC_SCORERcxx . . $ GRN_PROC_SCORER.,
175 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
176 if (scorer_object == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
177 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_SCORER_ERROR,
178 "[scorer][%.*s] failed to grn_proc_create()",
179 scorer_name_length, scorer_name_ptr);
180 return ctx->rccxx . . $ _grn_ctx#rc.;
181 }
182
183 {
184 grn_proccxx . . $ grn_proc# *scorer = (grn_proccxx . . $ grn_proc# *)scorer_object;
185 scorer->callbackscxx . . $ _grn_proc#callbacks..scorercxx . . $ _grn_proc#$anonymous_type_5#scorer..scorecxx . . $ _grn_proc#$anonymous_type_5#$anonymous_type_10#score. = score;
186 }
187 }
188
189 return GRN_SUCCESScxx . . $ GRN_SUCCESS.;
190 }