2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-09-08 14:52:42 adam
8 * Work on relevance feedback.
19 static rset_control *r_create(const struct rset_control *sel, void *parms);
20 static RSFD r_open (rset_control *ct, int wflag);
21 static void r_close (RSFD rfd);
22 static void r_delete (rset_control *ct);
23 static void r_rewind (RSFD rfd);
24 static int r_count (rset_control *ct);
25 static int r_read (RSFD rfd, void *buf);
26 static int r_write (RSFD rfd, const void *buf);
28 static const rset_control control =
42 const rset_control *rset_kind_relevance = &control;
44 struct rset_rel_info {
48 int (*cmp)(const void *p1, const void *p2);
52 struct rset_rel_rfd *rfd_list;
57 struct rset_rel_rfd *next;
58 struct rset_rel_info *info;
61 static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms)
68 isam_buf = xmalloc (info->key_size * parms->no_isam_positions);
69 isam_r = xmalloc (sizeof (*isam_r) * parms->no_isam_positions);
70 isam_pt = xmalloc (sizeof (*isam_pt) * parms->no_isam_positions);
72 for (i = 0; i<parms->no_isam_positions; i++)
74 isam_pt[i] = is_position (parms->is, parms->isam_positions[i]);
75 isam_r[i] = is_readkey (isam_pt[i], isam_buf + i*info->key_size);
78 for (i = 0; i<parms->no_isam_positions; i++)
79 is_pt_free (isam_pt[i]);
85 static rset_control *r_create (const struct rset_control *sel, void *parms)
88 rset_relevance_parms *r_parms = parms;
89 struct rset_rel_info *info;
91 newct = xmalloc(sizeof(*newct));
92 memcpy(newct, sel, sizeof(*sel));
93 newct->buf = xmalloc (sizeof(struct rset_rel_info));
96 info->key_size = r_parms->key_size;
97 assert (info->key_size > 1);
98 info->max_rec = r_parms->max_rec;
99 assert (info->max_rec > 1);
100 info->cmp = r_parms->cmp;
102 info->key_buf = xmalloc (info->key_size * info->max_rec);
103 info->score_buf = xmalloc (sizeof(*info->score_buf) * info->max_rec);
105 info->rfd_list = NULL;
107 relevance (info, r_parms);
111 static RSFD r_open (rset_control *ct, int wflag)
113 struct rset_rel_rfd *rfd;
114 struct rset_rel_info *info = ct->buf;
118 logf (LOG_FATAL, "relevance set type is read-only");
121 rfd = xmalloc (sizeof(*rfd));
122 rfd->next = info->rfd_list;
123 info->rfd_list = rfd;
129 static void r_close (RSFD rfd)
131 struct rset_rel_info *info = ((struct rset_rel_rfd*)rfd)->info;
132 struct rset_rel_rfd **rfdp;
134 for (rfdp = &info->rfd_list; *rfdp; rfdp = &(*rfdp)->next)
137 *rfdp = (*rfdp)->next;
141 logf (LOG_FATAL, "r_close but no rfd match!");
145 static void r_delete (rset_control *ct)
147 struct rset_rel_info *info = ct->buf;
149 assert (info->rfd_list == NULL);
150 xfree (info->key_buf);
151 xfree (info->score_buf);
156 static void r_rewind (RSFD rfd)
158 ((struct rset_rel_rfd*) rfd)->position = 0;
161 static int r_count (rset_control *ct)
163 struct rset_rel_info *info = ct->buf;
168 static int r_read (RSFD rfd, void *buf)
170 struct rset_rel_rfd *p = rfd;
171 struct rset_rel_info *info = p->info;
173 if (p->position >= info->max_rec)
175 memcpy ((char*) buf + sizeof(*info->score_buf),
176 (char*) info->key_buf + info->key_size * p->position,
179 info->score_buf + p->position, sizeof(*info->score_buf));
184 static int r_write (RSFD rfd, const void *buf)
186 logf (LOG_FATAL, "relevance set type is read-only");