2 * Copyright (c) 1995, the EUROPAGATE consortium (see below).
4 * The EUROPAGATE consortium members are:
6 * University College Dublin
7 * Danmarks Teknologiske Videnscenter
8 * An Chomhairle Leabharlanna
9 * Consejo Superior de Investigaciones Cientificas
11 * Permission to use, copy, modify, distribute, and sell this software and
12 * its documentation, in whole or in part, for any purpose, is hereby granted,
15 * 1. This copyright and permission notice appear in all copies of the
16 * software and its documentation. Notices of copyright or attribution
17 * which appear at the beginning of any file must remain unchanged.
19 * 2. The names of EUROPAGATE or the project partners may not be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
23 * 3. Users of this software (implementors and gateway operators) agree to
24 * inform the EUROPAGATE consortium of their use of the software. This
25 * information will be used to evaluate the EUROPAGATE project and the
26 * software, and to plan further developments. The consortium may use
27 * the information in later publications.
29 * 4. Users of this software agree to make their best efforts, when
30 * documenting their use of the software, to acknowledge the EUROPAGATE
31 * consortium, and the role played by the software in their work.
33 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
34 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
35 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
36 * IN NO EVENT SHALL THE EUROPAGATE CONSORTIUM OR ITS MEMBERS BE LIABLE
37 * FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF
38 * ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
39 * OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND
40 * ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
41 * USE OR PERFORMANCE OF THIS SOFTWARE.
46 * \file ccl_stop_words.c
47 * \brief Removes stop words from terms in RPN tree
56 struct ccl_stop_info {
59 struct ccl_stop_info *next;
62 struct ccl_stop_words {
64 NMEM nmem; /* memory for removed items */
65 struct ccl_stop_info *removed_items;
68 static void append_removed_item(ccl_stop_words_t csw,
70 const char *t, size_t len)
72 struct ccl_stop_info *csi = nmem_malloc(csw->nmem, sizeof(*csi));
73 struct ccl_stop_info **csip = &csw->removed_items;
75 csi->qualname = nmem_strdup(csw->nmem, qname);
79 csi->term = nmem_malloc(csw->nmem, len+1);
80 memcpy(csi->term, t, len);
81 csi->term[len] = '\0';
85 csip = &(*csip)->next;
90 ccl_stop_words_t ccl_stop_words_create(void)
92 NMEM nmem = nmem_create();
93 ccl_stop_words_t csw = xmalloc(sizeof(*csw));
95 csw->removed_items = 0;
96 csw->blank_chars = xstrdup(" \r\n\t");
100 void ccl_stop_words_destroy(ccl_stop_words_t csw)
104 nmem_destroy(csw->nmem);
105 xfree(csw->blank_chars);
110 struct ccl_rpn_node *ccl_remove_stop_r(ccl_stop_words_t csw,
112 struct ccl_rpn_node *p)
114 struct ccl_rpn_node *left, *right;
121 left = ccl_remove_stop_r(csw, bibset, p->u.p[0]);
122 right = ccl_remove_stop_r(csw, bibset, p->u.p[1]);
125 /* we must delete our binary node and return child (if any) */
143 char *cp = p->u.t.term;
147 while (*cp && strchr(csw->blank_chars, *cp))
154 while (*cp && !strchr(csw->blank_chars, *cp))
158 size_t len = cp - cp0;
159 if (ccl_search_stop(bibset, p->u.t.qual,
162 append_removed_item(csw, p->u.t.qual,
164 while (*cp && strchr(csw->blank_chars, *cp))
166 memmove(cp0, cp, strlen(cp)+1);
175 /* chop right blanks .. and see if term it gets empty */
176 if (p->u.t.term && csw->removed_items)
178 char *cp = p->u.t.term + strlen(p->u.t.term);
181 if (cp == p->u.t.term)
183 /* term is empty / blank */
187 if (!strchr(csw->blank_chars, cp[-1]))
199 int ccl_stop_words_tree(ccl_stop_words_t csw,
200 CCL_bibset bibset, struct ccl_rpn_node **t)
202 struct ccl_rpn_node *r;
204 /* remove list items */
205 nmem_reset(csw->nmem);
206 csw->removed_items = 0;
208 r = ccl_remove_stop_r(csw, bibset, *t);
210 if (csw->removed_items)
215 int ccl_stop_words_info(ccl_stop_words_t csw, int idx,
216 const char **qualname, const char **term)
218 struct ccl_stop_info *csi = csw->removed_items;
220 while (csi && i < idx)
227 *qualname = csi->qualname;
237 * indent-tabs-mode: nil
239 * vim: shiftwidth=4 tabstop=8 expandtab