2 * Copyright (C) 1994-1997, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.3 1997-11-17 15:35:26 adam
8 * Bug fix. Relation=relevance wasn't observed.
10 * Revision 1.2 1997/10/31 12:39:30 adam
11 * Changed log message.
13 * Revision 1.1 1997/10/27 14:33:06 adam
14 * Moved towards generic character mapping depending on "structure"
15 * field in abstract syntax file. Fixed a few memory leaks. Fixed
16 * bug with negative integers when doing searches with relational
31 struct zebra_map *next;
37 struct zebra_map *map_list;
40 void zebra_maps_close (ZebraMaps zms)
42 struct zebra_map *zm = zms->map_list;
45 struct zebra_map *zm_next = zm->next;
47 chrmaptab_destroy (zm->maptab);
51 nmem_destroy (zms->nmem);
55 ZebraMaps zebra_maps_open (const char *tabpath)
57 ZebraMaps zms = xmalloc (sizeof(*zms));
59 zms->nmem = nmem_create ();
60 zms->tabpath = nmem_strdup (zms->nmem, tabpath);
65 chrmaptab zebra_map_get (ZebraMaps zms, int reg_type)
70 for (zm = zms->map_list; zm; zm = zm->next)
72 if (reg_type == zm->reg_type)
80 strcat (name, "string");
83 strcat (name, "numeric");
89 strcat (name, "null");
91 strcat (name, ".chr");
93 zm = xmalloc (sizeof(*zm));
94 zm->reg_type = reg_type;
95 zm->next = zms->map_list;
97 if (!(zm->maptab = chrmaptab_create (zms->tabpath, name, 0)))
98 logf(LOG_WARN, "Failed to read character table %s", name);
100 logf(LOG_DEBUG, "Read character table %s", name);
104 const char **zebra_maps_input (ZebraMaps zms, int reg_type,
105 const char **from, int len)
107 static char str[2] = {0,0};
108 static const char *buf[2] = {0,0};
111 maptab = zebra_map_get (zms, reg_type);
113 return chr_map_input(maptab, from, len);
117 str[0] = isupper(**from) ? tolower(**from) : **from;
121 buf[0] = (char*) CHR_SPACE;
126 const char *zebra_maps_output(ZebraMaps zms, int reg_type, const char **from)
129 unsigned char i = (unsigned char) **from;
130 static char buf[2] = {0,0};
132 maptab = zebra_map_get (zms, reg_type);
134 return chr_map_output (maptab, from, 1);
141 /* ------------------------------------ */
147 Z_AttributesPlusTerm *zapt;
150 static int attr_find (AttrType *src, oid_value *attributeSetP)
152 while (src->major < src->zapt->num_attributes)
154 Z_AttributeElement *element;
156 element = src->zapt->attributeList[src->major];
157 if (src->type == *element->attributeType)
159 switch (element->which)
161 case Z_AttributeValue_numeric:
163 if (element->attributeSet && attributeSetP)
167 attrset = oid_getentbyoid (element->attributeSet);
168 *attributeSetP = attrset->value;
170 return *element->value.numeric;
172 case Z_AttributeValue_complex:
173 if (src->minor >= element->value.complex->num_list ||
174 element->value.complex->list[src->minor]->which !=
175 Z_StringOrNumeric_numeric)
178 if (element->attributeSet && attributeSetP)
182 attrset = oid_getentbyoid (element->attributeSet);
183 *attributeSetP = attrset->value;
185 return *element->value.complex->list[src->minor-1]->u.numeric;
195 static void attr_init (AttrType *src, Z_AttributesPlusTerm *zapt,
204 /* ------------------------------------ */
206 int zebra_maps_is_complete (ZebraMaps zms, int reg_type)
213 int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt,
214 int *reg_type, char **search_type, int *complete_flag)
216 AttrType completeness;
219 int completeness_value;
223 attr_init (&structure, zapt, 4);
224 attr_init (&completeness, zapt, 6);
225 attr_init (&relation, zapt, 2);
227 completeness_value = attr_find (&completeness, NULL);
228 structure_value = attr_find (&structure, NULL);
229 relation_value = attr_find (&relation, NULL);
231 if (completeness_value == 2 || completeness_value == 3)
237 *search_type = "phrase";
238 if (relation_value == 102)
239 *search_type = "ranked";
241 switch (structure_value)
247 case 6: /* word list */
248 case 105: /* free-form-text */
249 case 106: /* document-text */
250 case 108: /* string */
256 case 107: /* local-number */
257 *search_type = "local";
259 case 109: /* numeric string */