| 1 | /* Program WTRIG1: trigrams 1A |
|---|
| 2 | */ |
|---|
| 3 | #include <stdio.h> |
|---|
| 4 | #include <string.h> |
|---|
| 5 | #include <ctype.h> |
|---|
| 6 | #if BEFORE55a |
|---|
| 7 | #include <math.h> |
|---|
| 8 | #include <time.h> |
|---|
| 9 | #endif //BEFORE55a |
|---|
| 10 | |
|---|
| 11 | #include "cisis.h" /* CISIS Interface header file */ |
|---|
| 12 | #include "cirun.h" /* CISIS Interface runtime declarations */ |
|---|
| 13 | #if BEFORE55a |
|---|
| 14 | #include "cihsh.h" /* CISIS Interface hashing & binary table search */ |
|---|
| 15 | #endif //BEFORE55a |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | #define DISCART 1 |
|---|
| 19 | |
|---|
| 20 | #define PARMDTAG 1 |
|---|
| 21 | #define PARMDTAG6W 1 |
|---|
| 22 | |
|---|
| 23 | #define PARMLANG 1 |
|---|
| 24 | #define MAXPARMLANG 32 |
|---|
| 25 | |
|---|
| 26 | #define MAXSAVETEXT 128*1024 |
|---|
| 27 | |
|---|
| 28 | #if BEFORE55a |
|---|
| 29 | #define TAG1 1 |
|---|
| 30 | #define TAG2 2 |
|---|
| 31 | #define TAG3 3 |
|---|
| 32 | #endif //BEFORE55a |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #if BEFORE44B |
|---|
| 36 | /* tabelas de mxaot.c */ |
|---|
| 37 | unsigned char ansiuctab[256]= |
|---|
| 38 | { |
|---|
| 39 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, |
|---|
| 40 | 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, |
|---|
| 41 | 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
|---|
| 42 | 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, |
|---|
| 43 | 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
|---|
| 44 | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
|---|
| 45 | 96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
|---|
| 46 | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127, |
|---|
| 47 | 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143, |
|---|
| 48 | 144,145,146,147,148,149,150,151,152,153,138,155,140,157,158,159, |
|---|
| 49 | 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175, |
|---|
| 50 | 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191, |
|---|
| 51 | 65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, |
|---|
| 52 | 68, 78, 79, 79, 79, 79, 79,215,216, 85, 85, 85, 85, 89,222,223, |
|---|
| 53 | 65, 65, 65, 65, 65, 65, 65, 67, 69, 69, 69, 69, 73, 73, 73, 73, |
|---|
| 54 | 208, 78, 79, 79, 79, 79, 79,247,216, 85, 85, 85, 85,221,222,221 |
|---|
| 55 | }; |
|---|
| 56 | |
|---|
| 57 | unsigned char ansiactab[] = { |
|---|
| 58 | 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, |
|---|
| 59 | 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
|---|
| 60 | 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99,100,101,102,103,104, |
|---|
| 61 | 105,106,107,108,109,110,111,112,113,114,115,116,117, |
|---|
| 62 | 118,119,120,121,122,128,129,130,131,132,133,134,135,136,137,138,139,140,141, |
|---|
| 63 | 142,143,144,145,146,147,148,149,150,151,152,153,154, |
|---|
| 64 | 160,161,162,163,164,165,168,192,193,194,195,196,199,200,201,202,203,204,205, |
|---|
| 65 | 206,207,209,210,211,212,213,214,217,218,219,220,221, |
|---|
| 66 | 224,225,226,227,228,231,232,233,234,235,236,237,238,239,241,242,243,244,245, |
|---|
| 67 | 246,249,250,251,252,253,255 |
|---|
| 68 | ,000 |
|---|
| 69 | }; |
|---|
| 70 | #endif //BEFORE44b |
|---|
| 71 | |
|---|
| 72 | typedef struct xlistawt1 { |
|---|
| 73 | float weight; |
|---|
| 74 | LONGX hidx; |
|---|
| 75 | void *prev; |
|---|
| 76 | void *next; |
|---|
| 77 | void *avail; |
|---|
| 78 | } LISTAWT1; |
|---|
| 79 | |
|---|
| 80 | void main(int argc, char *argv[]) |
|---|
| 81 | { |
|---|
| 82 | LONGX COLLECTION_SIZE; /* N - #docs in collection */ |
|---|
| 83 | |
|---|
| 84 | LONGX *COLLECTION; /* n(t) - #docs trigram occurs */ |
|---|
| 85 | int *DOCUMENT; /* f(t) - #occs of trigram in document */ |
|---|
| 86 | /* [also flag 1st occ in doc] */ |
|---|
| 87 | |
|---|
| 88 | float *GLOBALWEIGHT; /* g(t) - trigram global weight */ |
|---|
| 89 | |
|---|
| 90 | float LOCALWEIGHT; /* l(t) - trigram local weight */ |
|---|
| 91 | float *PRODWEIGHT; /* lg(t) - trigram local*global weight */ |
|---|
| 92 | float TERMWEIGHT; /* w(t) - trigram normalized weight */ |
|---|
| 93 | |
|---|
| 94 | LONGX *OFFSET; |
|---|
| 95 | LONGX *COUNT; |
|---|
| 96 | LONGX *POSTINGS; |
|---|
| 97 | |
|---|
| 98 | LONGX *INDEX; /* position before relocation */ |
|---|
| 99 | |
|---|
| 100 | LISTAWT1 *lista; |
|---|
| 101 | |
|---|
| 102 | char *table; |
|---|
| 103 | LONGX maxprim,hidx; |
|---|
| 104 | char *h; |
|---|
| 105 | int hwidth; |
|---|
| 106 | int found; |
|---|
| 107 | LONGX nterms,hidx2; |
|---|
| 108 | LONGX countok,xcount,xcountrecs,ycount; |
|---|
| 109 | char *h2; |
|---|
| 110 | LONGX hloop; |
|---|
| 111 | |
|---|
| 112 | RECSTRU *recp; /* mandatory for defines REC,MFR,DIR,FIELDP */ |
|---|
| 113 | LONGX irec,crec,crec2,zirec,xirec; |
|---|
| 114 | LONGX maxmfn,mfn,docmfn; |
|---|
| 115 | |
|---|
| 116 | DIRSTRU *dirp; |
|---|
| 117 | int xdir; |
|---|
| 118 | int iocc,left; |
|---|
| 119 | FFI loop,keylen; |
|---|
| 120 | char *p,*q,*fldp; |
|---|
| 121 | |
|---|
| 122 | char areacmd[BUFSIZ]; |
|---|
| 123 | char areacmd6words[BUFSIZ]; |
|---|
| 124 | char areacmd6words2[BUFSIZ]; |
|---|
| 125 | |
|---|
| 126 | char *buff; |
|---|
| 127 | LONGX buffsize; |
|---|
| 128 | char *dtagbuff=NULL; |
|---|
| 129 | |
|---|
| 130 | LONGX count; |
|---|
| 131 | int iarg; |
|---|
| 132 | LONGX xtag; |
|---|
| 133 | LONGX n; |
|---|
| 134 | |
|---|
| 135 | int trigrams=1; |
|---|
| 136 | |
|---|
| 137 | char *indocumentsdb=NULL; |
|---|
| 138 | char *documentsdb=NULL; |
|---|
| 139 | |
|---|
| 140 | char *parmdocumentsdb=NULL; |
|---|
| 141 | UWORD parmtag=0; |
|---|
| 142 | int parmwidth=0; |
|---|
| 143 | char *parmuppercase="ascii"; |
|---|
| 144 | float parmmaxrf=0.50; |
|---|
| 145 | int parmmaxtv=50; |
|---|
| 146 | LONGX parmcategories=100000; |
|---|
| 147 | char *collectiondb=NULL; |
|---|
| 148 | char collectionsizedb[CIMPL+1] = { '\0' }; |
|---|
| 149 | char collectionoccsdb[CIMPL+1] = { '\0' }; |
|---|
| 150 | char outcollectionsizedb[CIMPL+1] = { '\0' }; |
|---|
| 151 | char outcollectionoccsdb[CIMPL+1] = { '\0' }; |
|---|
| 152 | char outtermvectorsdb[CIMPL+1] = { '\0' }; |
|---|
| 153 | char outterminverteddb[CIMPL+1] = { '\0' }; |
|---|
| 154 | int parmtrace=0; |
|---|
| 155 | int parmtrace2=0; |
|---|
| 156 | LONGX parmtell=0; |
|---|
| 157 | LONGX parmtell2=0; |
|---|
| 158 | |
|---|
| 159 | int parmwritebin=0; |
|---|
| 160 | |
|---|
| 161 | LONGX readcollectionsize=0; |
|---|
| 162 | |
|---|
| 163 | LONGX usercollectionsize=0; |
|---|
| 164 | UWORD usertag=0; |
|---|
| 165 | int userwidth=0; |
|---|
| 166 | char *useruppercase=NULL; |
|---|
| 167 | float usermaxrf=0; |
|---|
| 168 | int usermaxtv=0; |
|---|
| 169 | LONGX usercategories=0; |
|---|
| 170 | |
|---|
| 171 | FMT_CODE *extractfmtp=NULL; /* formato para tab= */ |
|---|
| 172 | char *extractfmta=NULL; /* area para tab= */ |
|---|
| 173 | |
|---|
| 174 | FMT_CODE *readextractfmtp=NULL; /* formato para tab= */ |
|---|
| 175 | char *readextractfmta=NULL; /* area para tab= */ |
|---|
| 176 | |
|---|
| 177 | time_t secs_now; |
|---|
| 178 | struct tm *tp; |
|---|
| 179 | time_t secs_start,secs_1,secs_2,secs_3,secs_4; |
|---|
| 180 | |
|---|
| 181 | int parmrelloc=1; |
|---|
| 182 | int parmsort=1; |
|---|
| 183 | int parmshowh=0; |
|---|
| 184 | int parmx12345=1; |
|---|
| 185 | |
|---|
| 186 | #if PARMLANG |
|---|
| 187 | char *HITS; /* HITS[] */ |
|---|
| 188 | LONGX hitbytes; |
|---|
| 189 | unsigned char hitbitmask[8] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 }; |
|---|
| 190 | unsigned char hitmask; |
|---|
| 191 | //LONGX hitmfn; |
|---|
| 192 | LONGX hitoffset; |
|---|
| 193 | char *langshits[MAXPARMLANG]; |
|---|
| 194 | char *langsname[MAXPARMLANG]; |
|---|
| 195 | LONGX langscount[MAXPARMLANG]; |
|---|
| 196 | int nlangs=0; |
|---|
| 197 | int langidx=(-1); |
|---|
| 198 | #endif /* PARMLANG */ |
|---|
| 199 | LONGX maxhits=0L; |
|---|
| 200 | |
|---|
| 201 | int parmdtag=0; |
|---|
| 202 | char dtagc1='\0'; |
|---|
| 203 | char dtagc2='\0'; |
|---|
| 204 | |
|---|
| 205 | int parm6words=0; |
|---|
| 206 | LONGX outmfn=0; /* init */ |
|---|
| 207 | |
|---|
| 208 | DIRSTRU *zdirp; |
|---|
| 209 | int zxdir; |
|---|
| 210 | int zloop; |
|---|
| 211 | char *zfldp; |
|---|
| 212 | LONGX countcollection; |
|---|
| 213 | |
|---|
| 214 | char parmexcludedb[CIMPL+1] = { '\0' }; |
|---|
| 215 | LONGX itrm; |
|---|
| 216 | |
|---|
| 217 | int parmsavetext=1; |
|---|
| 218 | char savetext[MAXSAVETEXT+1]; |
|---|
| 219 | |
|---|
| 220 | LONGX parmfrom,parmto,parmloop,parmcount; |
|---|
| 221 | LONGX xpcount; |
|---|
| 222 | |
|---|
| 223 | parmfrom=1; parmto=0; parmloop=1; parmcount=LONGX_MAX; |
|---|
| 224 | |
|---|
| 225 | /* get secs_ for elapsed */ |
|---|
| 226 | secs_start=time(&secs_now); |
|---|
| 227 | tp=localtime(&secs_start); |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | if (argc < 3) { |
|---|
| 231 | printf("%s",cicopyr("Utility WTRIG1")); |
|---|
| 232 | printf(" \n"); |
|---|
| 233 | printf("wtrig1 documents=<mf1>[,<mf3>] extract={<tag>|<fmt>} [collection=<mf2>] \n"); |
|---|
| 234 | printf(" \n"); |
|---|
| 235 | printf(" input parms and collection data from <mf2>.c and <mf2>.n, if provided \n"); |
|---|
| 236 | printf(" input text from <mf1>, using field <tag> or format specification <fmt> \n"); |
|---|
| 237 | printf(" output a term vector for each input text to <mf1>.v or <mf3>.v \n"); |
|---|
| 238 | //printf(" if collection is not provided, a first data reading is performed \n"); |
|---|
| 239 | //printf(" to get the term distribution used in term global weighting; \n"); |
|---|
| 240 | printf(" \n"); |
|---|
| 241 | printf(" options: width=<term width> 0 for trigrams [%d] \n",parmwidth); |
|---|
| 242 | printf(" case={ascii|ansi|<file>} [%s] \n",parmuppercase); |
|---|
| 243 | printf(" maxrf=<max relative frequency for a term> [%4.2f]\n",parmmaxrf); |
|---|
| 244 | printf(" maxtv=<max #terms in a term vector> [%d] \n",parmmaxtv); |
|---|
| 245 | printf(" K=<max #terms> [%"_LD_"] \n",parmcategories); |
|---|
| 246 | printf(" N=<total #docs> [maxmfn] \n"); |
|---|
| 247 | printf(" \n"); |
|---|
| 248 | printf(" col.c=<mf> collection parms [collection.c] \n"); |
|---|
| 249 | printf(" col.n=<mf> term distribution in collection [collection.n] \n"); |
|---|
| 250 | printf(" \n"); |
|---|
| 251 | printf(" out.c={<mf>|void} document parms [document.c|void]\n"); |
|---|
| 252 | printf(" out.n={<mf>|void} term distribution in documents [document.n|void]\n"); |
|---|
| 253 | printf(" out.x={<mf>|void} posting list for each term [document.x|void]\n"); |
|---|
| 254 | printf(" out.v={<mf>|void} term vector for each document [document.v] \n"); |
|---|
| 255 | printf(" \n"); |
|---|
| 256 | //printf(" [-relloc] [-sort] [+hash] \n"); |
|---|
| 257 | printf(" [dmfn] [6words] [exclude=<if>] [%d] [%d] [%s] \n",parmdtag,parm6words,parmexcludedb); |
|---|
| 258 | printf(" [bin] trace[={1|2|4|8|16|32|64|3..127}] [%d] \n",parmtrace); |
|---|
| 259 | printf(" \n"); |
|---|
| 260 | exit(1); |
|---|
| 261 | } |
|---|
| 262 | |
|---|
| 263 | /* get parameters */ |
|---|
| 264 | for (iarg=1; iarg < argc; iarg++) { |
|---|
| 265 | p=argv[iarg]; |
|---|
| 266 | if (parmtrace) printf("+++ %s\n",p); |
|---|
| 267 | if (strcmp(p,"trace") == 0) { |
|---|
| 268 | parmtrace2=1; |
|---|
| 269 | parmtrace=127; |
|---|
| 270 | continue; |
|---|
| 271 | } |
|---|
| 272 | if (strncmp(p,"documents?",10) == 0 || strncmp(p,"documents=",10) == 0 || |
|---|
| 273 | strncmp(p,"d?",2) == 0 || strncmp(p,"d=",2) == 0) { |
|---|
| 274 | if (strncmp(p,"d?",2) == 0 || strncmp(p,"d=",2) == 0) parmdocumentsdb=p+2; |
|---|
| 275 | else parmdocumentsdb=p+10; |
|---|
| 276 | if (!*parmdocumentsdb) fatal(p); |
|---|
| 277 | continue; |
|---|
| 278 | } |
|---|
| 279 | if (strncmp(p,"extract?",8) == 0 || strncmp(p,"extract=",8) == 0 || |
|---|
| 280 | strncmp(p,"e?",2) == 0 || strncmp(p,"e=",2) == 0) { |
|---|
| 281 | if (strncmp(p,"e?",2) == 0 || strncmp(p,"e=",2) == 0) q=p+2; |
|---|
| 282 | else q=p+8; |
|---|
| 283 | if (isdigit(*q)) { |
|---|
| 284 | if (sscanf(q,"%"_LD_,&xtag) != 1) fatal(p); |
|---|
| 285 | if (xtag < 1 || (unsigned)xtag > USHRT_MAX) fatal(p); |
|---|
| 286 | usertag=(UWORD)xtag; |
|---|
| 287 | if (extractfmta) fatal(p); |
|---|
| 288 | continue; |
|---|
| 289 | } |
|---|
| 290 | else { |
|---|
| 291 | extractfmta=loadfile(NULL,'@',q,NULL,0,'\0'); |
|---|
| 292 | if (!extractfmta) fatal(p); |
|---|
| 293 | if (fmt_gener(&extractfmtp,extractfmta)) fatal(extractfmta+fmt_errof); |
|---|
| 294 | if (usertag) fatal(p); |
|---|
| 295 | continue; |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | if (strncmp(p,"width?",6) == 0 || strncmp(p,"width=",6) == 0) { |
|---|
| 299 | if (sscanf(p+6,"%d",&userwidth) != 1) fatal(p); |
|---|
| 300 | if (userwidth < 0) fatal(p); |
|---|
| 301 | continue; |
|---|
| 302 | } |
|---|
| 303 | if (strncmp(p,"case?",5) == 0 || strncmp(p,"case=",5) == 0) { |
|---|
| 304 | useruppercase=p+5; |
|---|
| 305 | if (strcmp(useruppercase,"ascii") == 0) { |
|---|
| 306 | continue; |
|---|
| 307 | } |
|---|
| 308 | memset(isiswctab,0x00,256); |
|---|
| 309 | if (strcmp(useruppercase,"ansi") == 0) { |
|---|
| 310 | memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/); |
|---|
| 311 | for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1) |
|---|
| 312 | isiswctab[ansiactab[isiswctot]]=1; |
|---|
| 313 | } else { |
|---|
| 314 | unsigned char acbuff[256]; |
|---|
| 315 | if (!loaductb(NULL,isisuctab,useruppercase)) fatal(p); |
|---|
| 316 | if (!loadactb(NULL,acbuff,useruppercase)) fatal(p); |
|---|
| 317 | for (isiswctot=0; acbuff[isiswctot]; isiswctot=isiswctot+1) |
|---|
| 318 | isiswctab[acbuff[isiswctot]]=1; |
|---|
| 319 | } |
|---|
| 320 | continue; |
|---|
| 321 | } |
|---|
| 322 | if (strncmp(p,"maxrf?",6) == 0 || strncmp(p,"maxrf=",6) == 0) { |
|---|
| 323 | if (sscanf(p+6,"%f",&usermaxrf) != 1) fatal(p); |
|---|
| 324 | if (usermaxrf <= 0 || usermaxrf > 1.0) fatal(p); |
|---|
| 325 | continue; |
|---|
| 326 | } |
|---|
| 327 | if (strncmp(p,"maxtv?",6) == 0 || strncmp(p,"maxtv=",6) == 0) { |
|---|
| 328 | if (sscanf(p+6,"%d",&usermaxtv) != 1) fatal(p); |
|---|
| 329 | if (usermaxtv < 1) fatal(p); |
|---|
| 330 | continue; |
|---|
| 331 | } |
|---|
| 332 | if (strncmp(p,"K?",2) == 0 || strncmp(p,"K=",2) == 0) { |
|---|
| 333 | if (sscanf(p+2,"%"_LD_,&usercategories) != 1) fatal(p); |
|---|
| 334 | if (usercategories < 1) fatal(p); |
|---|
| 335 | continue; |
|---|
| 336 | } |
|---|
| 337 | if (strncmp(p,"N?",2) == 0 || strncmp(p,"N=",2) == 0) { |
|---|
| 338 | if (sscanf(p+2,"%"_LD_,&usercollectionsize) != 1) fatal(p); |
|---|
| 339 | if (usercollectionsize <= 0) fatal(p); |
|---|
| 340 | continue; |
|---|
| 341 | } |
|---|
| 342 | if (strncmp(p,"collection?",11) == 0 || strncmp(p,"collection=",11) == 0 || |
|---|
| 343 | strncmp(p,"c?",2) == 0 || strncmp(p,"c=",2) == 0) { |
|---|
| 344 | if (strncmp(p,"c?",2) == 0 || strncmp(p,"c=",2) == 0) collectiondb=p+2; |
|---|
| 345 | else collectiondb=p+11; |
|---|
| 346 | if (!*collectiondb) fatal(p); |
|---|
| 347 | continue; |
|---|
| 348 | } |
|---|
| 349 | if (strncmp(p,"col.c?",6) == 0 || strncmp(p,"col.c=",6) == 0) { |
|---|
| 350 | q=p+6; if (!*q) fatal(p); |
|---|
| 351 | strcpy(collectionsizedb,q); |
|---|
| 352 | continue; |
|---|
| 353 | } |
|---|
| 354 | if (strncmp(p,"col.n?",5) == 0 || strncmp(p,"col.n=",6) == 0) { |
|---|
| 355 | q=p+6; if (!*q) fatal(p); |
|---|
| 356 | strcpy(collectionoccsdb,q); |
|---|
| 357 | continue; |
|---|
| 358 | } |
|---|
| 359 | if (strncmp(p,"out.c?",6) == 0 || strncmp(p,"out.c=",6) == 0) { |
|---|
| 360 | q=p+6; if (!*q) fatal(p); |
|---|
| 361 | strcpy(outcollectionsizedb,q); |
|---|
| 362 | continue; |
|---|
| 363 | } |
|---|
| 364 | if (strncmp(p,"out.n?",6) == 0 || strncmp(p,"out.n=",6) == 0) { |
|---|
| 365 | q=p+6; if (!*q) fatal(p); |
|---|
| 366 | strcpy(outcollectionoccsdb,q); |
|---|
| 367 | continue; |
|---|
| 368 | } |
|---|
| 369 | if (strncmp(p,"out.v?",6) == 0 || strncmp(p,"out.v=",6) == 0) { |
|---|
| 370 | q=p+6; if (!*q) fatal(p); |
|---|
| 371 | strcpy(outtermvectorsdb,q); |
|---|
| 372 | continue; |
|---|
| 373 | } |
|---|
| 374 | if (strncmp(p,"out.x?",6) == 0 || strncmp(p,"out.x=",6) == 0) { |
|---|
| 375 | q=p+6; if (!*q) fatal(p); |
|---|
| 376 | strcpy(outterminverteddb,q); |
|---|
| 377 | continue; |
|---|
| 378 | } |
|---|
| 379 | if (strcmp(p,"dmfn") == 0) { |
|---|
| 380 | parmdtag=1; |
|---|
| 381 | dtagc1='\r'; |
|---|
| 382 | dtagc2='\n'; |
|---|
| 383 | continue; |
|---|
| 384 | } |
|---|
| 385 | if (strcmp(p,"6words") == 0) { |
|---|
| 386 | parm6words=1; |
|---|
| 387 | parmdtag=1; |
|---|
| 388 | dtagc1='\r'; |
|---|
| 389 | dtagc2='\n'; |
|---|
| 390 | continue; |
|---|
| 391 | } |
|---|
| 392 | if (strncmp(p,"exclude?",8) == 0 || strncmp(p,"exclude=",8) == 0) { |
|---|
| 393 | q=p+8; if (!*q) fatal(p); |
|---|
| 394 | strcpy(parmexcludedb,q); |
|---|
| 395 | continue; |
|---|
| 396 | } |
|---|
| 397 | if (strcmp(p,"bin") == 0) { |
|---|
| 398 | parmwritebin=1; |
|---|
| 399 | continue; |
|---|
| 400 | } |
|---|
| 401 | if (strcmp(p,"-relloc") == 0) { |
|---|
| 402 | parmrelloc=0; |
|---|
| 403 | continue; |
|---|
| 404 | } |
|---|
| 405 | if (strcmp(p,"-sort") == 0) { |
|---|
| 406 | parmsort=0; |
|---|
| 407 | continue; |
|---|
| 408 | } |
|---|
| 409 | if (strcmp(p,"+hash") == 0) { |
|---|
| 410 | parmshowh=1; |
|---|
| 411 | continue; |
|---|
| 412 | } |
|---|
| 413 | if (strncmp(p,"tell?",5) == 0 || strncmp(p,"tell=",5) == 0) { |
|---|
| 414 | if (sscanf(p+5,"%"_LD_,&parmtell) != 1) fatal(p); |
|---|
| 415 | parmtell2=parmtell; |
|---|
| 416 | continue; |
|---|
| 417 | } |
|---|
| 418 | if (strncmp(p,"tell2?",6) == 0 || strncmp(p,"tell2=",6) == 0) { |
|---|
| 419 | if (sscanf(p+6,"%"_LD_,&parmtell2) != 1) fatal(p); |
|---|
| 420 | continue; |
|---|
| 421 | } |
|---|
| 422 | if (strncmp(p,"trace?",6) == 0 || strncmp(p,"trace=",6) == 0) { |
|---|
| 423 | if (sscanf(p+6,"%d",&parmtrace) != 1) fatal(p); |
|---|
| 424 | continue; |
|---|
| 425 | } |
|---|
| 426 | if (strncmp(p,"from=",5) == 0) { |
|---|
| 427 | if (sscanf(p+5,"%"_LD_,&parmfrom) != 1) |
|---|
| 428 | fatal(p); |
|---|
| 429 | continue; |
|---|
| 430 | } |
|---|
| 431 | if (strncmp(p,"to=",3) == 0) { |
|---|
| 432 | if (sscanf(p+3,"%"_LD_,&parmto) != 1) |
|---|
| 433 | fatal(p); |
|---|
| 434 | continue; |
|---|
| 435 | } |
|---|
| 436 | if (strncmp(p,"loop=",5) == 0) { |
|---|
| 437 | if (sscanf(p+5,"%"_LD_,&parmloop) != 1) |
|---|
| 438 | fatal(p); |
|---|
| 439 | continue; |
|---|
| 440 | } |
|---|
| 441 | if (strncmp(p,"count=",6) == 0) { |
|---|
| 442 | if (sscanf(p+6,"%"_LD_,&parmcount) != 1) |
|---|
| 443 | fatal(p); |
|---|
| 444 | continue; |
|---|
| 445 | } |
|---|
| 446 | fatal(p); |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | /* check mandatory parms */ |
|---|
| 450 | if (!parmdocumentsdb) fatal("wtrig1: missing documents= parameter"); |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | /* program limitation: check COUNT[hidx] > COLLECTION[hidx] */ |
|---|
| 454 | if (collectiondb) if (*outterminverteddb) if (strcmp(outterminverteddb, "void") != 0) fatal("collection x out.x"); |
|---|
| 455 | /* parmsort optimization */ |
|---|
| 456 | if (collectiondb) if (*outcollectionoccsdb) if (strcmp(outcollectionoccsdb,"void") != 0) fatal("collection x out.n"); |
|---|
| 457 | /* disable parmsort */ |
|---|
| 458 | if (collectiondb) parmsort=0; |
|---|
| 459 | |
|---|
| 460 | indocumentsdb=documentsdb=strdup(parmdocumentsdb); |
|---|
| 461 | if ((p=strchr(indocumentsdb,',')) != NULL) { |
|---|
| 462 | *p='\0'; |
|---|
| 463 | documentsdb=p+1; |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | /* set input file names |
|---|
| 467 | */ |
|---|
| 468 | if (collectiondb) { |
|---|
| 469 | if (!*collectionsizedb) sprintf(collectionsizedb, "%s.c",collectiondb); |
|---|
| 470 | if (!*collectionoccsdb) sprintf(collectionoccsdb, "%s.n",collectiondb); |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | /* set output file names |
|---|
| 474 | */ |
|---|
| 475 | if (!*outcollectionsizedb) sprintf(outcollectionsizedb,"%s.c",documentsdb); |
|---|
| 476 | if (!collectiondb) { |
|---|
| 477 | if (!*outcollectionoccsdb) sprintf(outcollectionoccsdb,"%s.n",documentsdb); |
|---|
| 478 | if (!*outterminverteddb) sprintf(outterminverteddb, "%s.x",documentsdb); |
|---|
| 479 | } |
|---|
| 480 | if (!*outtermvectorsdb) sprintf(outtermvectorsdb, "%s.v",documentsdb); |
|---|
| 481 | |
|---|
| 482 | /* void file names */ |
|---|
| 483 | if (strcmp(outcollectionsizedb,"void") == 0) outcollectionsizedb[0]='\0'; |
|---|
| 484 | if (strcmp(outcollectionoccsdb,"void") == 0) outcollectionoccsdb[0]='\0'; |
|---|
| 485 | if (strcmp(outterminverteddb, "void") == 0) outterminverteddb[0]='\0'; |
|---|
| 486 | if (strcmp(outtermvectorsdb, "void") == 0) outtermvectorsdb[0]='\0'; |
|---|
| 487 | //if (strcmp(outtermvectorsdb,"void") == 0) fatal(p); |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | /* alloc working areas |
|---|
| 491 | */ |
|---|
| 492 | irec=nrecs; |
|---|
| 493 | p=dbxcipar(NULL,"maxmfrl",'='); if (dbxcipok) sscanf(p,"%"_LD_,&rec_maxmfrl); |
|---|
| 494 | if (rec_maxmfrl < (LONGX)MSNVSPLT || (RECHSIZE+rec_maxmfrl) > ALLOMAXV) rec_maxmfrl=MAXMFRL; |
|---|
| 495 | recallok(irec,rec_maxmfrl); |
|---|
| 496 | zirec=nrecs; |
|---|
| 497 | recallok(zirec,rec_maxmfrl); |
|---|
| 498 | crec=nrecs; |
|---|
| 499 | recallok(crec,sizeof(M0STRU)); |
|---|
| 500 | crec2=nrecs; |
|---|
| 501 | recallok(crec2,sizeof(M0STRU)); |
|---|
| 502 | |
|---|
| 503 | buff=loadfile(NULL,'@',"",NULL,buffsize=rec_maxmfrl*2,'\0'); |
|---|
| 504 | dtagbuff=loadfile(NULL,'@',"",NULL,buffsize,'\0'); |
|---|
| 505 | |
|---|
| 506 | /* here we go |
|---|
| 507 | */ |
|---|
| 508 | |
|---|
| 509 | /* set processing record */ |
|---|
| 510 | RECORD(zirec,"null",1L); /*MFRstatus=ACTIVE;*/ |
|---|
| 511 | |
|---|
| 512 | /* read maxmfn */ |
|---|
| 513 | RECORD(irec,indocumentsdb,0); |
|---|
| 514 | maxmfn=MF0nxtmfn-1; |
|---|
| 515 | |
|---|
| 516 | /* set collection size: N */ |
|---|
| 517 | COLLECTION_SIZE=maxmfn; |
|---|
| 518 | if (usercollectionsize) COLLECTION_SIZE=usercollectionsize; |
|---|
| 519 | |
|---|
| 520 | /* set other parms */ |
|---|
| 521 | if (usertag) parmtag=usertag; |
|---|
| 522 | |
|---|
| 523 | if (userwidth) { |
|---|
| 524 | parmwidth=userwidth; |
|---|
| 525 | trigrams=0; |
|---|
| 526 | } |
|---|
| 527 | else { |
|---|
| 528 | parmwidth=4; /* [][][][2] */ |
|---|
| 529 | trigrams=1; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | if (useruppercase) parmuppercase=useruppercase; |
|---|
| 533 | if (usermaxrf) parmmaxrf=usermaxrf; |
|---|
| 534 | if (usermaxtv) parmmaxtv=usermaxtv; |
|---|
| 535 | if (usercategories) parmcategories=usercategories; |
|---|
| 536 | |
|---|
| 537 | /* read collection info */ |
|---|
| 538 | if (*collectionsizedb) { |
|---|
| 539 | UWORD readtag=0; |
|---|
| 540 | int readwidth=0; |
|---|
| 541 | char *readuppercase=NULL; |
|---|
| 542 | float readmaxrf=0; |
|---|
| 543 | //LONGX readmaxprim=0; |
|---|
| 544 | int readmaxtv=0; |
|---|
| 545 | LONGX readcategories=0; |
|---|
| 546 | int readtrigrams=0; |
|---|
| 547 | |
|---|
| 548 | RECORD(irec,collectionsizedb,1); |
|---|
| 549 | if (RECrc != RCNORMAL) fatal("wtrig1/COLLECTION_SIZE/RCNORMAL"); |
|---|
| 550 | |
|---|
| 551 | /* read parms */ |
|---|
| 552 | for (iocc=1; *recfield(buff,irec,TAG1,iocc,""); iocc++) { |
|---|
| 553 | q="^nextract^v"; |
|---|
| 554 | p=strstr(buff,q); if (p) |
|---|
| 555 | if (isdigit(*(p+strlen(q)))) { |
|---|
| 556 | readtag=(UWORD)atol(p+strlen(q)); |
|---|
| 557 | } |
|---|
| 558 | else { |
|---|
| 559 | readextractfmta=loadfile(NULL,'@',p+strlen(q),NULL,0,'\0'); |
|---|
| 560 | if (!readextractfmta) fatal(buff); |
|---|
| 561 | if (fmt_gener(&readextractfmtp,readextractfmta)) fatal(readextractfmta+fmt_errof); |
|---|
| 562 | } |
|---|
| 563 | q="^nwidth^v"; |
|---|
| 564 | p=strstr(buff,q); if (p) readwidth=atoi(p+strlen(q)); |
|---|
| 565 | q="^ttrigrams"; |
|---|
| 566 | p=strstr(buff,q); if (p) readtrigrams=1; |
|---|
| 567 | q="^ncase^v"; |
|---|
| 568 | p=strstr(buff,q); if (p) readuppercase=p; |
|---|
| 569 | q="^nmaxrf^v"; |
|---|
| 570 | p=strstr(buff,q); if (p) readmaxrf=atof(p+strlen(q)); |
|---|
| 571 | q="^nmaxtv^v"; |
|---|
| 572 | p=strstr(buff,q); if (p) readmaxtv=atoi(p+strlen(q)); |
|---|
| 573 | q="^nK^v"; |
|---|
| 574 | p=strstr(buff,q); if (p) readcategories=atol(p+strlen(q)); |
|---|
| 575 | } |
|---|
| 576 | readcollectionsize=atol(recfield(buff,irec,TAG2,1,"")); |
|---|
| 577 | |
|---|
| 578 | if (readtag) if (readextractfmtp) fatal("wtrig1/collectin/extract=tag/extract=fmt"); |
|---|
| 579 | if (!usercollectionsize) COLLECTION_SIZE=readcollectionsize; |
|---|
| 580 | if (!usertag) if (!extractfmtp) { |
|---|
| 581 | if (readextractfmtp) { |
|---|
| 582 | extractfmta=readextractfmta; |
|---|
| 583 | extractfmtp=readextractfmtp; |
|---|
| 584 | } |
|---|
| 585 | else parmtag=readtag; |
|---|
| 586 | } |
|---|
| 587 | if (!userwidth) { parmwidth=readwidth; trigrams=readtrigrams; } |
|---|
| 588 | if (!useruppercase) parmuppercase=strdup(readuppercase); |
|---|
| 589 | if (!usermaxrf) parmmaxrf=readmaxrf; |
|---|
| 590 | if (!usermaxtv) parmmaxtv=readmaxtv; |
|---|
| 591 | if (!usercategories) parmcategories=readcategories; |
|---|
| 592 | } |
|---|
| 593 | |
|---|
| 594 | /* check collection size x document maxmfn */ |
|---|
| 595 | if (COLLECTION_SIZE < maxmfn) fatal("wtrig1/COLLECTION_SIZE"); |
|---|
| 596 | |
|---|
| 597 | /* check parmtag x format */ |
|---|
| 598 | if (parmtag) if (extractfmtp) fatal("wtrig1/extract=tag/extract=fmt"); |
|---|
| 599 | if (!parmtag) if (!extractfmtp) fatal("wtrig1/missing extract="); |
|---|
| 600 | if (extractfmtp) parmtag=999; |
|---|
| 601 | |
|---|
| 602 | /* setup fldupdat() for input records |
|---|
| 603 | */ |
|---|
| 604 | if (!trigrams) { |
|---|
| 605 | sprintf(areacmd,"Gsplit=%"_LD_"=words",(LONGX)parmtag); |
|---|
| 606 | } |
|---|
| 607 | else { |
|---|
| 608 | sprintf(areacmd,"Gsplit=%"_LD_"=trigrams",(LONGX)parmtag); |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | /* setup fldupdat() for 6-word window indexing |
|---|
| 612 | */ |
|---|
| 613 | if (parm6words) { |
|---|
| 614 | sprintf(areacmd6words, "Gsplit=%"_LD_"=6words",(LONGX)parmtag); |
|---|
| 615 | sprintf(areacmd6words2,"Gsplit=%"_LD_, (LONGX)parmtag); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | /* alloc itrm: do not read postings */ |
|---|
| 619 | if (*parmexcludedb) { |
|---|
| 620 | trmalloc(itrm=ntrms,0L); |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | /* calculate maxprim and allocate hash table |
|---|
| 624 | */ |
|---|
| 625 | table=hashalloc(parmcategories,parmwidth,&maxprim); |
|---|
| 626 | if (parmtrace2) printf("+++ hash=%"_LD_"\n",maxprim); |
|---|
| 627 | hwidth=(parmwidth+1); |
|---|
| 628 | |
|---|
| 629 | /* allocate list of relevant terms |
|---|
| 630 | */ |
|---|
| 631 | lista= (LISTAWT1 *)loadfile(NULL,'@',"",NULL, parmmaxtv*sizeof(LISTAWT1),'\0'); |
|---|
| 632 | |
|---|
| 633 | /* allocate frequencies and weights |
|---|
| 634 | */ |
|---|
| 635 | COLLECTION= (LONGX *) loadfile(NULL,'@',"",NULL, maxprim*sizeof(LONGX), '\0'); |
|---|
| 636 | DOCUMENT= (int *) loadfile(NULL,'@',"",NULL, maxprim*sizeof(int), '\0'); |
|---|
| 637 | GLOBALWEIGHT= (float *)loadfile(NULL,'@',"",NULL, maxprim*sizeof(float), '\0'); |
|---|
| 638 | PRODWEIGHT= (float *)loadfile(NULL,'@',"",NULL, maxprim*sizeof(float), '\0'); |
|---|
| 639 | |
|---|
| 640 | INDEX= (LONGX *) loadfile(NULL,'@',"",NULL, maxprim*sizeof(LONGX), '\0'); |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | /* get term docs in collection: n(t) */ |
|---|
| 644 | memset(COLLECTION,0x00,maxprim*sizeof(LONGX)); |
|---|
| 645 | if (*collectionoccsdb) { |
|---|
| 646 | /* read term docs in collection from file */ |
|---|
| 647 | for (mfn=1; ; mfn++) { |
|---|
| 648 | RECORD(irec,collectionoccsdb,mfn); |
|---|
| 649 | if (RECrc == RCEOF) break; |
|---|
| 650 | if (RECrc != RCNORMAL) continue; |
|---|
| 651 | for (dirp=MFRdir, xdir=0, loop=MFRnvf; loop--; dirp++, xdir++) { |
|---|
| 652 | if (dirp->tag != TAG3) continue; |
|---|
| 653 | if (dirp->len == 0) continue; |
|---|
| 654 | for (keylen=0, p=fldp=FIELDP(xdir), left=dirp->len; left; ) { |
|---|
| 655 | if (*p == '^') break; |
|---|
| 656 | keylen++; p++; left--; |
|---|
| 657 | } |
|---|
| 658 | n=0; |
|---|
| 659 | if (left > 2) if (*p++ == '^') if (*p++ == 'n') { /* ^n */ |
|---|
| 660 | left=left-2; |
|---|
| 661 | while (left) { |
|---|
| 662 | if (!isdigit(*p)) break; |
|---|
| 663 | n=n*10+((int)(*p)-(int)'0'); |
|---|
| 664 | p++; left--; |
|---|
| 665 | } |
|---|
| 666 | } |
|---|
| 667 | hidx=hashindex(table,maxprim,parmwidth,fldp,keylen,&found,1); |
|---|
| 668 | if (found) fatal("wtrig1/TAG3/duplicated"); |
|---|
| 669 | COLLECTION[hidx]=n; |
|---|
| 670 | } |
|---|
| 671 | } |
|---|
| 672 | } |
|---|
| 673 | else { |
|---|
| 674 | /* read all records to build term docs in collection*/ |
|---|
| 675 | FFI dtagfldlen=0; |
|---|
| 676 | unsigned char *dtagfldp; |
|---|
| 677 | unsigned char *dtagp; |
|---|
| 678 | LONGX countcollection=0; |
|---|
| 679 | count=xcount=xcountrecs=0; xpcount=0; |
|---|
| 680 | for (mfn=parmfrom; ; mfn+=parmloop) { |
|---|
| 681 | if (parmto) if (mfn > parmto) break; |
|---|
| 682 | if (parmcount) if (xpcount++ >= parmcount) break; |
|---|
| 683 | |
|---|
| 684 | RECORD(irec,indocumentsdb,mfn); |
|---|
| 685 | if (RECrc == RCEOF) break; |
|---|
| 686 | if (RECrc != RCNORMAL) { /* skip deleted / inexistent */ |
|---|
| 687 | xcount++; |
|---|
| 688 | continue; |
|---|
| 689 | } |
|---|
| 690 | /* process extract=<fmt> */ |
|---|
| 691 | #if PARMDTAG |
|---|
| 692 | if (extractfmtp) |
|---|
| 693 | fmt_inter(extractfmtp,irec,buffsize,dtagbuff,buffsize); |
|---|
| 694 | else |
|---|
| 695 | recfield(dtagbuff,irec,parmtag,1,""); |
|---|
| 696 | #else /* PARMDTAG */ |
|---|
| 697 | if (extractfmtp) { |
|---|
| 698 | char *lenp=buff+7; |
|---|
| 699 | int x=17; |
|---|
| 700 | /* +012345678901234567 */ |
|---|
| 701 | sprintf(buff,"d*H999 xxxxxxxxx "); |
|---|
| 702 | fmt_inter(extractfmtp,irec,buffsize-x-1,buff+x,buffsize-x-1); |
|---|
| 703 | sprintf(lenp,"%9"_LD_,(LONGX)strlen(buff+x)); buff[x-1]=' '; |
|---|
| 704 | if (fldupdat(irec,buff)) fatal(buff); |
|---|
| 705 | } |
|---|
| 706 | #endif /* PARMDTAG */ |
|---|
| 707 | #if PARMDTAG |
|---|
| 708 | /**/ |
|---|
| 709 | /* process each line */ |
|---|
| 710 | for (dtagfldlen=0, dtagp=dtagfldp=dtagbuff; ; ) { |
|---|
| 711 | if (!*dtagp || *dtagp == dtagc1 || *dtagp == dtagc2) { |
|---|
| 712 | /* empty record */ |
|---|
| 713 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 714 | if (dtagfldlen) { |
|---|
| 715 | char *p=dtagfldp; |
|---|
| 716 | FFI langlen=0; |
|---|
| 717 | if (dtagfldlen >= 2) if (*p++ == '^') if (*p++ == 'l') { |
|---|
| 718 | FFI skip=2; |
|---|
| 719 | FFI left=dtagfldlen-skip; |
|---|
| 720 | while (left--) { |
|---|
| 721 | if (*p++ == '^') { |
|---|
| 722 | skip++; if (*p == 'x') skip++; |
|---|
| 723 | break; |
|---|
| 724 | } |
|---|
| 725 | langlen++; |
|---|
| 726 | } |
|---|
| 727 | skip+=langlen; |
|---|
| 728 | dtagfldlen-=skip; |
|---|
| 729 | dtagfldp+=skip; |
|---|
| 730 | } |
|---|
| 731 | p=buff; |
|---|
| 732 | sprintf(p,"H%"_LD_" %"_LD_" ",(LONGX)parmtag,(LONGX)dtagfldlen); p+=strlen(p); |
|---|
| 733 | memcpy(p,dtagfldp,dtagfldlen); *(p+=dtagfldlen)='\0'; dtagfldlen=0; |
|---|
| 734 | if (fldupdat(irec,buff)) fatal("wtrig1/dtag/fldupdat/1"); |
|---|
| 735 | /**/ |
|---|
| 736 | #endif /* PARMDTAG */ |
|---|
| 737 | |
|---|
| 738 | /* process extract proc Gsplit=tag=6words */ |
|---|
| 739 | if (parm6words) { |
|---|
| 740 | //prtfields(recp,1); |
|---|
| 741 | if (fldupdat(irec,areacmd6words)) fatal(areacmd6words); |
|---|
| 742 | //prtfields(recp,2); |
|---|
| 743 | if (fldupdat(irec,areacmd6words2)) fatal(areacmd6words2); |
|---|
| 744 | //prtfields(recp,3); |
|---|
| 745 | //printf("++++\n"); |
|---|
| 746 | /*getchar();*/ |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | #if PARMDTAG6W |
|---|
| 750 | /*2*/ |
|---|
| 751 | /* for each 6words line |
|---|
| 752 | */ |
|---|
| 753 | for (zdirp=MFRdir, zxdir=0, zloop=MFRnvf; zloop--; zdirp++, zxdir++) { |
|---|
| 754 | char *zp; |
|---|
| 755 | if (zdirp->tag != parmtag) continue; |
|---|
| 756 | zfldp=FIELDP(zxdir); |
|---|
| 757 | if (*parmexcludedb) { |
|---|
| 758 | TRMSTRU *trmp; |
|---|
| 759 | unsigned char *p,*q; |
|---|
| 760 | int ucloop; |
|---|
| 761 | for (q=buff, p=(unsigned char *)zfldp, ucloop=zdirp->len; ucloop--; p++) *q++=isisuctab[*p]; |
|---|
| 762 | *q='\0'; |
|---|
| 763 | TERM(itrm,parmexcludedb,buff); |
|---|
| 764 | if (TRMrc == RCNORMAL) zfldp=NULL; |
|---|
| 765 | } |
|---|
| 766 | /* build trigrec */ |
|---|
| 767 | zp=buff; |
|---|
| 768 | sprintf(zp,"D*"); zp+=strlen(zp); |
|---|
| 769 | if (zfldp) { |
|---|
| 770 | sprintf(zp,"H%"_LD_" %"_LD_" ",(LONGX)parmtag,(LONGX)zdirp->len); zp+=strlen(zp); |
|---|
| 771 | memcpy(zp,zfldp,zdirp->len); *(zp+zdirp->len)='\0'; |
|---|
| 772 | } |
|---|
| 773 | if (fldupdat(zirec,buff)) fatal("wtrig1/line/fldupdat/1"); |
|---|
| 774 | //prtfields(vrecp[zirec],4); //debug// |
|---|
| 775 | /*2*/ |
|---|
| 776 | #endif /* PARMDTAG6W */ |
|---|
| 777 | |
|---|
| 778 | /* process extract proc Gsplit=tag={trigrams|words} */ |
|---|
| 779 | if (fldupdat(zirec,areacmd)) fatal(areacmd); |
|---|
| 780 | //prtfields(vrecp[zirec],5); |
|---|
| 781 | |
|---|
| 782 | xcountrecs++; /* count it <=== */ |
|---|
| 783 | memset(DOCUMENT,0x00,maxprim*sizeof(int)); |
|---|
| 784 | for (dirp=VMFRdir(zirec), xdir=0, loop=VMFRnvf(zirec); loop--; dirp++, xdir++) { |
|---|
| 785 | int ucloop; |
|---|
| 786 | unsigned char *p; |
|---|
| 787 | if (dirp->tag != parmtag) continue; |
|---|
| 788 | fldp=VFIELDP(zirec,xdir); |
|---|
| 789 | /* convert words to upper case */ |
|---|
| 790 | if (!trigrams) if (parmuppercase) |
|---|
| 791 | for (p=(unsigned char *)fldp, ucloop=dirp->len; ucloop--; p++) *p=isisuctab[*p]; |
|---|
| 792 | hidx=hashindex(table,maxprim,parmwidth,fldp,dirp->len,&found,1); |
|---|
| 793 | if (parmtrace & 0x01) { |
|---|
| 794 | printf(" 1|%"_LD_"|%s\n",mfn,table+hidx*hwidth); |
|---|
| 795 | } |
|---|
| 796 | if (!DOCUMENT[hidx]) { |
|---|
| 797 | DOCUMENT[hidx]++; COLLECTION[hidx]++; |
|---|
| 798 | } |
|---|
| 799 | } |
|---|
| 800 | countcollection++; |
|---|
| 801 | |
|---|
| 802 | #if PARMDTAG6W |
|---|
| 803 | /*2*/ |
|---|
| 804 | } /* end for each 6words line */ |
|---|
| 805 | /*2*/ |
|---|
| 806 | #endif /* PARMDTAG6W */ |
|---|
| 807 | #if PARMDTAG |
|---|
| 808 | /**/ |
|---|
| 809 | } /* end if dtagfldlen */ /* process each line */ |
|---|
| 810 | if (parmdtag) while (*dtagp == dtagc1 || *dtagp == dtagc2) dtagp++; |
|---|
| 811 | dtagfldp=dtagp; dtagfldlen=0; |
|---|
| 812 | if (!*dtagfldp) break; |
|---|
| 813 | } |
|---|
| 814 | else { |
|---|
| 815 | dtagp++; dtagfldlen++; |
|---|
| 816 | } |
|---|
| 817 | } /* end for dtagp */ |
|---|
| 818 | /**/ |
|---|
| 819 | #endif /* PARMDTAG */ |
|---|
| 820 | |
|---|
| 821 | count++; |
|---|
| 822 | if (parmtell) if (count%parmtell == 0) fprintf(stderr,"+ %"_LD_"+%"_LD_" +%"_LD_"\n",count,xcount,xcountrecs); |
|---|
| 823 | } |
|---|
| 824 | if (!usercollectionsize) if (!readcollectionsize) COLLECTION_SIZE=countcollection; |
|---|
| 825 | ///* check collection size x document maxmfn */ |
|---|
| 826 | //if (countcollection < COLLECTION_SIZE < maxmfn) fatal("wtrig1/countcollection"); |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | if (parmtrace & 0x02) { |
|---|
| 830 | printf(" 2| |%"_LD_"\n",COLLECTION_SIZE); |
|---|
| 831 | } |
|---|
| 832 | |
|---|
| 833 | /* discart frequent terms |
|---|
| 834 | */ |
|---|
| 835 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 836 | LONGX n; |
|---|
| 837 | if (!*h) continue; |
|---|
| 838 | n=COLLECTION[hidx]; |
|---|
| 839 | if (parmtrace & 0x02) |
|---|
| 840 | if (COLLECTION[hidx]) |
|---|
| 841 | printf(" 2|%s|%"_LD_"\n",h,COLLECTION[hidx]); |
|---|
| 842 | #if DISCART |
|---|
| 843 | if (parmmaxrf != 1.0) { |
|---|
| 844 | if ((float)n/COLLECTION_SIZE > parmmaxrf) { |
|---|
| 845 | memset(h,0x00,strlen(h)); |
|---|
| 846 | COLLECTION[hidx]=0; |
|---|
| 847 | } |
|---|
| 848 | } |
|---|
| 849 | #endif /* DISCART */ |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | /* step 1: calculate global weights |
|---|
| 854 | */ |
|---|
| 855 | /* calculate */ |
|---|
| 856 | memset(GLOBALWEIGHT,0x00,maxprim*sizeof(float)); |
|---|
| 857 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 858 | if (*h) if (COLLECTION[hidx]) { |
|---|
| 859 | double lognum = (double)COLLECTION_SIZE; |
|---|
| 860 | double logden = (double)COLLECTION[hidx]; |
|---|
| 861 | GLOBALWEIGHT[hidx] = (float)sqrt(log(lognum/logden)); |
|---|
| 862 | } |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | /* discart terms with weight=0.00 |
|---|
| 867 | */ |
|---|
| 868 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 869 | int parmdiscartgw0=0; |
|---|
| 870 | if (!*h) continue; |
|---|
| 871 | #if DISCART |
|---|
| 872 | if (parmmaxrf == 1.0) if (parmdiscartgw0) { |
|---|
| 873 | if (GLOBALWEIGHT[hidx] == 0.00) { |
|---|
| 874 | memset(h,0x00,strlen(h)); |
|---|
| 875 | COLLECTION[hidx]=0; |
|---|
| 876 | } |
|---|
| 877 | } |
|---|
| 878 | #endif /* DISCART */ |
|---|
| 879 | if (COLLECTION[hidx]) |
|---|
| 880 | if (parmtrace & 0x04) |
|---|
| 881 | printf(" 4|%s|%"_LD_"|%f\n",h,COLLECTION[hidx],GLOBALWEIGHT[hidx]); |
|---|
| 882 | } |
|---|
| 883 | |
|---|
| 884 | /* get secs_ for elapsed */ |
|---|
| 885 | secs_1=time(&secs_now); |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | /* setup output term vectors |
|---|
| 889 | */ |
|---|
| 890 | if (*outtermvectorsdb) { |
|---|
| 891 | if (parmmaxtv*sizeof(LISTAWT1) > VRECnbytes(irec)-LEADER-sizeof(DIRSTRU)) fatal("outtermvectordb/maxmfrl overflow"); |
|---|
| 892 | recisis0(outtermvectorsdb); |
|---|
| 893 | record(crec,outtermvectorsdb,0L); |
|---|
| 894 | RECORD(zirec,outtermvectorsdb,1L); MFRstatus=ACTIVE; |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | /* setup output term inverted file |
|---|
| 898 | */ |
|---|
| 899 | if (*outterminverteddb) { |
|---|
| 900 | LONGX *collecp=COLLECTION; |
|---|
| 901 | LONGX HK=0; |
|---|
| 902 | LONGX off=0; |
|---|
| 903 | recisis0(outterminverteddb); |
|---|
| 904 | RECORD(crec2,outterminverteddb,0L); |
|---|
| 905 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth, collecp++) { |
|---|
| 906 | if (*h) HK+= *collecp; |
|---|
| 907 | } |
|---|
| 908 | OFFSET= (LONGX *) loadfile(NULL,'@',"",NULL, maxprim*sizeof(LONGX), '\0'); |
|---|
| 909 | COUNT= (LONGX *) loadfile(NULL,'@',"",NULL, maxprim*sizeof(LONGX), '\0'); |
|---|
| 910 | POSTINGS= (LONGX *) loadfile(NULL,'@',"",NULL, HK*sizeof(LONGX), '\0'); |
|---|
| 911 | memset(OFFSET,0x00,maxprim*sizeof(LONGX)); |
|---|
| 912 | memset(COUNT,0x00,maxprim*sizeof(LONGX)); |
|---|
| 913 | memset(POSTINGS,0x00,HK*sizeof(LONGX)); |
|---|
| 914 | collecp=COLLECTION; |
|---|
| 915 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 916 | if (*h) { OFFSET[hidx]=off; off+=COLLECTION[hidx]; } |
|---|
| 917 | } |
|---|
| 918 | //for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) |
|---|
| 919 | // if (*h) printf("OFFSET=%"_LD_" %"_LD_" h=%"_LD_"=%s\n",OFFSET[hidx],COLLECTION[hidx],hidx,h); |
|---|
| 920 | } |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | /* -------------------------------------------------- |
|---|
| 925 | step2: read all records to calculate local weights |
|---|
| 926 | */ |
|---|
| 927 | /* step2: read all records to calculate local weights |
|---|
| 928 | */ |
|---|
| 929 | countcollection=0; |
|---|
| 930 | countok=xcount=ycount=0; xpcount=0; |
|---|
| 931 | |
|---|
| 932 | if (!*outtermvectorsdb) parmx12345=0; |
|---|
| 933 | |
|---|
| 934 | if (parmx12345) { /* 12345 */ |
|---|
| 935 | |
|---|
| 936 | for (docmfn=parmfrom; ; docmfn+=parmloop) { |
|---|
| 937 | LISTAWT1 *listhdr,*listtail,*avail,*l; |
|---|
| 938 | LONGX zcount,zcount2; |
|---|
| 939 | int *docump; |
|---|
| 940 | float soma2,fator,invsqrts2; |
|---|
| 941 | float *prodp; |
|---|
| 942 | |
|---|
| 943 | FFI dtagfldlen=0; |
|---|
| 944 | unsigned char *dtagfldp; |
|---|
| 945 | unsigned char *dtagp; |
|---|
| 946 | |
|---|
| 947 | if (parmto) if (mfn > parmto) break; |
|---|
| 948 | if (parmcount) if (xpcount++ >= parmcount) break; |
|---|
| 949 | |
|---|
| 950 | /* read indocument */ |
|---|
| 951 | RECORD(irec,indocumentsdb,docmfn); |
|---|
| 952 | if (RECrc == RCEOF) break; |
|---|
| 953 | if (RECrc != RCNORMAL) { /* skip deleted / inexistent */ |
|---|
| 954 | /*xcount++;*/ |
|---|
| 955 | continue; |
|---|
| 956 | } |
|---|
| 957 | |
|---|
| 958 | /* process extract=<fmt> */ |
|---|
| 959 | #if PARMDTAG |
|---|
| 960 | if (extractfmtp) |
|---|
| 961 | fmt_inter(extractfmtp,irec,buffsize,dtagbuff,buffsize); |
|---|
| 962 | else |
|---|
| 963 | recfield(dtagbuff,irec,parmtag,1,""); |
|---|
| 964 | #else /* PARMDTAG */ |
|---|
| 965 | if (extractfmtp) { |
|---|
| 966 | char *lenp=buff+7; |
|---|
| 967 | int x=17; |
|---|
| 968 | /* +012345678901234567 */ |
|---|
| 969 | sprintf(buff,"d*H999 xxxxxxxxx "); |
|---|
| 970 | fmt_inter(extractfmtp,irec,buffsize-x-1,buff+x,buffsize-x-1); |
|---|
| 971 | sprintf(lenp,"%9"_LD_,(LONGX)strlen(buff+x)); buff[x-1]=' '; |
|---|
| 972 | if (fldupdat(irec,buff)) fatal(buff); |
|---|
| 973 | } |
|---|
| 974 | #endif /* PARMDTAG */ |
|---|
| 975 | |
|---|
| 976 | #if PARMDTAG |
|---|
| 977 | /**/ |
|---|
| 978 | /* process each line |
|---|
| 979 | */ |
|---|
| 980 | for (dtagfldlen=0, dtagp=dtagfldp=dtagbuff; ; ) { |
|---|
| 981 | char zilang[BUFSIZ]={'\0'}; |
|---|
| 982 | int langidx=(-1); |
|---|
| 983 | if (!*dtagp || *dtagp == dtagc1 || *dtagp == dtagc2) { |
|---|
| 984 | /* empty record */ |
|---|
| 985 | MFRmfrl=MFRbase=LEADER; MFRnvf=0; |
|---|
| 986 | if (dtagfldlen) { |
|---|
| 987 | char *p=dtagfldp; |
|---|
| 988 | FFI langlen=0; |
|---|
| 989 | char *langp; |
|---|
| 990 | if (dtagfldlen >= 2) if (*p++ == '^') if (*p++ == 'l') { |
|---|
| 991 | FFI skip=2; |
|---|
| 992 | FFI left=dtagfldlen-skip; |
|---|
| 993 | langp=p; |
|---|
| 994 | while (left--) { |
|---|
| 995 | if (*p++ == '^') { |
|---|
| 996 | skip++; if (*p == 'x') skip++; |
|---|
| 997 | break; |
|---|
| 998 | } |
|---|
| 999 | langlen++; |
|---|
| 1000 | } |
|---|
| 1001 | skip+=langlen; |
|---|
| 1002 | dtagfldlen-=skip; |
|---|
| 1003 | dtagfldp+=skip; |
|---|
| 1004 | if (langlen>=BUFSIZ) langlen=BUFSIZ-1; |
|---|
| 1005 | memcpy(zilang,langp,langlen); zilang[langlen]='\0'; |
|---|
| 1006 | #if PARMLANG |
|---|
| 1007 | if (*zilang) { |
|---|
| 1008 | int xlang; |
|---|
| 1009 | /* search&store language */ |
|---|
| 1010 | langidx=(-1); |
|---|
| 1011 | for (xlang=0; xlang < nlangs; xlang++) { |
|---|
| 1012 | if (strcmp(zilang,langsname[xlang]) == 0) { langidx=xlang; break; } |
|---|
| 1013 | } |
|---|
| 1014 | if (langidx < 0) { |
|---|
| 1015 | /* allocate languages bit strings */ |
|---|
| 1016 | if (nlangs >= MAXPARMLANG) fatal("wtrig1/terminverted/MAXPARMLANG"); |
|---|
| 1017 | hitbytes=COLLECTION_SIZE/8+1; /* bit string size */ |
|---|
| 1018 | HITS= (char *)loadfile(NULL,'@',"",NULL,hitbytes,'\0'); |
|---|
| 1019 | /* init HIT list = documents having 1+ of document results in this lang */ |
|---|
| 1020 | memset(HITS,0x00,hitbytes); |
|---|
| 1021 | /* store */ |
|---|
| 1022 | langidx=nlangs; |
|---|
| 1023 | langshits[nlangs]=HITS; langsname[nlangs]=strdup(zilang); langscount[nlangs++]=0; |
|---|
| 1024 | } |
|---|
| 1025 | } |
|---|
| 1026 | #endif /* PARMLANG */ |
|---|
| 1027 | } |
|---|
| 1028 | p=buff; |
|---|
| 1029 | sprintf(p,"H%"_LD_" %"_LD_" ",(LONGX)parmtag,(LONGX)dtagfldlen); p+=strlen(p); |
|---|
| 1030 | memcpy(p,dtagfldp,dtagfldlen); *(p+=dtagfldlen)='\0'; dtagfldlen=0; |
|---|
| 1031 | if (fldupdat(irec,buff)) fatal("wtrig1/dtag/fldupdat/2"); |
|---|
| 1032 | /**/ |
|---|
| 1033 | #endif /* PARMDTAG */ |
|---|
| 1034 | |
|---|
| 1035 | /* process extract proc Gsplit=tag=6words */ |
|---|
| 1036 | if (parm6words) { |
|---|
| 1037 | if (fldupdat(irec,areacmd6words)) fatal(areacmd6words); |
|---|
| 1038 | if (fldupdat(irec,areacmd6words2)) fatal(areacmd6words2); |
|---|
| 1039 | } |
|---|
| 1040 | |
|---|
| 1041 | #if PARMDTAG6W |
|---|
| 1042 | /*2*/ |
|---|
| 1043 | /* for each 6words line |
|---|
| 1044 | */ |
|---|
| 1045 | for (zdirp=MFRdir, zxdir=0, zloop=MFRnvf; zloop--; zdirp++, zxdir++) { |
|---|
| 1046 | char *zp; |
|---|
| 1047 | FFI n; |
|---|
| 1048 | if (zdirp->tag != parmtag) continue; |
|---|
| 1049 | zfldp=FIELDP(zxdir); |
|---|
| 1050 | if (parmdtag) if (parmsavetext) { |
|---|
| 1051 | /* save original text */ |
|---|
| 1052 | n=sizeof(savetext)-1; |
|---|
| 1053 | if (DIRlen(zxdir) < n) n=DIRlen(zxdir); |
|---|
| 1054 | memcpy(savetext,zfldp,n); savetext[n]='\0'; |
|---|
| 1055 | } |
|---|
| 1056 | /* exclude common words */ |
|---|
| 1057 | if (*parmexcludedb) { |
|---|
| 1058 | TRMSTRU *trmp; |
|---|
| 1059 | unsigned char *p,*q; |
|---|
| 1060 | int ucloop; |
|---|
| 1061 | for (q=buff, p=(unsigned char *)zfldp, ucloop=zdirp->len; ucloop--; p++) *q++=isisuctab[*p]; |
|---|
| 1062 | *q='\0'; |
|---|
| 1063 | TERM(itrm,parmexcludedb,buff); |
|---|
| 1064 | if (TRMrc == RCNORMAL) zfldp=NULL; |
|---|
| 1065 | } |
|---|
| 1066 | /* build trigrec */ |
|---|
| 1067 | zp=buff; |
|---|
| 1068 | sprintf(zp,"D*"); zp+=strlen(zp); |
|---|
| 1069 | if (zfldp) { |
|---|
| 1070 | sprintf(zp,"H%"_LD_" %"_LD_" ",(LONGX)parmtag,(LONGX)zdirp->len); zp+=strlen(zp); |
|---|
| 1071 | memcpy(zp,zfldp,zdirp->len); *(zp+zdirp->len)='\0'; |
|---|
| 1072 | } |
|---|
| 1073 | if (fldupdat(zirec,buff)) fatal("wtrig1/line/fldupdat/2"); |
|---|
| 1074 | /*2*/ |
|---|
| 1075 | #endif /* PARMDTAG6W */ |
|---|
| 1076 | |
|---|
| 1077 | /* go ahead */ |
|---|
| 1078 | if (countcollection >= COLLECTION_SIZE) |
|---|
| 1079 | fatal("wtrig1/COLLECTION_SIZE/dtag"); |
|---|
| 1080 | countcollection++; |
|---|
| 1081 | |
|---|
| 1082 | /* process extract proc Gsplit=tag={trigrams|words} */ |
|---|
| 1083 | if (fldupdat(zirec,areacmd)) fatal(areacmd); |
|---|
| 1084 | |
|---|
| 1085 | /* setup list of relevant terms |
|---|
| 1086 | */ |
|---|
| 1087 | memset(lista,0x00,parmmaxtv*sizeof(LISTAWT1)); |
|---|
| 1088 | for (l=lista, avail=lista+1, loop=0; (LONGX)loop<(parmmaxtv-1); loop++, l++, avail++) |
|---|
| 1089 | l->avail=avail; |
|---|
| 1090 | listhdr=listtail=avail=lista; |
|---|
| 1091 | zcount=zcount2=0; |
|---|
| 1092 | |
|---|
| 1093 | /* zero and build f(t) |
|---|
| 1094 | */ |
|---|
| 1095 | memset(DOCUMENT,0x00,maxprim*sizeof(int)); |
|---|
| 1096 | for (dirp=VMFRdir(zirec), xdir=0, loop=VMFRnvf(zirec); loop--; dirp++, xdir++) { |
|---|
| 1097 | FFI ucloop; |
|---|
| 1098 | unsigned char *p; |
|---|
| 1099 | if (dirp->tag != parmtag) continue; |
|---|
| 1100 | fldp=VFIELDP(zirec,xdir); |
|---|
| 1101 | /* convert words to upper case */ |
|---|
| 1102 | if (!trigrams) if (parmuppercase) |
|---|
| 1103 | for (p=(unsigned char *)fldp, ucloop=dirp->len; ucloop--; p++) *p=isisuctab[*p]; |
|---|
| 1104 | |
|---|
| 1105 | hidx=hashindex(table,maxprim,parmwidth,fldp,dirp->len,&found,0); |
|---|
| 1106 | if (!found) { |
|---|
| 1107 | #if DISCART |
|---|
| 1108 | continue; |
|---|
| 1109 | #else /* DISCART */ |
|---|
| 1110 | /* bug compiler/code/unsigned char */ |
|---|
| 1111 | fldp[dirp->len]='\0'; /*!*/ |
|---|
| 1112 | fprintf(stderr,"*** fldp=%s",fldp); |
|---|
| 1113 | /* bc5 must be compiler/code/unsigned char */ |
|---|
| 1114 | fatal("wtrig1/f(t)/term not found in collection"); |
|---|
| 1115 | #endif /* DISCART */ |
|---|
| 1116 | } |
|---|
| 1117 | /* optimize term processing */ |
|---|
| 1118 | if (!COLLECTION[hidx]) continue; |
|---|
| 1119 | /* count term */ |
|---|
| 1120 | DOCUMENT[hidx]++; |
|---|
| 1121 | } |
|---|
| 1122 | |
|---|
| 1123 | /* calculate localweight x globalweight |
|---|
| 1124 | */ |
|---|
| 1125 | memset(PRODWEIGHT,0x00,maxprim*sizeof(float)); |
|---|
| 1126 | soma2=0; |
|---|
| 1127 | for (docump=DOCUMENT, h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth, docump++) { |
|---|
| 1128 | if (*h) if (*docump) { |
|---|
| 1129 | double logarg = (double)(1 + *docump); |
|---|
| 1130 | LOCALWEIGHT = (float)log(logarg); |
|---|
| 1131 | PRODWEIGHT[hidx] = LOCALWEIGHT*GLOBALWEIGHT[hidx]; |
|---|
| 1132 | fator=PRODWEIGHT[hidx]; |
|---|
| 1133 | soma2+=fator*fator; |
|---|
| 1134 | if (parmtrace & 0x08) |
|---|
| 1135 | printf(" 8|%"_LD_"|%s|%d\n",docmfn,h,*docump); |
|---|
| 1136 | if (parmtrace & 0x10) |
|---|
| 1137 | printf("16|%"_LD_"|%s|%f\n",docmfn,h,LOCALWEIGHT); |
|---|
| 1138 | if (parmtrace & 0x20) |
|---|
| 1139 | printf("32|%"_LD_"|%s|%f\n",docmfn,h,PRODWEIGHT[hidx]); |
|---|
| 1140 | } |
|---|
| 1141 | } |
|---|
| 1142 | |
|---|
| 1143 | /* calculate normalization factor = sqrt of sum of squares |
|---|
| 1144 | */ |
|---|
| 1145 | if (soma2) invsqrts2=1/sqrt(soma2); |
|---|
| 1146 | if (parmtrace & 0x40) |
|---|
| 1147 | printf("64|%"_LD_"| |%f|%f\n",docmfn,soma2,invsqrts2); |
|---|
| 1148 | |
|---|
| 1149 | /* skip empty vectors */ |
|---|
| 1150 | if (!soma2) { |
|---|
| 1151 | ycount++; |
|---|
| 1152 | continue; |
|---|
| 1153 | } |
|---|
| 1154 | |
|---|
| 1155 | /* calculate final term weight = local x global x normalization |
|---|
| 1156 | */ |
|---|
| 1157 | for (prodp=PRODWEIGHT, h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth, prodp++) { |
|---|
| 1158 | if (*h) if (*prodp) { |
|---|
| 1159 | LISTAWT1 *l,*prev; |
|---|
| 1160 | float nextw; |
|---|
| 1161 | float PRODW= *prodp; |
|---|
| 1162 | TERMWEIGHT = PRODW * invsqrts2; |
|---|
| 1163 | prev=NULL; |
|---|
| 1164 | l=NULL; if (listhdr->weight) l=listhdr; |
|---|
| 1165 | while (l) { |
|---|
| 1166 | if (TERMWEIGHT < l->weight) { prev=l; l=l->next; } |
|---|
| 1167 | else break; |
|---|
| 1168 | } |
|---|
| 1169 | nextw=((l)?l->weight:0.0); |
|---|
| 1170 | if (avail) { |
|---|
| 1171 | LISTAWT1 *nextavail=avail->avail; |
|---|
| 1172 | avail->weight=TERMWEIGHT; avail->hidx=hidx; |
|---|
| 1173 | avail->prev=prev; |
|---|
| 1174 | avail->next=l; |
|---|
| 1175 | if (prev) prev->next=avail; |
|---|
| 1176 | if (nextw) l->prev=avail; |
|---|
| 1177 | if (!avail->prev) listhdr=avail; |
|---|
| 1178 | if (!avail->next) listtail=avail; |
|---|
| 1179 | avail=nextavail; |
|---|
| 1180 | if (parmtrace2) printf("64a|"); |
|---|
| 1181 | zcount++; |
|---|
| 1182 | } |
|---|
| 1183 | else { |
|---|
| 1184 | if (TERMWEIGHT > listtail->weight) { |
|---|
| 1185 | LISTAWT1 *last=listtail; |
|---|
| 1186 | LISTAWT1 *repl=last; |
|---|
| 1187 | LISTAWT1 *lnext=NULL; |
|---|
| 1188 | if (l) lnext=l->next; |
|---|
| 1189 | if (last->prev) { |
|---|
| 1190 | listtail=last->prev; |
|---|
| 1191 | listtail->next=NULL; |
|---|
| 1192 | } |
|---|
| 1193 | repl->weight=TERMWEIGHT; repl->hidx=hidx; |
|---|
| 1194 | repl->prev=prev; |
|---|
| 1195 | if (prev) prev->next=repl; |
|---|
| 1196 | if (l) if (lnext) { |
|---|
| 1197 | repl->next=l; |
|---|
| 1198 | l->prev=repl; |
|---|
| 1199 | } |
|---|
| 1200 | if (!repl->prev) listhdr=repl; |
|---|
| 1201 | if (!repl->next) listtail=repl; |
|---|
| 1202 | if (parmtrace2) printf("64b|"); |
|---|
| 1203 | zcount2++; |
|---|
| 1204 | } |
|---|
| 1205 | } |
|---|
| 1206 | if (parmtrace2) { |
|---|
| 1207 | printf("%"_LD_"|%s|%f\n",docmfn,h,TERMWEIGHT); |
|---|
| 1208 | for (l=listhdr; l; l=l->next) { |
|---|
| 1209 | char *p; |
|---|
| 1210 | if (!l) break; |
|---|
| 1211 | p=table+(l->hidx*hwidth); |
|---|
| 1212 | printf("%"_LD_"|%"_LD_"=%s|%f p=%"_LD_"|n=%"_LD_"|a=%"_LD_" hdr=%"_LD_"|lst=%"_LD_"|prev=%"_LD_"\n",docmfn,l->hidx,p,l->weight, |
|---|
| 1213 | (l->prev)?((LISTAWT1 *)(l->prev))->hidx:-1, |
|---|
| 1214 | (l->next)?((LISTAWT1 *)(l->next))->hidx:-1, |
|---|
| 1215 | (l->avail)?((LISTAWT1 *)(l->avail))->hidx:-1, |
|---|
| 1216 | (listhdr->hidx)?listhdr->hidx:-1, |
|---|
| 1217 | (listtail->hidx)?listtail->hidx:-1, |
|---|
| 1218 | (prev)?prev->hidx:-1); |
|---|
| 1219 | } |
|---|
| 1220 | printf("\n"); |
|---|
| 1221 | } |
|---|
| 1222 | } /* end if h */ |
|---|
| 1223 | } /* end for hidx */ |
|---|
| 1224 | |
|---|
| 1225 | /* list term vector |
|---|
| 1226 | */ |
|---|
| 1227 | if (parmtrace & 0x40) for (l=listhdr; l; l=l->next) { |
|---|
| 1228 | if (!l->weight) break; |
|---|
| 1229 | hidx=l->hidx; h=table+hidx*hwidth; |
|---|
| 1230 | printf("64|%"_LD_"|%s|%f\n",docmfn,h,l->weight); |
|---|
| 1231 | } |
|---|
| 1232 | |
|---|
| 1233 | /* output term vector for the document |
|---|
| 1234 | */ |
|---|
| 1235 | outmfn++; |
|---|
| 1236 | if (*outtermvectorsdb) { |
|---|
| 1237 | char *batchp=buff; |
|---|
| 1238 | if (parmdtag) VMFRmfn(zirec)=outmfn; else VMFRmfn(zirec)=docmfn; |
|---|
| 1239 | sprintf(batchp,"D*"); batchp+=strlen(batchp); |
|---|
| 1240 | if (parmdtag || 1) { |
|---|
| 1241 | sprintf(batchp,"<1 0>%"_LD_"</1>",docmfn); batchp+=strlen(batchp); |
|---|
| 1242 | } |
|---|
| 1243 | if (*zilang) { |
|---|
| 1244 | sprintf(batchp,"<2 0>%s</2>",zilang); batchp+=strlen(batchp); |
|---|
| 1245 | } |
|---|
| 1246 | if (parmdtag) if (parmsavetext) { |
|---|
| 1247 | sprintf(batchp,"<3 0>%s</3>",savetext); batchp+=strlen(batchp); |
|---|
| 1248 | } |
|---|
| 1249 | |
|---|
| 1250 | if (listhdr->weight) { |
|---|
| 1251 | int parmwritebinv=parmwritebin; |
|---|
| 1252 | |
|---|
| 1253 | if (fldupdat(zirec,buff)) fatal("wtrig1/outtermvector/fldupdat/1"); |
|---|
| 1254 | if (parmwritebinv) { |
|---|
| 1255 | char *p; |
|---|
| 1256 | int n,n1,n2; |
|---|
| 1257 | unsigned short int usi_w; |
|---|
| 1258 | DIRSTRU *dirp; |
|---|
| 1259 | int xdir=VMFRnvf(zirec); |
|---|
| 1260 | sprintf(buff,"<4 0></4>"); |
|---|
| 1261 | if (fldupdat(zirec,buff)) fatal("wtrig1/outtermvector/fldupdat/2"); |
|---|
| 1262 | dirp=VMFRdir(zirec); dirp+=xdir; |
|---|
| 1263 | p=VFIELDP(zirec,xdir); |
|---|
| 1264 | for (l=listhdr; l; l=l->next) { |
|---|
| 1265 | if (!l->weight) break; |
|---|
| 1266 | hidx=l->hidx; h=table+hidx*hwidth; |
|---|
| 1267 | TERMWEIGHT=l->weight; |
|---|
| 1268 | usi_w=(unsigned short int)(USHRT_MAX*TERMWEIGHT); |
|---|
| 1269 | memcpy(p,(void *)&usi_w,sizeof(usi_w)); n1=sizeof(usi_w); p+=n1; |
|---|
| 1270 | memcpy(p,h,n2=strlen(h)+1); p+=n2; n=n1+n2; |
|---|
| 1271 | /* |
|---|
| 1272 | memcpy(p,h,hwidth); n=hwidth; p+=n; |
|---|
| 1273 | memcpy(p,(void *)&TERMWEIGHT,sizeof(TERMWEIGHT)); n+=sizeof(TERMWEIGHT); p+=sizeof(TERMWEIGHT); |
|---|
| 1274 | memcpy(p,(void *)&DOCUMENT[hidx],sizeof(DOCUMENT[hidx])); n+=sizeof(DOCUMENT[hidx]); p+=sizeof(DOCUMENT[hidx]); |
|---|
| 1275 | */ |
|---|
| 1276 | dirp->len+=n; VMFRmfrl(zirec)=VMFRmfrl(zirec)+n; |
|---|
| 1277 | } |
|---|
| 1278 | } |
|---|
| 1279 | else { /* parmwritebin */ |
|---|
| 1280 | for (l=listhdr; l; l=l->next) { |
|---|
| 1281 | if (!l->weight) break; |
|---|
| 1282 | hidx=l->hidx; h=table+hidx*hwidth; |
|---|
| 1283 | TERMWEIGHT=l->weight; |
|---|
| 1284 | sprintf(batchp,"<4 0>%s^w%f^n%d</4>",h,TERMWEIGHT,DOCUMENT[hidx]); |
|---|
| 1285 | batchp+=strlen(batchp); |
|---|
| 1286 | } |
|---|
| 1287 | if (fldupdat(zirec,buff)) fatal("wtrig1/outtermvector/fldupdat/3"); |
|---|
| 1288 | } /* parmwritebin */ |
|---|
| 1289 | |
|---|
| 1290 | |
|---|
| 1291 | recupdat(crec,zirec); /* cisis_wwtrig2(WTRIG2HANDLEP)*/ |
|---|
| 1292 | |
|---|
| 1293 | } /* end if listhdr->weight */ |
|---|
| 1294 | } |
|---|
| 1295 | |
|---|
| 1296 | /* add postings to the inverted file |
|---|
| 1297 | */ |
|---|
| 1298 | if (*outterminverteddb) { |
|---|
| 1299 | LONGX mfn=outmfn; |
|---|
| 1300 | for (l=listhdr; l; l=l->next) { |
|---|
| 1301 | LONGX *postp; |
|---|
| 1302 | if (!l->weight) break; |
|---|
| 1303 | hidx=l->hidx; |
|---|
| 1304 | if (hidx >= maxprim) { |
|---|
| 1305 | printf("%"_LD_"|%s|fatal: wtrig1/terminverted/hidx\n",mfn,h); |
|---|
| 1306 | fatal("wtrig1/terminverted/hidx"); |
|---|
| 1307 | } |
|---|
| 1308 | if (COUNT[hidx] > COLLECTION[hidx]) { |
|---|
| 1309 | printf("%"_LD_"|%s|fatal: wtrig1/terminverted/count\n",mfn,h); |
|---|
| 1310 | for (l=listhdr; l; l=l->next) { |
|---|
| 1311 | char *p; |
|---|
| 1312 | if (!l) break; |
|---|
| 1313 | p=table+(l->hidx*hwidth); |
|---|
| 1314 | printf("%"_LD_"|%"_LD_"=%s|%f p=%"_LD_"|n=%"_LD_"|a=%"_LD_" hdr=%"_LD_"|lst=%"_LD_"|prev=%"_LD_"\n",mfn,l->hidx,p,l->weight, |
|---|
| 1315 | (l->prev)?((LISTAWT1 *)(l->prev))->hidx:-1, |
|---|
| 1316 | (l->next)?((LISTAWT1 *)(l->next))->hidx:-1, |
|---|
| 1317 | (l->avail)?((LISTAWT1 *)(l->avail))->hidx:-1, |
|---|
| 1318 | (listhdr->hidx)?listhdr->hidx:-1, |
|---|
| 1319 | (listtail->hidx)?listtail->hidx:-1); |
|---|
| 1320 | } |
|---|
| 1321 | printf("\n"); |
|---|
| 1322 | fatal("wtrig1/terminverted/count"); |
|---|
| 1323 | } |
|---|
| 1324 | postp=POSTINGS+OFFSET[hidx]+COUNT[hidx]; |
|---|
| 1325 | *postp=mfn; COUNT[hidx]++; |
|---|
| 1326 | } |
|---|
| 1327 | #if PARMLANG |
|---|
| 1328 | /* add posting to the language bit strigs */ |
|---|
| 1329 | if (*zilang) if (langidx >= 0) { |
|---|
| 1330 | char *HITS=langshits[langidx]; |
|---|
| 1331 | if (outmfn < 1) fatal("wtrig1/terminverted/outmfn invalid/1"); |
|---|
| 1332 | if (outmfn > COLLECTION_SIZE) fatal("wtrig1/terminverted/outmfn invalid/2"); |
|---|
| 1333 | hitmask =hitbitmask[outmfn&BY8RMASK]; |
|---|
| 1334 | hitoffset = outmfn/8; |
|---|
| 1335 | HITS[hitoffset] |= hitmask; |
|---|
| 1336 | if (parmtrace) printf(" x|%"_LD_"|%s|%d|%d|%"_LD_"\n",docmfn,zilang,langidx,nlangs,outmfn); |
|---|
| 1337 | } |
|---|
| 1338 | #endif /* PARMLANG */ |
|---|
| 1339 | } |
|---|
| 1340 | |
|---|
| 1341 | #if PARMDTAG6W |
|---|
| 1342 | /*2*/ |
|---|
| 1343 | } /* end for each 6words line */ |
|---|
| 1344 | /*2*/ |
|---|
| 1345 | #endif /* PARMDTAG6W */ |
|---|
| 1346 | #if PARMDTAG |
|---|
| 1347 | /**/ |
|---|
| 1348 | } /* end if dtagfldlen */ /* process each line */ |
|---|
| 1349 | if (parmdtag) while (*dtagp == dtagc1 || *dtagp == dtagc2) dtagp++; |
|---|
| 1350 | dtagfldp=dtagp; dtagfldlen=0; |
|---|
| 1351 | if (!*dtagfldp) break; |
|---|
| 1352 | } |
|---|
| 1353 | else { |
|---|
| 1354 | dtagp++; dtagfldlen++; |
|---|
| 1355 | } |
|---|
| 1356 | } /* end for dtagp */ |
|---|
| 1357 | /**/ |
|---|
| 1358 | #endif /* PARMDTAG */ |
|---|
| 1359 | |
|---|
| 1360 | countok++; |
|---|
| 1361 | if (parmtell2) if (countok%parmtell2 == 0) fprintf(stderr,"++ %"_LD_"+%"_LD_" %"_LD_" %"_LD_"+%"_LD_"\n",countok,xcount,ycount,zcount,zcount2); |
|---|
| 1362 | } /* end for mfn */ |
|---|
| 1363 | |
|---|
| 1364 | } /* end if x12345 */ |
|---|
| 1365 | |
|---|
| 1366 | /* get secs_ for elapsed */ |
|---|
| 1367 | secs_2=time(&secs_now); |
|---|
| 1368 | |
|---|
| 1369 | |
|---|
| 1370 | /* rellocate hashing table of collection terms (word/trigrams) |
|---|
| 1371 | */ |
|---|
| 1372 | //if (parmtell || parmtrace) printf("+"); |
|---|
| 1373 | //if (parmtell || parmtrace) printf("+++ relloc'ing \n"); |
|---|
| 1374 | if (parmtell2) fprintf(stderr,"++ %"_LD_" recs \n",countok); |
|---|
| 1375 | if (parmtell2) fprintf(stderr,"++ %"_LD_" vectors \n",outmfn); |
|---|
| 1376 | if (parmrelloc) |
|---|
| 1377 | for (nterms=0, p=h=table, hidx2=hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1378 | if (!*h) continue; |
|---|
| 1379 | if (hidx2 != hidx) { |
|---|
| 1380 | memcpy(p,h,hwidth); memset(h,0x00,hwidth); |
|---|
| 1381 | COLLECTION[hidx2]=COLLECTION[hidx]; COLLECTION[hidx]=0; |
|---|
| 1382 | GLOBALWEIGHT[hidx2]=GLOBALWEIGHT[hidx]; GLOBALWEIGHT[hidx]=0; |
|---|
| 1383 | } |
|---|
| 1384 | INDEX[hidx2]=hidx; |
|---|
| 1385 | p+=hwidth; hidx2++; nterms++; |
|---|
| 1386 | } |
|---|
| 1387 | else |
|---|
| 1388 | for (nterms=0, h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1389 | INDEX[hidx]=hidx; |
|---|
| 1390 | if (!*h) continue; |
|---|
| 1391 | nterms++; |
|---|
| 1392 | } |
|---|
| 1393 | //if (!nterms) fatal("wtrig1/outcollectionoccs/zero terms"); |
|---|
| 1394 | |
|---|
| 1395 | if (parmtrace & 0x04) |
|---|
| 1396 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1397 | if (!*h) continue; |
|---|
| 1398 | printf("x4|%s|%"_LD_"|%f\n",h,COLLECTION[hidx],GLOBALWEIGHT[hidx]); |
|---|
| 1399 | } |
|---|
| 1400 | |
|---|
| 1401 | |
|---|
| 1402 | /* sort collection by term (word/trigrams) |
|---|
| 1403 | */ |
|---|
| 1404 | if (parmrelloc) if (parmsort) { |
|---|
| 1405 | //if (parmtell || parmtrace) printf("+"); |
|---|
| 1406 | if (parmtell || parmtrace) printf("+++ sorting %"_LD_" terms \n",nterms); |
|---|
| 1407 | if (parmtell2) parmtell2=nterms/5; |
|---|
| 1408 | for (h=table, hidx=0, hloop=nterms-1; hidx < hloop; hidx++, h+=hwidth) { /* x:x+1 */ |
|---|
| 1409 | if (parmtell2) if ((hidx+1)%parmtell2 == 0) fprintf(stderr,"+++ %"_LD_"/5 \n",(LONGX)hidx/parmtell2+1); |
|---|
| 1410 | for (h2=h+hwidth, hidx2=hidx+1; hidx2 < nterms; hidx2++, h2+=hwidth) { |
|---|
| 1411 | LONGX index; |
|---|
| 1412 | LONGX n; |
|---|
| 1413 | float w; |
|---|
| 1414 | if (memcmp(h,h2,hwidth) == 0) fatal("wtrig1/outcollectionoccs/duplicated key");; |
|---|
| 1415 | if (memcmp(h,h2,hwidth) < 0) continue; |
|---|
| 1416 | memcpy(buff,h,hwidth); |
|---|
| 1417 | memcpy(h,h2,hwidth); |
|---|
| 1418 | memcpy(h2,buff,hwidth); |
|---|
| 1419 | index=INDEX[hidx]; |
|---|
| 1420 | INDEX[hidx]=INDEX[hidx2]; |
|---|
| 1421 | INDEX[hidx2]=index; |
|---|
| 1422 | n=COLLECTION[hidx]; |
|---|
| 1423 | COLLECTION[hidx]=COLLECTION[hidx2]; |
|---|
| 1424 | COLLECTION[hidx2]=n; |
|---|
| 1425 | w=GLOBALWEIGHT[hidx]; |
|---|
| 1426 | GLOBALWEIGHT[hidx]=GLOBALWEIGHT[hidx2]; |
|---|
| 1427 | GLOBALWEIGHT[hidx2]=w; |
|---|
| 1428 | } |
|---|
| 1429 | } |
|---|
| 1430 | } |
|---|
| 1431 | |
|---|
| 1432 | /* get secs_ for elapsed */ |
|---|
| 1433 | secs_3=time(&secs_now); |
|---|
| 1434 | |
|---|
| 1435 | if (parmtrace & 0x04) |
|---|
| 1436 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1437 | if (!*h) continue; |
|---|
| 1438 | printf("y4|%s|%"_LD_"|%f|%"_LD_"\n",h,COLLECTION[hidx],GLOBALWEIGHT[hidx],INDEX[hidx]); |
|---|
| 1439 | } |
|---|
| 1440 | |
|---|
| 1441 | |
|---|
| 1442 | /* output collection occs for each term |
|---|
| 1443 | */ |
|---|
| 1444 | //if (parmtell || parmtrace) printf("+"); |
|---|
| 1445 | if (*outcollectionoccsdb) { |
|---|
| 1446 | char *batchp; |
|---|
| 1447 | LONGX mfn=1; |
|---|
| 1448 | if (parmtell || parmtrace) printf("+++ writing global frequencies to %s\n",outcollectionoccsdb); |
|---|
| 1449 | recisis0(outcollectionoccsdb); |
|---|
| 1450 | RECORD(crec,outcollectionoccsdb,0L); |
|---|
| 1451 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1452 | //for (h=table, hidx=0; hidx < nterms; hidx++, h+=hwidth) { |
|---|
| 1453 | if (*h) { |
|---|
| 1454 | batchp=buff; |
|---|
| 1455 | if (parmshowh) |
|---|
| 1456 | sprintf(batchp,"<3 0>%s^n%"_LD_"^w%f^h%"_LD_"</3>",h,COLLECTION[hidx],GLOBALWEIGHT[hidx],INDEX[hidx]); |
|---|
| 1457 | else |
|---|
| 1458 | sprintf(batchp,"<3 0>%s^n%"_LD_"^w%f</3>" ,h,COLLECTION[hidx],GLOBALWEIGHT[hidx]); |
|---|
| 1459 | batchp+=strlen(batchp); |
|---|
| 1460 | RECORD(irec,outcollectionoccsdb,mfn); MFRstatus=ACTIVE; |
|---|
| 1461 | if (fldupdat(irec,buff)) fatal("wtrig1/outcollectionoccs/fldupdat"); |
|---|
| 1462 | recupdat(crec,irec); mfn++; |
|---|
| 1463 | } |
|---|
| 1464 | } |
|---|
| 1465 | } |
|---|
| 1466 | |
|---|
| 1467 | /* output term inverted file |
|---|
| 1468 | */ |
|---|
| 1469 | //if (parmtell || parmtrace) printf("+"); |
|---|
| 1470 | if (*outterminverteddb) { |
|---|
| 1471 | LONGX count; |
|---|
| 1472 | LONGX *postp; |
|---|
| 1473 | char *batchp; |
|---|
| 1474 | RECSTRU *recp; |
|---|
| 1475 | if (parmtell || parmtrace) printf("+++ writing list of postings to %s\n",outterminverteddb); |
|---|
| 1476 | //allocate larger output record /* 20110812 */ |
|---|
| 1477 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1478 | if (!*h) continue; |
|---|
| 1479 | count=COUNT[INDEX[hidx]]; |
|---|
| 1480 | if (count > maxhits) maxhits=count; |
|---|
| 1481 | } |
|---|
| 1482 | xirec=nrecs; |
|---|
| 1483 | recallok(xirec,BUFSIZ+maxhits*sizeof(*postp)); /* 20110812 */ |
|---|
| 1484 | for (h=table, hidx=0; hidx < maxprim; hidx++, h+=hwidth) { |
|---|
| 1485 | //for (h=table, hidx=0; hidx < nterms; hidx++, h+=hwidth) { |
|---|
| 1486 | if (!*h) continue; |
|---|
| 1487 | count=COUNT[INDEX[hidx]]; |
|---|
| 1488 | if (count) { |
|---|
| 1489 | /* write term postings in record mfn=hidx+1 */ |
|---|
| 1490 | RECORD(xirec,outterminverteddb,hidx+1); MFRstatus=ACTIVE; |
|---|
| 1491 | batchp=buff; |
|---|
| 1492 | sprintf(batchp,"<33 0>%s^n%"_LD_"</33>",h,count); batchp+=strlen(batchp); |
|---|
| 1493 | postp=POSTINGS+OFFSET[INDEX[hidx]]; |
|---|
| 1494 | if (parmwritebin) { |
|---|
| 1495 | char *p,*q; |
|---|
| 1496 | // 20110812 |
|---|
| 1497 | //int n; |
|---|
| 1498 | LONGX n; |
|---|
| 1499 | sprintf(batchp,"<5 0></5>"); |
|---|
| 1500 | if (fldupdat(xirec,buff)) fatal("wtrig1/outtermvinverted/bin/fldupdat"); |
|---|
| 1501 | dirp=MFRdir; dirp++; |
|---|
| 1502 | p=FIELDP(1); |
|---|
| 1503 | // 20110812 |
|---|
| 1504 | // n=sizeof(*postp); |
|---|
| 1505 | // if (MFRmfrl+count*n > RECnbytes) fatal("wtrig1/outtermvinverted/RECnbytes"); /* 20110811 */ |
|---|
| 1506 | //for (; count--; postp++) { |
|---|
| 1507 | // q=(char *)postp; |
|---|
| 1508 | // memcpy(p,q,n); p+=n; |
|---|
| 1509 | // dirp->len+=n; MFRmfrl+=n; |
|---|
| 1510 | //} |
|---|
| 1511 | q=(char *)postp; |
|---|
| 1512 | n=sizeof(*postp)*COUNT[INDEX[hidx]]; |
|---|
| 1513 | memcpy(p,q,(size_t)n); |
|---|
| 1514 | dirp->len+=n; MFRmfrl+=n; |
|---|
| 1515 | } |
|---|
| 1516 | else { |
|---|
| 1517 | for (; count--; postp++) { |
|---|
| 1518 | sprintf(batchp,"<5 0>%"_LD_"</5>",*postp); batchp+=strlen(batchp); |
|---|
| 1519 | } |
|---|
| 1520 | if (fldupdat(xirec,buff)) fatal("wtrig1/outtermvinverted/fldupdat"); |
|---|
| 1521 | } |
|---|
| 1522 | recupdat(crec2,xirec); |
|---|
| 1523 | } |
|---|
| 1524 | } |
|---|
| 1525 | #if PARMLANG |
|---|
| 1526 | /* add posting to the language bit strigs */ |
|---|
| 1527 | for (langidx=0; langidx < nlangs; langidx++) { |
|---|
| 1528 | char *HITS=langshits[langidx]; |
|---|
| 1529 | LONGX n; |
|---|
| 1530 | /* write term postings in record mfn=nterms+(langidx+1) */ |
|---|
| 1531 | RECORD(xirec,outterminverteddb,nterms+langidx+1); MFRstatus=ACTIVE; |
|---|
| 1532 | batchp=buff; |
|---|
| 1533 | sprintf(batchp,"<34 0>%s^n%"_LD_"^b%"_LD_"</34><35 0></35>",langsname[langidx],langscount[langidx],hitbytes); batchp+=strlen(batchp); |
|---|
| 1534 | if (fldupdat(xirec,buff)) fatal("wtrig1/outtermvinverted/langs/fldupdat"); |
|---|
| 1535 | n=hitbytes; |
|---|
| 1536 | dirp=MFRdir; dirp++; |
|---|
| 1537 | memcpy(FIELDP(1),HITS,n); dirp->len+=n; MFRmfrl+=n; |
|---|
| 1538 | recupdat(crec2,xirec); |
|---|
| 1539 | } |
|---|
| 1540 | #endif /* PARMLANG */ |
|---|
| 1541 | } |
|---|
| 1542 | |
|---|
| 1543 | /* get secs_ for elapsed */ |
|---|
| 1544 | secs_4=time(&secs_now); |
|---|
| 1545 | |
|---|
| 1546 | /* output collection size |
|---|
| 1547 | */ |
|---|
| 1548 | //if (parmtell || parmtrace) printf("+"); |
|---|
| 1549 | if (*outcollectionsizedb) { |
|---|
| 1550 | char *batchp=buff; |
|---|
| 1551 | if (parmtell || parmtrace) printf("+++ writing parms and documents' collection data to %s\n",outcollectionsizedb); |
|---|
| 1552 | recisis0(outcollectionsizedb); |
|---|
| 1553 | RECORD(crec,outcollectionsizedb,0L); |
|---|
| 1554 | RECORD(irec,outcollectionsizedb,1L); MFRstatus=ACTIVE; |
|---|
| 1555 | sprintf(batchp,"<1 0>^ndocuments^v%s</1>",indocumentsdb); |
|---|
| 1556 | batchp+=strlen(batchp); |
|---|
| 1557 | if (extractfmta) |
|---|
| 1558 | #if BEFORE20051103 |
|---|
| 1559 | sprintf(batchp,"<1 0>^nextract^v%s</1>",extractfmta); /* extractfmta may contains </1> */ |
|---|
| 1560 | #else |
|---|
| 1561 | sprintf(batchp,"H 1 %d ^nextract^v%s",strlen("^nextract^v")+strlen(extractfmta),extractfmta); |
|---|
| 1562 | #endif |
|---|
| 1563 | else |
|---|
| 1564 | sprintf(batchp,"<1 0>^nextract^v%"_LD_"</1>",(LONGX)parmtag); |
|---|
| 1565 | batchp+=strlen(batchp); |
|---|
| 1566 | if (collectiondb) { |
|---|
| 1567 | sprintf(batchp,"<1 0>^ncollection^v%s</1>",collectiondb); |
|---|
| 1568 | batchp+=strlen(batchp); |
|---|
| 1569 | } |
|---|
| 1570 | sprintf(batchp,"<1 0>^nwidth^v%d^t%s</1>",parmwidth,(trigrams)?"trigrams":"words"); |
|---|
| 1571 | batchp+=strlen(batchp); |
|---|
| 1572 | sprintf(batchp,"<1 0>^ncase^v%s</1>",parmuppercase); |
|---|
| 1573 | batchp+=strlen(batchp); |
|---|
| 1574 | sprintf(batchp,"<1 0>^nK^v%"_LD_"</1>",parmcategories); |
|---|
| 1575 | batchp+=strlen(batchp); |
|---|
| 1576 | sprintf(batchp,"<1 0>^nmaxrf^v%f</1>",parmmaxrf); |
|---|
| 1577 | batchp+=strlen(batchp); |
|---|
| 1578 | sprintf(batchp,"<1 0>^nmaxtv^v%d</1>",parmmaxtv); |
|---|
| 1579 | batchp+=strlen(batchp); |
|---|
| 1580 | if (parmdtag) { |
|---|
| 1581 | sprintf(batchp,"<1 0>^ndmfn^v%d</1>",parmdtag); |
|---|
| 1582 | batchp+=strlen(batchp); |
|---|
| 1583 | } |
|---|
| 1584 | if (parm6words) { |
|---|
| 1585 | sprintf(batchp,"<1 0>^n6words^v%d</1>",parm6words); |
|---|
| 1586 | batchp+=strlen(batchp); |
|---|
| 1587 | } |
|---|
| 1588 | if (*parmexcludedb) { |
|---|
| 1589 | sprintf(batchp,"<1 0>^nexclude^v%s</1>",parmexcludedb); |
|---|
| 1590 | batchp+=strlen(batchp); |
|---|
| 1591 | } |
|---|
| 1592 | sprintf(batchp,"<1 0>^nbin^v%d</1>",parmwritebin); |
|---|
| 1593 | batchp+=strlen(batchp); |
|---|
| 1594 | sprintf(batchp,"<1 0>^nmaxprim^v%"_LD_"</1>",maxprim); |
|---|
| 1595 | batchp+=strlen(batchp); |
|---|
| 1596 | sprintf(batchp,"<1 0>^nnterms^v%"_LD_"</1>",nterms); |
|---|
| 1597 | batchp+=strlen(batchp); |
|---|
| 1598 | #if PARMLANG |
|---|
| 1599 | sprintf(batchp,"<1 0>^nlanguages^v%d</1>",nlangs); |
|---|
| 1600 | batchp+=strlen(batchp); |
|---|
| 1601 | #endif /* PARMLANG */ |
|---|
| 1602 | sprintf(batchp,"<1 0>^nndocs^v%"_LD_"</1>",countok); |
|---|
| 1603 | batchp+=strlen(batchp); |
|---|
| 1604 | sprintf(batchp,"<1 0>^nndocsread^v%"_LD_"</1>",countok+xcount); |
|---|
| 1605 | batchp+=strlen(batchp); |
|---|
| 1606 | sprintf(batchp,"<1 0>^nelapsed1^v%"_LD_"</1>",(LONGX)secs_1-secs_start); |
|---|
| 1607 | batchp+=strlen(batchp); |
|---|
| 1608 | sprintf(batchp,"<1 0>^nelapsed2^v%"_LD_"</1>",(LONGX)secs_2-secs_start); |
|---|
| 1609 | batchp+=strlen(batchp); |
|---|
| 1610 | sprintf(batchp,"<1 0>^nelapsed3^v%"_LD_"</1>",(LONGX)secs_3-secs_start); |
|---|
| 1611 | batchp+=strlen(batchp); |
|---|
| 1612 | sprintf(batchp,"<1 0>^nelapsed4^v%"_LD_"</1>",(LONGX)secs_4-secs_start); |
|---|
| 1613 | batchp+=strlen(batchp); |
|---|
| 1614 | sprintf(batchp,"<1 0>^ndate^v%04d%02d%02d %02d%02d%02d</1>", |
|---|
| 1615 | 1900+tp->tm_year,tp->tm_mon+1,tp->tm_mday,tp->tm_hour,tp->tm_min,tp->tm_sec); |
|---|
| 1616 | batchp+=strlen(batchp); |
|---|
| 1617 | sprintf(batchp,"<2 0>%"_LD_"</2>",COLLECTION_SIZE); |
|---|
| 1618 | batchp+=strlen(batchp); |
|---|
| 1619 | sprintf(batchp,"<3 0>%"_LD_"</3>",maxhits); |
|---|
| 1620 | //printf("\n%s\n",buff); |
|---|
| 1621 | if (fldupdat(irec,buff)) fatal("wtrig1/outcollectionsize/fldupdat"); |
|---|
| 1622 | recupdat(crec,irec); |
|---|
| 1623 | } |
|---|
| 1624 | |
|---|
| 1625 | if (parmtell || parmtrace) printf("\n"); |
|---|
| 1626 | |
|---|
| 1627 | exit(0); /* AOT, 30/07/2004 - thanks MB */ |
|---|
| 1628 | |
|---|
| 1629 | } /* end of main */ |
|---|
| 1630 | |
|---|
| 1631 | |
|---|