Metadata 'skiparticle works for ICU normalization
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 24 Nov 2009 11:19:35 +0000 (12:19 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 24 Nov 2009 11:19:35 +0000 (12:19 +0100)
The skiparticle handling was only working for the 7-bit ASCII
normalization code before.

src/charsets.c
src/charsets.h
src/logic.c
src/normalize7bit.c
src/normalize7bit.h
src/relevance.c
test/test_icu_4.res
test/test_icu_5.res

index 9332aa0..f71f4c8 100644 (file)
@@ -30,6 +30,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/log.h>
 #include <ctype.h>
 #include <assert.h>
+#include <string.h>
 
 #include "charsets.h"
 #include "normalize7bit.h"
@@ -42,7 +43,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 /* charset handle */
 struct pp2_charset_s {
     const char *(*token_next_handler)(pp2_relevance_token_t prt);
-    const char *(*get_sort_handler)(pp2_relevance_token_t prt, int skip);
+    const char *(*get_sort_handler)(pp2_relevance_token_t prt);
     int ref_count;
 #if YAZ_HAVE_ICU
     struct icu_chain * icu_chn;
@@ -51,11 +52,11 @@ struct pp2_charset_s {
 };
 
 static const char *pp2_relevance_token_a_to_z(pp2_relevance_token_t prt);
-static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt, int skip_article);
+static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt);
 
 #if YAZ_HAVE_ICU
 static const char *pp2_relevance_token_icu(pp2_relevance_token_t prt);
-static const char *pp2_get_sort_icu(pp2_relevance_token_t prt, int skip_article);
+static const char *pp2_get_sort_icu(pp2_relevance_token_t prt);
 #endif
 
 /* tokenzier handle */
@@ -142,12 +143,30 @@ void pp2_charset_destroy(pp2_charset_t pct)
 }
 
 pp2_relevance_token_t pp2_relevance_tokenize(pp2_charset_t pct,
-                                             const char *buf)
+                                             const char *buf,
+                                             int skip_article)
 {
     pp2_relevance_token_t prt = xmalloc(sizeof(*prt));
 
     assert(pct);
 
+    if (skip_article)
+    {
+        const char *p = buf;
+        char firstword[64];
+        char *pout = firstword;
+        char articles[] = "the den der die des an a "; // must end in space
+        
+        while (*p && !isalnum(*(unsigned char *)p))
+            p++;
+        for (; *p && *p != ' ' && pout - firstword < (sizeof(firstword)-2); p++)
+            *pout++ = tolower(*(unsigned char *)p);
+        *pout++ = ' ';
+        *pout++ = '\0';
+        if (strstr(articles, firstword))
+            buf = p;
+    }
+
     prt->norm_str = wrbuf_alloc();
     prt->sort_str = wrbuf_alloc();
     prt->cp = buf;
@@ -184,9 +203,9 @@ const char *pp2_relevance_token_next(pp2_relevance_token_t prt)
     return (prt->pct->token_next_handler)(prt);
 }
 
-const char *pp2_get_sort(pp2_relevance_token_t prt, int skip)
+const char *pp2_get_sort(pp2_relevance_token_t prt)
 {
-    return prt->pct->get_sort_handler(prt, skip);
+    return prt->pct->get_sort_handler(prt);
 }
 
 #define raw_char(c) (((c) >= 'a' && (c) <= 'z') ? (c) : -1)
@@ -220,8 +239,7 @@ static const char *pp2_relevance_token_a_to_z(pp2_relevance_token_t prt)
     return wrbuf_cstr(prt->norm_str);
 }
 
-static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt,
-                                    int skip_article)
+static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt)
 {
     if (prt->last_cp == 0)
         return 0;
@@ -229,7 +247,7 @@ static const char *pp2_get_sort_ascii(pp2_relevance_token_t prt,
     {
         char *tmp = xstrdup(prt->last_cp);
         char *result = 0;
-        result = normalize7bit_mergekey(tmp, skip_article);
+        result = normalize7bit_mergekey(tmp);
         
         wrbuf_rewind(prt->sort_str);
         wrbuf_puts(prt->sort_str, result);
@@ -253,8 +271,7 @@ static const char *pp2_relevance_token_icu(pp2_relevance_token_t prt)
     return 0;
 }
 
-static const char *pp2_get_sort_icu(pp2_relevance_token_t prt,
-                                    int skip_article)
+static const char *pp2_get_sort_icu(pp2_relevance_token_t prt)
 {
     return icu_chain_token_sortkey(prt->pct->icu_chn);
 }
index cb41404..8d1efba 100644 (file)
@@ -38,10 +38,11 @@ void pp2_charset_destroy(pp2_charset_t pct);
 void pp2_charset_incref(pp2_charset_t pct);
 
 pp2_relevance_token_t pp2_relevance_tokenize(pp2_charset_t pct,
-                                             const char *buf);
+                                             const char *buf,
+                                             int skip_article);
 void pp2_relevance_token_destroy(pp2_relevance_token_t prt);
 const char *pp2_relevance_token_next(pp2_relevance_token_t prt);
-const char *pp2_get_sort(pp2_relevance_token_t prt, int skip_article);
+const char *pp2_get_sort(pp2_relevance_token_t prt);
 
 #if 0
 typedef int pp2_charset_normalize_t(pp2_charset_t pct,
index 3afa67c..c07d303 100644 (file)
@@ -895,7 +895,7 @@ static int get_mergekey_from_doc(xmlDoc *doc, xmlNode *root, const char *name,
                     pp2_relevance_token_t prt =
                         pp2_relevance_tokenize(
                             service->mergekey_pct,
-                            (const char *) value);
+                            (const char *) value, 0);
                     
                     wrbuf_puts(norm_wr, name);
                     wrbuf_puts(norm_wr, "=");
@@ -935,7 +935,7 @@ static const char *get_mergekey(xmlDoc *doc, struct client *cl, int record_no,
         pp2_relevance_token_t prt =
             pp2_relevance_tokenize(
                 service->mergekey_pct,
-                (const char *) mergekey);
+                (const char *) mergekey, 0);
         
         while ((norm_str = pp2_relevance_token_next(prt)))
         {
@@ -1197,11 +1197,11 @@ struct record *ingest_record(struct client *cl, const char *rec,
                          
                         prt = pp2_relevance_tokenize(
                             service->sort_pct,
-                            rec_md->data.text.disp);
+                            rec_md->data.text.disp, skip_article);
 
                         pp2_relevance_token_next(prt);
                          
-                        sort_str = pp2_get_sort(prt, skip_article);
+                        sort_str = pp2_get_sort(prt);
                          
                         cluster->sortkeys[sk_field_id]->text.disp = 
                             rec_md->data.text.disp;
index 1f993c9..cfa59bb 100644 (file)
@@ -44,29 +44,9 @@ char * normalize7bit_generic(char * str, const char * rm_chars)
     return p;
 }
 
-
-
-char * normalize7bit_mergekey(char *buf, int skiparticle)
+char *normalize7bit_mergekey(char *buf)
 {
     char *p = buf, *pout = buf;
-
-    if (skiparticle)
-    {
-        char firstword[64];
-        char articles[] = "the den der die des an a "; // must end in space
-
-        while (*p && !isalnum(*(unsigned char *)p))
-            p++;
-        pout = firstword;
-        while (*p && *p != ' ' && pout - firstword < 62)
-            *(pout++) = tolower(*(unsigned char *)(p++));
-        *(pout++) = ' ';
-        *(pout++) = '\0';
-        if (!strstr(articles, firstword))
-            p = buf;
-        pout = buf;
-    }
-
     while (*p)
     {
         while (*p && !isalnum(*(unsigned char *)p))
index 4cc51af..72aac93 100644 (file)
@@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #ifndef NORMALIZE7BIT_H
 #define NORMALIZE7BIT_H
 
-char *normalize7bit_mergekey(char *buf, int skiparticle);
+char *normalize7bit_mergekey(char *buf);
 char * normalize7bit_generic(char * str, const char * rm_chars);
 int extract7bit_dates(const char *buf, int *first, int *last, int longdate);
 
index c88676e..0234d91 100644 (file)
@@ -77,7 +77,7 @@ static struct word_entry *build_word_entries(pp2_charset_t pct, NMEM nmem,
 
     for (; *p; p++)
     {
-        pp2_relevance_token_t prt = pp2_relevance_tokenize(pct, *p);
+        pp2_relevance_token_t prt = pp2_relevance_tokenize(pct, *p, 0);
         const char *norm_str;
 
         while ((norm_str = pp2_relevance_token_next(prt)))
@@ -93,7 +93,7 @@ static struct word_entry *build_word_entries(pp2_charset_t pct, NMEM nmem,
 void relevance_countwords(struct relevance *r, struct record_cluster *cluster,
                           const char *words, int multiplier, const char *name)
 {
-    pp2_relevance_token_t prt = pp2_relevance_tokenize(r->pct, words);
+    pp2_relevance_token_t prt = pp2_relevance_tokenize(r->pct, words, 0);
     int *mult = cluster->term_frequency_vec_tmp;
     const char *norm_str;
     int i, length = 0;
index 899610d..84feb43 100644 (file)
 </hit>
 <hit>
 
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description tag="504">Includes bibliographical references and index</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+<hit>
+
 <md-title>The Puget Sound Region</md-title>
 <md-title-remainder>a portfolio of thematic computer maps</md-title-remainder>
 <md-date>1974</md-date>
 </hit>
 <hit>
 
-<md-title>The Computer Bible</md-title>
-<md-date>1973-1980</md-date>
-<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>The Computer Bible</md-title>
-<md-date>1973-1980</md-date>
-<md-description tag="500">Hebrew and Greek; introductions in English</md-description>
-<md-description tag="500">Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description>
-<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
-<md-test-usersetting-2>test-usersetting-2 data: 
-        YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title the computer bible author medium book</recid>
-</hit>
-<hit>
-
-<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
-<md-title-remainder>proceedings of the workshop</md-title-remainder>
-<md-date>1977</md-date>
-<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
-<md-title-remainder>proceedings of the workshop</md-title-remainder>
-<md-date>1977</md-date>
-<md-description tag="504">Includes bibliographical references and index</md-description>
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description tag="500">Cover title</md-description>
 <md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
 <md-test-usersetting-2>test-usersetting-2 data: 
         YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+<recid>title a plan for community college computer development author medium book</recid>
 </hit>
 <hit>
 
 </hit>
 <hit>
 
-<md-title>A plan for community college computer development</md-title>
-<md-date>1971</md-date>
-<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>A plan for community college computer development</md-title>
-<md-date>1971</md-date>
-<md-description tag="500">Cover title</md-description>
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description tag="500">Hebrew and Greek; introductions in English</md-description>
+<md-description tag="500">Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description>
 <md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
 <md-test-usersetting-2>test-usersetting-2 data: 
         YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title a plan for community college computer development author medium book</recid>
+<recid>title the computer bible author medium book</recid>
 </hit>
 </show>
index c4bc05d..407ac56 100644 (file)
@@ -8,16 +8,17 @@
 <num>9</num>
 <hit>
 
-<md-title>A plan for community college computer development</md-title>
-<md-date>1971</md-date>
-<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>A plan for community college computer development</md-title>
-<md-date>1971</md-date>
-<md-description tag="500">Cover title</md-description>
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>The Computer Bible</md-title>
+<md-date>1973-1980</md-date>
+<md-description tag="500">Hebrew and Greek; introductions in English</md-description>
+<md-description tag="500">Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description>
 <md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
 <md-test-usersetting-2>test-usersetting-2 data: 
         YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title a plan for community college computer development author medium book</recid>
+<recid>title the computer bible author medium book</recid>
 </hit>
 <hit>
 
 </hit>
 <hit>
 
-<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
-<md-title-remainder>proceedings of the workshop</md-title-remainder>
-<md-date>1977</md-date>
-<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
-<md-title-remainder>proceedings of the workshop</md-title-remainder>
-<md-date>1977</md-date>
-<md-description tag="504">Includes bibliographical references and index</md-description>
-<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
-<md-test-usersetting-2>test-usersetting-2 data: 
-        YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
-</hit>
-<hit>
-
-<md-title>The Computer Bible</md-title>
-<md-date>1973-1980</md-date>
-<md-description>Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
-<md-title>The Computer Bible</md-title>
-<md-date>1973-1980</md-date>
-<md-description tag="500">Hebrew and Greek; introductions in English</md-description>
-<md-description tag="500">Vols. 2, 8: Missoula, Mont. : Published by Scholars Press for Biblical Research Associates</md-description>
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description>Cover title</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>A plan for community college computer development</md-title>
+<md-date>1971</md-date>
+<md-description tag="500">Cover title</md-description>
 <md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
 <md-test-usersetting-2>test-usersetting-2 data: 
         YYYYYYYYY</md-test-usersetting-2></location>
-<recid>title the computer bible author medium book</recid>
+<recid>title a plan for community college computer development author medium book</recid>
 </hit>
 <hit>
 
 </hit>
 <hit>
 
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description>Includes bibliographical references and index</md-description><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">
+<md-title>Reconstruction tomography in diagnostic radiology and nuclear medicine</md-title>
+<md-title-remainder>proceedings of the workshop</md-title-remainder>
+<md-date>1977</md-date>
+<md-description tag="504">Includes bibliographical references and index</md-description>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test-usersetting-2>test-usersetting-2 data: 
+        YYYYYYYYY</md-test-usersetting-2></location>
+<recid>title reconstruction tomography in diagnostic radiology and nuclear medicine author medium book</recid>
+</hit>
+<hit>
+
 <md-title>The use of passwords for controlled access to computer resources</md-title>
 <md-date>1977</md-date>
 <md-author>Wood, Helen M</md-author><location id="z3950.indexdata.com/marc" name="Index Data MARC test server">