1 /* $Id: test_relevance.c,v 1.3 2007-04-19 11:57:53 marc Exp $
2 Copyright (c) 2006-2007, Index Data.
4 This file is part of Pazpar2.
6 Pazpar2 is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with Pazpar2; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include <sys/socket.h>
39 #include <yaz/timing.h>
45 //#include "pazpar2.h"
46 #include "relevance.h"
55 void test_relevance(int argc, char **argv)
57 NMEM nmem = nmem_create();
60 const char * queryterms[] =
62 // {"ål", "økologi", "æble", 0};
64 struct record_cluster *cluster = 0;
65 struct conf_service *service = 0;
66 struct reclist *list = 0;
67 struct record *record = 0;
68 const char *mergekey = "amergekey";
71 struct relevance *rel = 0;
73 rel = relevance_create(nmem, queryterms, numrecs);
74 list = reclist_create(nmem, numrecs);
76 service = conf_service_create(nmem);
78 // setting up service - sic!
79 // this should have been done by a nice service_create function !!!
81 //service->num_metadata = 1;
82 //service->metadata = 0;
83 //service->num_sortkeys = 0;
84 //service->sortkeys = 0;
87 //if (service->num_metadata)
89 // = nmem_malloc(nmem,
90 // sizeof(struct conf_metadata) * service->num_metadata);
92 // service->metadata = 0;
93 //service->metadata->name = nmem_strdup(nmem, "aname");
94 //service->metadata->brief = 1;
95 //service->metadata->termlist = 1;
96 //service->metadata->rank = 1;
97 //service->metadata->type = Metadata_type_generic;
98 //service->metadata->type = Metadata_type_year;
99 //service->metadata->merge = Metadata_merge_no;
100 //service->metadata->merge = Metadata_merge_unique;
101 //service->metadata->merge = Metadata_merge_longest;
102 //service->metadata->merge = Metadata_merge_range;
103 //service->metadata->merge = Metadata_merge_all;
106 = conf_metadata_create(nmem, "name",
107 Metadata_type_generic, Metadata_merge_unique,
109 service->num_metadata = 1;
111 conf_service_add_metadata(nmem, service, "name",
112 Metadata_type_generic, Metadata_merge_unique,
116 if (service->num_sortkeys)
119 sizeof(struct conf_sortkey) * service->num_sortkeys);
121 service->sortkeys = 0;
122 // service->sortkeys.type = Metadata_sortkey_numeric;
123 // service->sortkeys.type = Metadata_sortkey_skiparticle;
124 // service->sortkeys.name = service->metadata->name;
125 //service->metadata->sortkey_offset = sk_node;
129 // preparing one record
130 // this should have been done by a nice record_create function
131 // why the heck does the record know which client it belongs to ??
133 record = nmem_malloc(nmem, sizeof(struct record));
135 // which client should I use for record->client = cl; ??
137 // and which sortkeys data_types list should I use ??
138 record->sortkeys = 0;
141 sizeof(struct record_metadata*) * service->num_metadata);
142 memset(record->metadata, 0,
143 sizeof(struct record_metadata*) * service->num_metadata);
146 // now we need to put some actual data into the record ... how ??
147 // there is a hell of a lot spagetti code in logic.c ingest_record()
148 // line 694 ff snippet from there:
149 // this code needs to be analyzed and the fundamental stuff extracted
152 service->metadata[imeta].name;
153 md = &service->metadata[imeta];
154 if (md->sortkey_offset >= 0)
155 sk = &service->sortkeys[md->sortkey_offset];
158 // Find out where we are putting it if (md->merge == Metadata_merge_no)
159 wheretoput = &res->metadata[imeta];
161 wheretoput = &cluster->metadata[imeta];
165 newm = nmem_malloc(se->nmem, sizeof(struct record_metadata));
167 if (md->type == Metadata_type_generic)
170 for (p = (char *) value; *p && isspace(*p); p++)
172 for (pe = p + strlen(p) - 1;
173 pe > p && strchr(" ,/.:([", *pe); pe--)
175 newm->data.text = nmem_strdup(se->nmem, p);
178 else if (md->type == Metadata_type_year)
180 if (extract_years((char *) value, &first, &last) < 0)
185 yaz_log(YLOG_WARN, "Unknown type in metadata element %s", type);
188 if (md->type == Metadata_type_year && md->merge != Metadata_merge_range)
190 yaz_log(YLOG_WARN, "Only range merging supported for years");
193 if (md->merge == Metadata_merge_unique)
195 struct record_metadata *mnode;
196 for (mnode = *wheretoput; mnode; mnode = mnode->next)
197 if (!strcmp((const char *) mnode->data.text, newm->data.text))
201 newm->next = *wheretoput;
205 else if (md->merge == Metadata_merge_longest)
208 strlen(newm->data.text) > strlen((*wheretoput)->data.text))
213 char *s = nmem_strdup(se->nmem, newm->data.text);
214 if (!cluster->sortkeys[md->sortkey_offset])
215 cluster->sortkeys[md->sortkey_offset] =
216 nmem_malloc(se->nmem, sizeof(union data_types));
217 normalize_mergekey(s,
218 (sk->type == Metadata_sortkey_skiparticle));
219 cluster->sortkeys[md->sortkey_offset]->text = s;
223 else if (md->merge == Metadata_merge_all || md->merge == Metadata_merge_no)
225 newm->next = *wheretoput;
228 else if (md->merge == Metadata_merge_range)
230 assert(md->type == Metadata_type_year);
234 (*wheretoput)->data.number.min = first;
235 (*wheretoput)->data.number.max = last;
237 cluster->sortkeys[md->sortkey_offset] = &newm->data;
241 if (first < (*wheretoput)->data.number.min)
242 (*wheretoput)->data.number.min = first;
243 if (last > (*wheretoput)->data.number.max)
244 (*wheretoput)->data.number.max = last;
247 relevance_countwords(se->relevance, cluster,
248 (char *) value, md->rank);
251 if (md->type == Metadata_type_year)
254 sprintf(year, "%d", last);
255 add_facet(se, (char *) type, year);
258 sprintf(year, "%d", first);
259 add_facet(se, (char *) type, year);
263 add_facet(se, (char *) type, (char *) value);
267 //mergekey_norm = (xmlChar *) nmem_strdup(se->nmem, (char*) mergekey);
268 //normalize_mergekey((char *) mergekey_norm, 0);
271 // insert one record into recordlist/cluster - what's a cluster, exactly??
272 cluster = reclist_insert(list, service, record, (char *)mergekey, &total);
275 relevance_newrec(rel, cluster);
283 //relevance_prepare_read(rel, list);
286 //relevance_donerecord(rel, cluster);
287 // relevance_countwords(se->rel, cluster,
288 // (char *) value, service->metadata->rank);
300 int main(int argc, char **argv)
302 YAZ_CHECK_INIT(argc, argv);
306 test_relevance(argc, argv);
318 * indent-tabs-mode: nil
320 * vim: shiftwidth=4 tabstop=8 expandtab