source: trunk/gsdl/packages/yaz/zutil/logrpn.c@ 1343

Last change on this file since 1343 was 1343, checked in by johnmcp, 24 years ago

Added the YAZ toolkit source to the packages directory (for z39.50 stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
RevLine 
[1343]1/*
2 * Copyright (C) 1995-2000, Index Data
3 * All rights reserved.
4 * Sebastian Hammer, Adam Dickmeiss
5 *
6 * $Log$
7 * Revision 1.1 2000/08/03 03:12:36 johnmcp
8 * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
9 *
10 * Revision 1.4 2000/01/31 13:15:22 adam
11 * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
12 * that some characters are not surrounded by spaces in resulting term.
13 * ILL-code updates.
14 *
15 * Revision 1.3 1999/11/30 13:47:12 adam
16 * Improved installation. Moved header files to include/yaz.
17 *
18 * Revision 1.2 1999/08/27 09:40:33 adam
19 * Renamed logf function to yaz_log. Removed VC++ project files.
20 *
21 * Revision 1.1 1999/06/08 10:10:16 adam
22 * New sub directory zutil. Moved YAZ Compiler to be part of YAZ tree.
23 *
24 * Revision 1.1 1998/11/16 16:02:35 adam
25 * Added loggin utilies, log_rpn_query and log_scan_term. These used
26 * to be part of Zebra.
27 *
28 *
29 *
30 * Old logs from zlogs.c:
31 *
32 * Revision 1.9 1998/10/13 20:36:02 adam
33 * Changed "indent" format string in log messages.
34 *
35 * Revision 1.8 1998/04/02 14:35:29 adam
36 * First version of Zebra that works with compiled ASN.1.
37 *
38 * Revision 1.7 1998/01/29 13:40:11 adam
39 * Better logging for scan service.
40 *
41 * Revision 1.6 1997/09/29 09:06:41 adam
42 * Removed static var to make this module thread safe.
43 *
44 * Revision 1.5 1997/04/30 08:56:07 quinn
45 * null
46 *
47 * Revision 1.4 1996/10/08 09:41:25 quinn
48 * Fixed diagnostic.
49 *
50 * Revision 1.3 1996/03/20 09:36:40 adam
51 * Function dict_lookup_grep got extra parameter, init_pos, which marks
52 * from which position in pattern approximate pattern matching should occur.
53 * Approximate pattern matching is used in relevance=re-2.
54 *
55 * Revision 1.2 1996/01/03 16:22:11 quinn
56 * operator->roperator
57 *
58 * Revision 1.1 1995/11/16 17:00:55 adam
59 * Better logging of rpn query.
60 *
61 */
62#include <stdio.h>
63
64#include <yaz/log.h>
65#include <yaz/logrpn.h>
66
67static void attrStr (int type, int value, enum oid_value ast, char *str)
68{
69 *str = '\0';
70 switch (ast)
71 {
72 case VAL_BIB1:
73 case VAL_EXP1:
74 case VAL_GILS:
75 switch (type)
76 {
77 case 1:
78 sprintf (str, "use");
79 break;
80 case 2:
81 switch (value)
82 {
83 case 1:
84 sprintf (str, "relation=Less than");
85 break;
86 case 2:
87 sprintf (str, "relation=Less than or equal");
88 break;
89 case 3:
90 sprintf (str, "relation=Equal");
91 break;
92 case 4:
93 sprintf (str, "relation=Greater or equal");
94 break;
95 case 5:
96 sprintf (str, "relation=Greater than");
97 break;
98 case 6:
99 sprintf (str, "relation=Not equal");
100 break;
101 case 100:
102 sprintf (str, "relation=Phonetic");
103 break;
104 case 101:
105 sprintf (str, "relation=Stem");
106 break;
107 case 102:
108 sprintf (str, "relation=Relevance");
109 break;
110 case 103:
111 sprintf (str, "relation=AlwaysMatches");
112 break;
113 default:
114 sprintf (str, "relation");
115 }
116 break;
117 case 3:
118 switch (value)
119 {
120 case 1:
121 sprintf (str, "position=First in field");
122 break;
123 case 2:
124 sprintf (str, "position=First in any subfield");
125 break;
126 case 3:
127 sprintf (str, "position=Any position in field");
128 break;
129 default:
130 sprintf (str, "position");
131 }
132 break;
133 case 4:
134 switch (value)
135 {
136 case 1:
137 sprintf (str, "structure=Phrase");
138 break;
139 case 2:
140 sprintf (str, "structure=Word");
141 break;
142 case 3:
143 sprintf (str, "structure=Key");
144 break;
145 case 4:
146 sprintf (str, "structure=Year");
147 break;
148 case 5:
149 sprintf (str, "structure=Date");
150 break;
151 case 6:
152 sprintf (str, "structure=Word list");
153 break;
154 case 100:
155 sprintf (str, "structure=Date (un)");
156 break;
157 case 101:
158 sprintf (str, "structure=Name (norm)");
159 break;
160 case 102:
161 sprintf (str, "structure=Name (un)");
162 break;
163 case 103:
164 sprintf (str, "structure=Structure");
165 break;
166 case 104:
167 sprintf (str, "structure=urx");
168 break;
169 case 105:
170 sprintf (str, "structure=free-form-text");
171 break;
172 case 106:
173 sprintf (str, "structure=document-text");
174 break;
175 case 107:
176 sprintf (str, "structure=local-number");
177 break;
178 case 108:
179 sprintf (str, "structure=string");
180 break;
181 case 109:
182 sprintf (str, "structure=numeric string");
183 break;
184 default:
185 sprintf (str, "structure");
186 }
187 break;
188 case 5:
189 switch (value)
190 {
191 case 1:
192 sprintf (str, "truncation=Right");
193 break;
194 case 2:
195 sprintf (str, "truncation=Left");
196 break;
197 case 3:
198 sprintf (str, "truncation=Left&right");
199 break;
200 case 100:
201 sprintf (str, "truncation=Do not truncate");
202 break;
203 case 101:
204 sprintf (str, "truncation=Process #");
205 break;
206 case 102:
207 sprintf (str, "truncation=re-1");
208 break;
209 case 103:
210 sprintf (str, "truncation=re-2");
211 break;
212 default:
213 sprintf (str, "truncation");
214 }
215 break;
216 case 6:
217 switch (value)
218 {
219 case 1:
220 sprintf (str, "completeness=Incomplete subfield");
221 break;
222 case 2:
223 sprintf (str, "completeness=Complete subfield");
224 break;
225 case 3:
226 sprintf (str, "completeness=Complete field");
227 break;
228 default:
229 sprintf (str, "completeness");
230 }
231 break;
232 }
233 break;
234 default:
235 break;
236 }
237 if (*str)
238 sprintf (str + strlen(str), " (%d=%d)", type, value);
239 else
240 sprintf (str, "%d=%d", type, value);
241}
242
243/*
244 * zlog_attributes: print attributes of term
245 */
246static void zlog_attributes (Z_AttributesPlusTerm *t, int level,
247 enum oid_value ast)
248{
249 int of, i;
250 char str[80];
251#ifdef ASN_COMPILED
252 int num_attributes = t->attributes->num_attributes;
253#else
254 int num_attributes = t->num_attributes;
255#endif
256
257 for (of = 0; of < num_attributes; of++)
258 {
259 const char *attset_name = "";
260 Z_AttributeElement *element;
261#ifdef ASN_COMPILED
262 element = t->attributes->attributes[of];
263#else
264 element = t->attributeList[of];
265#endif
266 if (element->attributeSet)
267 {
268 oident *attrset;
269 attrset = oid_getentbyoid (element->attributeSet);
270 attset_name = attrset->desc;
271 }
272 switch (element->which)
273 {
274 case Z_AttributeValue_numeric:
275 attrStr (*element->attributeType,
276 *element->value.numeric, ast, str);
277 yaz_log (LOG_LOG, "%*.0s%s %s", level, "", attset_name, str);
278 break;
279 case Z_AttributeValue_complex:
280 yaz_log (LOG_LOG, "%*.0s%s attributeType=%d complex",
281 level, "", attset_name, *element->attributeType);
282 for (i = 0; i<element->value.complex->num_list; i++)
283 {
284 if (element->value.complex->list[i]->which ==
285 Z_StringOrNumeric_string)
286 yaz_log (LOG_LOG, "%*.0s string: '%s'", level, "",
287 element->value.complex->list[i]->u.string);
288 else if (element->value.complex->list[i]->which ==
289 Z_StringOrNumeric_numeric)
290 yaz_log (LOG_LOG, "%*.0s numeric: '%d'", level, "",
291 *element->value.complex->list[i]->u.numeric);
292 }
293 break;
294 default:
295 yaz_log (LOG_LOG, "%.*s%s attribute unknown",
296 level, "", attset_name);
297 }
298 }
299}
300
301static void zlog_structure (Z_RPNStructure *zs, int level, enum oid_value ast)
302{
303 if (zs->which == Z_RPNStructure_complex)
304 {
305 switch (zs->u.complex->roperator->which)
306 {
307 case Z_Operator_and:
308 yaz_log (LOG_LOG, "%*.0s and", level, "");
309 break;
310 case Z_Operator_or:
311 yaz_log (LOG_LOG, "%*.0s or", level, "");
312 break;
313 case Z_Operator_and_not:
314 yaz_log (LOG_LOG, "%*.0s and-not", level, "");
315 break;
316 default:
317 yaz_log (LOG_LOG, "%*.0s unknown complex", level, "");
318 return;
319 }
320 zlog_structure (zs->u.complex->s1, level+2, ast);
321 zlog_structure (zs->u.complex->s2, level+2, ast);
322 }
323 else if (zs->which == Z_RPNStructure_simple)
324 {
325 if (zs->u.simple->which == Z_Operand_APT)
326 {
327 Z_AttributesPlusTerm *zapt = zs->u.simple->u.attributesPlusTerm;
328
329 if (zapt->term->which == Z_Term_general)
330 {
331 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
332 zapt->term->u.general->len,
333 zapt->term->u.general->buf);
334 }
335 else
336 {
337 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
338 }
339 zlog_attributes (zapt, level+2, ast);
340 }
341 else if (zs->u.simple->which == Z_Operand_resultSetId)
342 {
343 yaz_log (LOG_LOG, "%*.0s set '%s'", level, "",
344 zs->u.simple->u.resultSetId);
345 }
346 else
347 yaz_log (LOG_LOG, "%*.0s unknown simple structure", level, "");
348 }
349 else
350 yaz_log (LOG_LOG, "%*.0s unknown structure", level, "");
351}
352
353void log_rpn_query (Z_RPNQuery *rpn)
354{
355 oident *attrset;
356 enum oid_value ast;
357
358 attrset = oid_getentbyoid (rpn->attributeSetId);
359 if (attrset)
360 {
361 ast = attrset->value;
362 yaz_log (LOG_LOG, "RPN query. Type: %s", attrset->desc);
363 }
364 else
365 {
366 ast = VAL_NONE;
367 yaz_log (LOG_LOG, "RPN query. Unknown type");
368 }
369 zlog_structure (rpn->RPNStructure, 0, ast);
370}
371
372void log_scan_term (Z_AttributesPlusTerm *zapt, oid_value ast)
373{
374 int level = 0;
375 if (zapt->term->which == Z_Term_general)
376 {
377 yaz_log (LOG_LOG, "%*.0s term '%.*s' (general)", level, "",
378 zapt->term->u.general->len, zapt->term->u.general->buf);
379 }
380 else
381 yaz_log (LOG_LOG, "%*.0s term (not general)", level, "");
382 zlog_attributes (zapt, level+2, ast);
383}
Note: See TracBrowser for help on using the repository browser.