Repositories » TXT0
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

The hash table idtab[] in ii.c (and ii1.c) was meant to keep the
document ID string which was meant to be the representation of a

document. However, more about the document needs to be in memory; the
byte-length and token-length for example, so, the Doc structure was
invented and idtab[] renamed to doctab[] and its elements (of type
Node) hold a data item of type Doc.

Changeset 755567d6bb5f

Parent 769c9c738c1b

by Rup Palchowdhury

Changes to 7 files · Browse files at 755567d6bb5f Showing diff from parent 769c9c738c1b Diff from another changeset...

Change 1 of 2 Show Entire File Makefile Stacked
 
20
21
22
23
 
 
24
25
26
27
28
 
 
 
29
30
31
 
62
63
64
65
66
67
68
69
 
 
 
 
 
 
 
 
 
 
 
20
21
22
 
23
24
25
26
27
28
29
30
31
32
33
34
35
 
66
67
68
 
 
 
 
 
69
70
71
72
73
74
75
76
77
78
@@ -20,12 +20,16 @@
  parser.c \   crc.c \   post.c \ - term.c + term.c \ + doc.c    OBJ = $(patsubst %.c,$(O)/%.o,$(SRC))    all: raw2t t2mem ii ii1   +qparse: $(O)/qparse.o $(OBJ) + $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ $(LIBS) +  raw2t: $(O)/raw2t.o $(OBJ)   $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -o $@ $^ $(LIBS)   @@ -62,8 +66,13 @@
 clean:   rm -f $(O)/*.o $(DEPDIR)/*.d raw2t t2mem   -.PHONY: quicktest -quicktest: - ./raw2t <test/tiny.txt | ./t2mem | diff -q - test/tiny.out - ./raw2t <test/two.txt | ./t2mem | diff -q - test/two.out - ./raw2t <test/big.txt | ./t2mem | diff -q - test/big.out +.PHONY: parsetest +parsetest: + ./raw2t <test/tiny.txt | ./t2mem | diff -q - test/tiny.mem + ./raw2t <test/big.txt | ./t2mem | diff -q - test/big.mem +.PHONY: iitest +iitest: + ./ii <test/tiny.t | diff -q - test/tiny.ii + ./ii <test/big.t | diff -q - test/big.ii + ./ii1 <test/tiny.t | sort -t":" -k1,1 | diff -q - test/tiny.ii + ./ii1 <test/big.t | sort -t":" -k1,1 | diff -q - test/big.ii
Change 1 of 1 Show Entire File doc.c Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@@ -0,0 +1,30 @@
+#include <stdlib.h> +#include "Doc.h" + +Doc *newdoc(char *id, unsigned n_byte, unsigned n_term) +{ + Doc *doc; + doc = (Doc *)malloc(sizeof(Doc)); + doc->id = id; + doc->n_byte = n_byte; + doc->n_term = n_term; + return doc; +} + +int doccmp(void *d1, void *d2) +{ + if (((Doc *)d1)->id == ((Doc *)d2)->id) + return 0; + return 1; +} + +unsigned hashdoc(void *data, unsigned hsize) +{ + static unsigned MULTIPLIER = 31; + unsigned h; + char *p; + h = 0; + for (p = (char *)(((Doc *)data)->id); *p != '\0'; p++) + h = MULTIPLIER * h + *p; + return h % hsize; +}
Change 1 of 1 Show Entire File doc.h Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
@@ -0,0 +1,11 @@
+typedef struct Doc Doc; + +struct Doc { + char *id; + unsigned n_term; + unsigned n_byte; +}; + +Doc *newdoc(char*, unsigned, unsigned); +int doccmp(void*, void*); +unsigned hashdoc(void*, unsigned);
Change 1 of 5 Show Entire File ii.c Stacked
 
10
11
12
 
13
14
15
 
21
22
23
24
 
 
25
26
27
28
 
 
29
30
31
32
 
33
34
35
 
50
51
52
53
 
 
 
 
 
 
 
 
 
 
54
55
56
 
61
62
63
64
65
66
67
68
 
 
 
 
 
 
 
 
 
69
70
71
 
102
103
104
105
106
 
 
107
108
109
 
10
11
12
13
14
15
16
 
22
23
24
 
25
26
27
28
 
 
29
30
31
32
33
 
34
35
36
37
 
52
53
54
 
55
56
57
58
59
60
61
62
63
64
65
66
67
 
72
73
74
 
 
75
 
 
76
77
78
79
80
81
82
83
84
85
86
87
 
118
119
120
 
 
121
122
123
124
125
@@ -10,6 +10,7 @@
 #include "term.h"  #include "tokenizer.h"  #include "tfile.h" +#include "doc.h"    enum {NTERMS = 100003, NDOCS = 100003};  /* enum {NTERMS = 10007, NDOCS = 4093}; */ @@ -21,15 +22,16 @@
  TNode *tree;   Post *post;   Term *term; - unsigned n_doc; + Doc *doc; + unsigned n_doc, n_term;   char *p_txt, *ts;   THeader *h; - Node *idtab[NDOCS], *termtab[NTERMS]; - Node *npid, *npt; + Node *doctab[NDOCS], *termtab[NTERMS]; + Node *npdoc, *npdoc_, *npterm, *npterm_;       for (int i = 0; i < NDOCS; i++) - idtab[i] = NULL; + doctab[i] = NULL;   for (int i = 0; i < NTERMS; i++)   termtab[i] = NULL;   @@ -50,7 +52,16 @@
  exit(0);     tdoc->id[tdoc->h->n_id] = '\0'; - npid = hlookup(idtab, newnode(strdup(tdoc->id)), 1, hash, NDOCS, strcmp); + sscanf(tdoc->rsrc[0], "%u", &n_term); + doc = newdoc(strdup(tdoc->id), tdoc->h->n_txt, n_term); + + npdoc_ = newnode(doc); + npdoc = hlookup(doctab, npdoc_, 1, hashdoc, NDOCS, doccmp); + if (npdoc != npdoc_) { + free(doc); + free(npdoc_); + } +   i_ = 0;   p_txt = tdoc->txt;   @@ -61,11 +72,16 @@
  ts = (char *)malloc(i - i_ + 1);   memcpy(ts, p_txt, i - i_);   ts[i - i_] = '\0'; - - npt = hlookup(termtab, newnode(ts), 1, hash, NTERMS, strcmp);   - post = newpost((char *)(npid->data), 1); - term = newterm((char *)(npt->data), 1, post); + npterm_ = newnode(ts); + npterm = hlookup(termtab, npterm_, 1, hash, NTERMS, strcmp); + if (npterm != npterm_) { + free(ts); + free(npterm_); + } + + post = newpost((char *)(((Doc *)(npdoc->data))->id), 1); + term = newterm((char *)(npterm->data), 1, post);     /* if term exists   if post exists at front of list @@ -102,8 +118,8 @@
  /* applyinorder(tree, printtree, "%s:%d "); */     /* fprintf(stderr, "\n"); */ - /* fprintf(stderr, "idtab[]\n"); */ - /* hstats(idtab, NDOCS); */ + /* fprintf(stderr, "doctab[]\n"); */ + /* hstats(doctab, NDOCS); */   /* fprintf(stderr, "termtab[]\n"); */   /* hstats(termtab, NTERMS); */  
Change 1 of 6 Show Entire File ii1.c Stacked
 
9
10
11
 
12
13
14
 
55
56
57
58
 
 
59
60
61
62
63
 
 
64
65
66
 
67
68
69
 
84
85
86
87
 
 
 
 
 
 
 
 
 
 
88
89
90
 
95
96
97
98
99
100
101
102
103
 
 
 
 
 
 
 
 
 
104
105
106
 
112
113
114
115
 
 
116
117
118
119
 
 
120
121
122
123
 
 
 
124
125
126
127
 
 
128
129
 
130
131
132
133
134
135
136
137
138
 
 
 
139
140
141
 
 
142
143
144
 
152
153
154
155
156
 
 
157
158
159
 
9
10
11
12
13
14
15
 
56
57
58
 
59
60
61
62
 
 
 
63
64
65
66
 
67
68
69
70
 
85
86
87
 
88
89
90
91
92
93
94
95
96
97
98
99
100
 
105
106
107
 
 
108
 
 
 
109
110
111
112
113
114
115
116
117
118
119
120
 
126
127
128
 
129
130
131
132
 
 
133
134
135
 
 
 
136
137
138
139
140
 
 
141
142
143
 
144
145
146
147
148
149
150
 
 
 
151
152
153
154
 
 
155
156
157
158
159
 
167
168
169
 
 
170
171
172
173
174
@@ -9,6 +9,7 @@
 #include "term.h"  #include "tokenizer.h"  #include "tfile.h" +#include "doc.h"    enum {NTERMS = 100003, NDOCS = 100003};  /* enum {NTERMS = 10007, NDOCS = 4093}; */ @@ -55,15 +56,15 @@
  TDoc *tdoc;   Post *post, *post_;   Term *term, *term_; - unsigned n_doc; + Doc *doc; + unsigned n_doc, n_term;   char *p_txt, *ts;   THeader *h; - Node *idtab[NDOCS], *termtab[NTERMS], *ii[NTERMS]; - Node *npid, *npt, *npii, *npii_; - + Node *doctab[NDOCS], *termtab[NTERMS], *ii[NTERMS]; + Node *npdoc, *npdoc_, *npterm, *npterm_, *npii, *npii_;     for (int i = 0; i < NDOCS; i++) - idtab[i] = NULL; + doctab[i] = NULL;   for (int i = 0; i < NTERMS; i++)   termtab[i] = NULL;   for (int i = 0; i < NTERMS; i++) @@ -84,7 +85,16 @@
  exit(0);     tdoc->id[tdoc->h->n_id] = '\0'; - npid = hlookup(idtab, newnode(strdup(tdoc->id)), 1, hash, NDOCS, strcmp); + sscanf(tdoc->rsrc[0], "%u", &n_term); + doc = newdoc(strdup(tdoc->id), tdoc->h->n_txt, n_term); + + npdoc_ = newnode(doc); + npdoc = hlookup(doctab, npdoc_, 1, hashdoc, NDOCS, doccmp); + if (npdoc != npdoc_) { + free(doc); + free(npdoc_); + } +   i_ = 0;   p_txt = tdoc->txt;   @@ -95,12 +105,16 @@
  ts = (char *)malloc(i - i_ + 1);   memcpy(ts, p_txt, i - i_);   ts[i - i_] = '\0'; - - npt = hlookup(termtab, newnode(ts), 1, hash, NTERMS, strcmp);   - post = newpost((char *)(npid->data), 1); - term = newterm((char *)(npt->data), 1, post); - npii = newnode(term); + npterm_ = newnode(ts); + npterm = hlookup(termtab, npterm_, 1, hash, NTERMS, strcmp); + if (npterm != npterm_) { + free(ts); + free(npterm_); + } + + post_ = newpost((char *)(((Doc *)(npdoc->data))->id), 1); + term_ = newterm((char *)(npterm->data), 1, post_);     /* if term exists   if post exists at front of list @@ -112,33 +126,34 @@
  add term to hash table   */   - npii_ = hlookup(ii, npii, 1, hashterm, NTERMS, termcmp1); + npii_ = newnode(term_); + npii = hlookup(ii, npii_, 1, hashterm, NTERMS, termcmp1);     if (npii != npii_) { /* a new Term wasn't added to the table */ - term_ = (Term *)(npii_->data); - post_ = (Post *)(term_->plist->data); + term = (Term *)(npii->data); + post = (Post *)(term->plist->data);   - if (postcmp(post, post_) == 0) { - post_->tf++; - post->ref = 0; + if (postcmp(post_, post) == 0) { + post->tf++; + post_->ref = 0;   }   else { - term_->plist = addfront(term_->plist, term->plist); - term_->df++; + term->plist = addfront(term->plist, term_->plist); + term->df++;   } - term->ref = 0; + term_->ref = 0;   }     i_ = i + 1;   p_txt = &(tdoc->txt[i + 1]);     - if (post->ref == 0) { - free(post); - free(term->plist); + if (post_->ref == 0) { + free(post_); + free(term_->plist);   } - if (term->ref == 0) { - free(term); + if (term_->ref == 0) { + free(term_);   }   }   } @@ -152,8 +167,8 @@
  /* hprint(ii, NTERMS); */     /* fprintf(stderr, "\n"); */ - /* fprintf(stderr, "idtab[]\n"); */ - /* hstats(idtab, NDOCS); */ + /* fprintf(stderr, "doctab[]\n"); */ + /* hstats(doctab, NDOCS); */   /* fprintf(stderr, "termtab[]\n"); */   /* hstats(termtab, NTERMS); */  
Change 1 of 2 Show Entire File tokenizer.c Stacked
 
113
114
115
116
 
117
118
119
 
123
124
125
 
 
126
127
128
 
113
114
115
 
116
117
118
119
 
123
124
125
126
127
128
129
130
@@ -113,7 +113,7 @@
  static int len = 0;   n = 0;   for (i = 0; i < size; i++, src++) { - if (t->asciitab[(int)(*src)] == 1) { + if (t->asciitab[(int)(*src)] == SEPCHAR) {   if (len > 0) {   *dest = ' ';   dest++; @@ -123,6 +123,8 @@
  continue;   }   *dest = *src; + if (t->casechange == LOWERCASE && *src >= 65 && *src <= 90) + *dest += 32;   dest++;   len++;   n++;
Change 1 of 1 Show Entire File tokenizer.h Stacked
 
2
3
4
 
 
5
6
7
 
2
3
4
5
6
7
8
9
@@ -2,6 +2,8 @@
 #define KB 1024  #define MB 1048576  #define GB 1073741824 +#define CR 13 +#define LF 10    enum {KEEPCASE, LOWERCASE};  enum {TERM, OTAG, CTAG};