From 7eefa059dbe0c2d4ba24060421940df637d9cca8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 8 Sep 1995 14:52:41 +0000 Subject: [PATCH] Work on relevance feedback. --- rset/Makefile | 4 +- rset/rsbool.c | 6 +- rset/rset.c | 6 +- rset/rsisam.c | 6 +- rset/rsnull.c | 6 +- rset/rsrel.c | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rset/rstemp.c | 6 +- 7 files changed, 211 insertions(+), 11 deletions(-) create mode 100644 rset/rsrel.c diff --git a/rset/Makefile b/rset/Makefile index 7769f03..570d1ac 100644 --- a/rset/Makefile +++ b/rset/Makefile @@ -1,7 +1,7 @@ # Copyright (C) 1994, Index Data I/S # All rights reserved. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile,v 1.6 1995-09-06 13:27:15 adam Exp $ +# $Id: Makefile,v 1.7 1995-09-08 14:52:41 adam Exp $ SHELL=/bin/sh RANLIB=ranlib @@ -11,7 +11,7 @@ INCLUDE=-I../include -I$(YAZ)/include DEFS=$(INCLUDE) LIB=../lib/rset.a PROG= -PO=rset.o rstemp.o rsisam.o rsnull.o rsbool.o +PO=rset.o rstemp.o rsisam.o rsnull.o rsbool.o rsrel.o CPP=cc -E all: $(LIB) diff --git a/rset/rsbool.c b/rset/rsbool.c index a20c452..f34a61f 100644 --- a/rset/rsbool.c +++ b/rset/rsbool.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsbool.c,v $ - * Revision 1.4 1995-09-08 08:54:04 adam + * Revision 1.5 1995-09-08 14:52:41 adam + * Work on relevance feedback. + * + * Revision 1.4 1995/09/08 08:54:04 adam * More efficient and operation. * * Revision 1.3 1995/09/07 13:58:43 adam @@ -109,7 +112,6 @@ static rset_control *r_create (const struct rset_control *sel, void *parms) rset_bool_parms *bool_parms = parms; struct rset_bool_info *info; - logf (LOG_DEBUG, "rsbool_create(%s)", sel->desc); newct = xmalloc(sizeof(*newct)); memcpy (newct, sel, sizeof(*sel)); newct->buf = xmalloc (sizeof(struct rset_bool_info)); diff --git a/rset/rset.c b/rset/rset.c index e10f1b1..0776cb2 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rset.c,v $ - * Revision 1.5 1995-09-07 13:58:43 adam + * Revision 1.6 1995-09-08 14:52:41 adam + * Work on relevance feedback. + * + * Revision 1.5 1995/09/07 13:58:43 adam * New parameter: result-set file descriptor (RSFD) to support multiple * positions within the same result-set. * Boolean operators: and, or, not implemented. @@ -32,6 +35,7 @@ RSET rset_create(const rset_control *sel, void *parms) { RSET new; + logf (LOG_DEBUG, "rs_create(%s)", sel->desc); new = xmalloc(sizeof(*new)); /* make dynamic alloc scheme */ if (!(new->control = (*sel->f_create)(sel, parms))) return 0; diff --git a/rset/rsisam.c b/rset/rsisam.c index 1eb1828..371b7c7 100644 --- a/rset/rsisam.c +++ b/rset/rsisam.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsisam.c,v $ - * Revision 1.9 1995-09-07 13:58:43 adam + * Revision 1.10 1995-09-08 14:52:42 adam + * Work on relevance feedback. + * + * Revision 1.9 1995/09/07 13:58:43 adam * New parameter: result-set file descriptor (RSFD) to support multiple * positions within the same result-set. * Boolean operators: and, or, not implemented. @@ -80,7 +83,6 @@ static rset_control *r_create(const struct rset_control *sel, void *parms) rset_isam_parms *pt = parms; struct rset_isam_info *info; - logf (LOG_DEBUG, "rsisam_create(%s)", sel->desc); newct = xmalloc(sizeof(*newct)); memcpy(newct, sel, sizeof(*sel)); diff --git a/rset/rsnull.c b/rset/rsnull.c index a278293..d46c9aa 100644 --- a/rset/rsnull.c +++ b/rset/rsnull.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsnull.c,v $ - * Revision 1.2 1995-09-07 13:58:43 adam + * Revision 1.3 1995-09-08 14:52:42 adam + * Work on relevance feedback. + * + * Revision 1.2 1995/09/07 13:58:43 adam * New parameter: result-set file descriptor (RSFD) to support multiple * positions within the same result-set. * Boolean operators: and, or, not implemented. @@ -47,7 +50,6 @@ static rset_control *r_create(const struct rset_control *sel, void *parms) { rset_control *newct; - logf (LOG_DEBUG, "rsnull_create(%s)", sel->desc); newct = xmalloc(sizeof(*newct)); memcpy(newct, sel, sizeof(*sel)); return newct; diff --git a/rset/rsrel.c b/rset/rsrel.c new file mode 100644 index 0000000..4faed5b --- /dev/null +++ b/rset/rsrel.c @@ -0,0 +1,188 @@ +/* + * Copyright (C) 1994-1995, Index Data I/S + * All rights reserved. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: rsrel.c,v $ + * Revision 1.1 1995-09-08 14:52:42 adam + * Work on relevance feedback. + * + */ + +#include +#include + +#include +#include +#include + +static rset_control *r_create(const struct rset_control *sel, void *parms); +static RSFD r_open (rset_control *ct, int wflag); +static void r_close (RSFD rfd); +static void r_delete (rset_control *ct); +static void r_rewind (RSFD rfd); +static int r_count (rset_control *ct); +static int r_read (RSFD rfd, void *buf); +static int r_write (RSFD rfd, const void *buf); + +static const rset_control control = +{ + "relevance set type", + 0, + r_create, + r_open, + r_close, + r_delete, + r_rewind, + r_count, + r_read, + r_write +}; + +const rset_control *rset_kind_relevance = &control; + +struct rset_rel_info { + int key_size; + int max_rec; + int no_rec; + int (*cmp)(const void *p1, const void *p2); + void *key_buf; + int *score_buf; + + struct rset_rel_rfd *rfd_list; +}; + +struct rset_rel_rfd { + int position; + struct rset_rel_rfd *next; + struct rset_rel_info *info; +}; + +static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms) +{ + char *isam_buf; + int *isam_r; + ISPT *isam_pt; + int i; + + isam_buf = xmalloc (info->key_size * parms->no_isam_positions); + isam_r = xmalloc (sizeof (*isam_r) * parms->no_isam_positions); + isam_pt = xmalloc (sizeof (*isam_pt) * parms->no_isam_positions); + + for (i = 0; ino_isam_positions; i++) + { + isam_pt[i] = is_position (parms->is, parms->isam_positions[i]); + isam_r[i] = is_readkey (isam_pt[i], isam_buf + i*info->key_size); + } + + for (i = 0; ino_isam_positions; i++) + is_pt_free (isam_pt[i]); + xfree (isam_buf); + xfree (isam_r); + xfree (isam_pt); +} + +static rset_control *r_create (const struct rset_control *sel, void *parms) +{ + rset_control *newct; + rset_relevance_parms *r_parms = parms; + struct rset_rel_info *info; + + newct = xmalloc(sizeof(*newct)); + memcpy(newct, sel, sizeof(*sel)); + newct->buf = xmalloc (sizeof(struct rset_rel_info)); + + info = newct->buf; + info->key_size = r_parms->key_size; + assert (info->key_size > 1); + info->max_rec = r_parms->max_rec; + assert (info->max_rec > 1); + info->cmp = r_parms->cmp; + + info->key_buf = xmalloc (info->key_size * info->max_rec); + info->score_buf = xmalloc (sizeof(*info->score_buf) * info->max_rec); + info->no_rec = 0; + info->rfd_list = NULL; + + relevance (info, r_parms); + return newct; +} + +static RSFD r_open (rset_control *ct, int wflag) +{ + struct rset_rel_rfd *rfd; + struct rset_rel_info *info = ct->buf; + + if (wflag) + { + logf (LOG_FATAL, "relevance set type is read-only"); + return NULL; + } + rfd = xmalloc (sizeof(*rfd)); + rfd->next = info->rfd_list; + info->rfd_list = rfd; + rfd->position = 0; + rfd->info = info; + return rfd; +} + +static void r_close (RSFD rfd) +{ + struct rset_rel_info *info = ((struct rset_rel_rfd*)rfd)->info; + struct rset_rel_rfd **rfdp; + + for (rfdp = &info->rfd_list; *rfdp; rfdp = &(*rfdp)->next) + if (*rfdp == rfd) + { + *rfdp = (*rfdp)->next; + free (rfd); + return; + } + logf (LOG_FATAL, "r_close but no rfd match!"); + assert (0); +} + +static void r_delete (rset_control *ct) +{ + struct rset_rel_info *info = ct->buf; + + assert (info->rfd_list == NULL); + xfree (info->key_buf); + xfree (info->score_buf); + xfree (info); + xfree (ct); +} + +static void r_rewind (RSFD rfd) +{ + ((struct rset_rel_rfd*) rfd)->position = 0; +} + +static int r_count (rset_control *ct) +{ + struct rset_rel_info *info = ct->buf; + + return info->no_rec; +} + +static int r_read (RSFD rfd, void *buf) +{ + struct rset_rel_rfd *p = rfd; + struct rset_rel_info *info = p->info; + + if (p->position >= info->max_rec) + return 0; + memcpy ((char*) buf + sizeof(*info->score_buf), + (char*) info->key_buf + info->key_size * p->position, + info->key_size); + memcpy ((char*) buf, + info->score_buf + p->position, sizeof(*info->score_buf)); + ++(p->position); + return 1; +} + +static int r_write (RSFD rfd, const void *buf) +{ + logf (LOG_FATAL, "relevance set type is read-only"); + return -1; +} diff --git a/rset/rstemp.c b/rset/rstemp.c index 0c835f9..e7a0a4c 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rstemp.c,v $ - * Revision 1.7 1995-09-07 13:58:44 adam + * Revision 1.8 1995-09-08 14:52:42 adam + * Work on relevance feedback. + * + * Revision 1.7 1995/09/07 13:58:44 adam * New parameter: result-set file descriptor (RSFD) to support multiple * positions within the same result-set. * Boolean operators: and, or, not implemented. @@ -88,7 +91,6 @@ static struct rset_control *r_create(const struct rset_control *sel, rset_temp_parms *temp_parms = parms; struct rset_temp_info *info; - logf (LOG_DEBUG, "ritemp_create(%s)", sel->desc); newct = xmalloc(sizeof(*newct)); memcpy(newct, sel, sizeof(*sel)); newct->buf = xmalloc (sizeof(struct rset_temp_info)); -- 1.7.10.4