root/trunk/w2.c

Revision 389, 13.7 kB (checked in by heitor.barbieri, 3 weeks ago)

essage first commit

Line 
1/* ==----------------------------- w2.c ------------------------------== */
2
3#if WHENFUN
4#include "w2rcol.c"    // usa colvdb/close       
5#include "w2ralbs.c"   // usa colxdb/mstsetup
6#endif
7
8int w2reply ( int cmd, WTFUN_ARRAY *awtfp, int coll, int yocc, LISTA *l, int joinjd, int showv3, int showid, char *reply, char *batchp )
9{
10    WTFUN_XWT *xwtp=awtfp->vwtfp[coll];  // current
11
12    if (reply) {
13
14      *reply='\0';
15     
16      //open
17      sprintf(reply,"<similar rank=\"%d\" s=\"%f\"",yocc,l->sim);
18      reply+=strlen(reply);
19
20      //if (parmcollmfntag)
21      sprintf(reply," c=\"%"_LD_"\"",l->mfn);
22      reply+=strlen(reply);
23      ////if (parmcollapse)
24      ////if (!parmtext)
25      ////sprintf(reply," m=\"%"_LD_"\"",l->xxx);
26      ////reply+=strlen(reply);
27      //if (parmcollmfntag)
28      sprintf(reply," h=\"%"_LD_"\"",l->hit);
29      reply+=strlen(reply);
30
31      //showid
32      if (showid) {
33          sprintf(reply," id=\"");
34          reply+=strlen(reply);
35         
36#include "w2oid.c"
37///////////////////////////////////////////////////////////////////////////////////////////////////
38          sprintf(reply,"\"");
39          reply+=strlen(reply);
40      }
41
42     
43      //output collection's jdlist as " jd=\"..;..;..\""
44      if (jk_n /*joinjd*/) {
45                   
46#include "w2ojd.c"
47///////////////////////////////////////////////////////////////////////////////////////////////////
48      }
49
50      sprintf(reply,">");
51      reply+=strlen(reply);
52
53      //showv3
54      if (jkv_n || showv3) {
55
56#include "w2ov3.c"
57///////////////////////////////////////////////////////////////////////////////////////////////////
58      }
59
60      //close
61      sprintf(reply,"</similar>\n");
62      reply+=strlen(reply);
63     
64      /* ... */
65      if (!reply) fatal("w2reply/reply");
66    }
67   
68    return 0;
69}
70
71
72
73
74int trigcoll (int cmd, WTFUN_ARRAY *awtfp, char *parmstring, char *reply)
75{
76    WTFUN_XWT *xwtp;           
77   
78    int coll=(-1);
79    int icol;
80    int parmdetails=(cmd >=3)?1:0;
81   
82    char *parmeval=NULL;    // check for eval= in w2pdoc.c
83    int joinjd=0;           // check for TAG440/jd= in w2set.c / w2pdoc.c
84   
85    char *parmdisp=NULL;    // check for disp= in w2pdoc.c
86    int showv3=(-TAG3);     // usage
87    int showid=0;           // usage
88
89    char *ry=reply; // watch
90       
91#include "w2loc.c"
92///////////////////////////////////////////////////////////////////////////////////////////////////
93
94    *reply='\0';
95
96    xwtp=awtfp->vwtfp[0]; // wtf4p use
97    memset(xwtp,0x00,sizeof(WTFUN_XWT));
98   
99#include "wtfun.c"
100///////////////////////////////////////////////////////////////////////////////////////////////////
101
102    /* get secs_ for elapsed */
103    secs_start=time(&secs_now);
104
105#if FATRAPWT
106     /* save/notrap */
107     strcpy(z_iomsg,fatal_iomsg); memcpy(z_jumper,fatal_jumper,sizeof(fatal_jumper)); z_errcod=fatal_errcod; 
108     z_xerrno=dbxopt_errno; 
109     /* trap cisis fatal() */
110     strcpy(fatal_iomsg,"trap");
111     /* disable dbxopen msg */
112     dbxopt_errno=0;
113     z_jumprc = setjmp(fatal_jumper);
114     if (z_jumprc != 0) {
115         /* error */
116         if (reply) {
117             sprintf(reply,"<error type=\"fatal\" in=\"trigcoll\" code=\"%d\">%s</error>\n",fatal_errcod,fatal_iomsg);
118         }
119         /* restore/notrap */  //strcpy(fatal_iomsg,"");
120         memcpy(fatal_jumper,z_jumper,sizeof(fatal_jumper)); strcpy(fatal_iomsg,z_iomsg); 
121         fatal_errcod=z_errcod; 
122         dbxopt_errno=z_xerrno;
123         return (-1);
124     }
125
126#endif
127
128
129    /* get calling parameters from parmstring
130    */
131#include "w2arg.c"
132#include "w2p0.c"
133#include "w2pcol.c"
134///////////////////////////////////////////////////////////////////////////////////////////////////
135           
136    if (!collectiondb) return -1;
137   
138    /* select collection from structure
139    */
140    //if (cmd) fprintf(stderr,"*** wt: %s \n",collectiondb);   
141    for (icol=1; icol < awtfp->nwtfs; icol++) { // wtf4p skip
142        if (strcmp(collectiondb,awtfp->vwtfname[icol]) == 0) { 
143            xwtp=awtfp->vwtfp[coll=icol]; 
144            if (cmd) fprintf(stderr,"*** wt: %s [coll#%d] OK  \n",awtfp->vwtfname[coll],coll);   
145            parmdocumentsdb=NULL;
146            break;
147        }
148    }
149   
150    if (coll == -1) {
151        /* validade collection  */       
152            char *q=dbxcipar(NULL,collectiondb,'='); 
153            int value=(dbxcipok)?atoi(q):0;
154            if (value != awtfp->globalport) return -1;
155    }   
156    if (coll == -1) {
157        /* setup collection in [0] */
158            WTFUN_XWT *xxwtp=wtnew(cmd);                 // new coll
159            if (!xxwtp) return -1;
160            memcpy(xxwtp,xwtp,sizeof(WTFUN_XWT));        // copy parms
161            xwtp=xxwtp;                                  // set current
162            coll=awtfp->nwtfs;                           // coll#
163            awtfp->vwtfp[coll]=xwtp;                     // wtfp
164            strcpy(awtfp->vwtfname[coll],collectiondb);  // wtfname
165            awtfp->nwtfs++;                              // push
166            if (cmd) fprintf(stderr,"*** wt: %s [coll#%d] NEW \n",awtfp->vwtfname[coll],coll);   
167#include "w2set.c"  // ///inirec///outcrec///outirec
168                       // usar colcdb/close
169                       // usar colndb/close
170                       // mstsetup(colxdb,LONGX_MAX,LONGX_MAX);
171#if WHENFUN
172            int w2rcol  ( cmd, awtfp, coll );
173            int w2rcox  ( cmd, awtfp, coll );
174#else
175#include "w2rcol.c"    // usa colvdb/close       
176#include "w2ralbs.c"   // usa colxdb/mstsetup
177#endif
178///////////////////////////////////////////////////////////////////////////////////////////////////
179//        /* then store new entry */
180//        if (COLLECTION_SIZE > 0) {
181//        }
182    }
183    else {                                            // coll already loaded
184        /* set */
185        parmcollmfntag=collcollmfntag;
186        parmmaxrf=collmaxrf;
187        parmmaxtv=collmaxtv;
188        parmmaxrel=collmaxrel;
189        parmminsim=collminsim;
190        parmmaxsim=collmaxsim;       
191        /* get */
192#include "w2pcox.c"
193///////////////////////////////////////////////////////////////////////////////////////////////////   
194        /* chk */
195        if (parmcollmfntag > collcollmfntag)   parmcollmfntag=collcollmfntag;   
196        if (parmmaxrf > collmaxrf)   parmmaxtv=collmaxrf;   
197        if (parmmaxtv > collmaxtv)   parmmaxtv=collmaxtv;         
198        if (parmmaxrel > collmaxrel) parmmaxrel=collmaxrel;
199        if (parmminsim > parmmaxsim) parmminsim=collminsim;
200        if (parmminsim > parmmaxsim) parmmaxsim=collmaxsim;
201    }
202   
203    /* pcol parms
204    */ 
205    if (parmmaxrel > collmaxrel) parmmaxrel=collmaxrel;
206    if (!parmmaxrel) parmmaxrel=collmaxrel;
207   
208#if JDIN440
209    /* joinjd parm
210    */ 
211    joinjd=collcolljd;
212#else
213    joinjd=jd_n;
214#endif
215
216#if ALLOWUPCASE
217    /* load proper uppercase */
218    memcpy(isisuctab,xisisuctab,sizeof(xisisuctab));
219    memcpy(isiswctab,xisiswctab,sizeof(xisiswctab)); 
220    isiswctot=xisiswctot;
221#else
222    // default is ansi
223    memcpy(isisuctab,ansiuctab,256/*sizeof(ansiuctab)*/);
224    for (isiswctot=0; ansiactab[isiswctot]; isiswctot=isiswctot+1) isiswctab[ansiactab[isiswctot]]=1;       
225#endif
226
227
228    /* get secs_ for elapsed */
229    secs_colok=time(&secs_now);
230
231       
232    /* read/build document */
233#include "w2pdoc.c"
234///////////////////////////////////////////////////////////////////////////////////////////////////
235
236    /* pdoc parms
237    */ 
238    //
239
240    /* reply parms
241    */
242    //reply..
243    if (replyhere) {
244        char *pcolname;       
245       
246        sprintf(reply,"<parms>\n");
247        reply+=strlen(reply);
248       
249        sprintf(reply,"<collection path=\"%s\" size=\"%"_LD_"\" terms=\"%"_LD_"\" width=\"%d\" maxtv=\"%d\" maxrf=\"%f\" maxrel=\"%d\" minsim=\"%f\" maxsim=\"%f\"",
250            awtfp->vwtfname[coll],
251            COLLECTION_SIZE,readnterms,0/*,readwidth+trigs*/,readmaxtv,
252            collmaxrf,collmaxrel,collminsim,collmaxsim);
253        reply+=strlen(reply);       
254        if (parmdetails) { sprintf(reply," mfntag=\"%d,%d\" jdkeys=\"%d\" jdwidth=\"%d\"",collcollmfntag,parmcollmfntag,jdtabcats,jdtabwidth); reply+=strlen(reply); }       
255        pcolname=awtfp->vwtfname[coll]; 
256        sprintf(reply,">%s",pcolname);
257        reply+=strlen(reply);
258        sprintf(reply,"</collection>\n");
259        reply+=strlen(reply);
260       
261        if (parmtext) {
262            sprintf(reply,"<document size=\"%d\" maxrf=\"%f\" maxrel=\"%d\" minsim=\"%f\" maxsim=\"%f\"",
263                strlen(parmtext),
264                parmmaxrf,parmmaxrel,parmminsim,parmmaxsim);
265            reply+=strlen(reply);
266            if (parmdetails) { sprintf(reply," jd=\"%d\" v=\"%d\" id=\"%d\"",joinjd,showv3,showid); reply+=strlen(reply); }
267            sprintf(reply,">%s",parmtext);
268            reply+=strlen(reply);
269            sprintf(reply,"</document>\n");
270            reply+=strlen(reply);
271        }
272        sprintf(reply,"</parms>\n");
273        reply+=strlen(reply);
274    }
275       
276    /* end col
277    */
278    /* return if documents= missing */
279    if (!parmtext) if (!parmdocumentsdb) return coll;
280
281
282   
283    /* Document
284    */
285   
286    /* get secs_ for elapsed */
287    secs_startdoc=time(&secs_now);
288       
289    /* setup filesnames
290    */   
291    if (parmtext) {
292    }
293    else {
294        if (!*docvdb) sprintf(docvdb,"%s.v",parmdocumentsdb);
295        if (!*docydb) sprintf(docydb,"%s.y",parmdocumentsdb);
296    }
297
298    if (*docydb) dbdocydb=docydb;
299   
300    /* init output
301    */
302    if (*docydb) {
303        recisis0(docydb);
304        record(outcrec,docydb,0L);
305    }
306
307    /* main loop: process each document against all docs in collection
308    */
309    count=0;
310    for (docmfn=1; ; docmfn++) {
311
312        /* init similarity computation and most similar hit */
313#include "w2iscms.c"
314///////////////////////////////////////////////////////////////////////////////////////////////////
315
316        /* read term vector */
317#include "w2rdoc.c"
318///////////////////////////////////////////////////////////////////////////////////////////////////
319
320        /* init list of relevant terms */
321#include "w2setrt.c"
322///////////////////////////////////////////////////////////////////////////////////////////////////
323
324        /* init term WEIGHTs for the document */
325        memset(WEIGHT,0x00,readnterms*sizeof(float));
326
327        /* init HIT list = docs in collection having 1+ of document terms */
328        memset(HITS,0x00,hitbytes);
329
330#include "w2slng.c"
331///////////////////////////////////////////////////////////////////////////////////////////////////
332
333        /* loop term vector fields
334        */
335        for (docv=docvector, docloop=docvectcnt; docloop--; docv++) {
336
337            /* get term key */
338#include "w2tkey.c"
339///////////////////////////////////////////////////////////////////////////////////////////////////
340
341            /* similarity computation */
342#include "w2tksum.c"
343///////////////////////////////////////////////////////////////////////////////////////////////////
344
345            /* store weight */
346            WEIGHT[dochidx]=weight;
347           
348            /* OR collection mfns (where term occurs) into HIT - w2rhit(HITS,colxdb,fldarea) */
349#include "w2rhit.c"
350///////////////////////////////////////////////////////////////////////////////////////////////////
351
352        } /* end loop term vector elements for HIT construction */
353
354       
355        /* loop throught hit records and process against the corresponding vector WEIGHT[0..nterms-1]
356        */
357        for (hitmfn=1; hitmfn <= COLLECTION_SIZE; hitmfn++) {
358
359#include "w2rtphix.c"
360///////////////////////////////////////////////////////////////////////////////////////////////////
361
362            if (parmtrace & 0x10) printf("16|%"_LD_"|%"_LD_"\n",docmfn,hitmfn);
363
364#include "w2ctv.c"
365///////////////////////////////////////////////////////////////////////////////////////////////////
366
367            /* compute similarity between input document and collection doc
368            */
369#include "w2simil.c"
370///////////////////////////////////////////////////////////////////////////////////////////////////
371
372            /* output results
373            */
374#include "w2rel1.c"
375///////////////////////////////////////////////////////////////////////////////////////////////////
376
377        } /* end loop throught hit records and process the corresponding vector */
378
379        /* output related collection docs for the document
380        */
381#include "w2out1.c"
382///////////////////////////////////////////////////////////////////////////////////////////////////
383
384        count++;
385        if (parmtell) if (count%parmtell == 0) fprintf(stderr,"+++ %"_LD_"\n",count);
386       
387        if (parmtext) break;
388
389       
390    } /* end read term vector */
391
392
393    /* output collapsed results last record */
394#include "w2outx.c"
395///////////////////////////////////////////////////////////////////////////////////////////////////
396
397    /* close input text and results
398    */
399    if (*docvdb) {
400        dbxflush(docvdb); /* close/flush */
401    }
402    if (*docydb) {
403        dbxflush(docydb); /* close/flush */
404    }
405
406    /* release list of related
407    */
408#if IFFREE
409#if CICPP
410    delete lista;
411#else /* CICPP */
412     if (lista) FREE(lista);
413#endif /* CICPP */
414    lista=NULL;
415#endif
416
417    /* get secs_ for elapsed */
418    secs_docok=time(&secs_now);
419
420    /* ... */
421    if (!reply) fatal("trigcoll/reply");
422
423    /* log execution
424    */
425    //reply..
426    if (replyhere && 0) {
427        sprintf(reply,"<elapsed");
428        reply+=strlen(reply);
429        if (secs_colok-secs_start) { 
430            sprintf(reply," col=\"%"_LD_"\" doc=\"%"_LD_"\"",(LONGX)secs_colok-secs_start, (LONGX)secs_docok-secs_startdoc);
431            reply+=strlen(reply);
432        }
433        sprintf(reply,">%"_LD_"</elapsed>\n",(LONGX)secs_docok-secs_start);
434        reply+=strlen(reply);
435    }
436
437#if FATRAPWT
438     /* restore/notrap */  //strcpy(fatal_iomsg,"");
439     memcpy(fatal_jumper,z_jumper,sizeof(fatal_jumper)); strcpy(fatal_iomsg,z_iomsg); fatal_errcod=z_errcod; dbxopt_errno=z_xerrno;
440#endif
441
442    /* end doc
443    */
444    return coll;   
445}
Note: See TracBrowser for help on using the browser.