forked from generalpacific/file-retriever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.c
executable file
·149 lines (116 loc) · 2.97 KB
/
index.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
145
146
147
/* Author : Chaudhary Prashant
Desc : The main function creating the index by reading file names from the file named 'files.txt'
License : GPLv3
*/
#include"index.h"
#include"fileExtension.h"
extern int numOfDocs;
extern int fileLen[MAXDOCS];
int main(){
//int indexer() {
FILE *files,*fp,*conf;
char temp[MAXIMUM],tempFileName[MAXIMUM],filesName[MAXIMUM],textFileName[MAXIMUM];
int i,docId = 1;
int fileType;
int ret;
int totalErrors = 0;
initializeStopWordsArray();
initializeTrie();
/* conf = fopen("CONFIG","r");
readLine(conf,filesName);
fclose(conf);*/
files = fopen("INDEX/files.txt","r");
if(files == NULL){
goto createStatusFile;
}
while(readLine(files,tempFileName) != FAIL) {
printf("%d \n",docId);
printf("%s\n",tempFileName);
fileType = checkFileExtension(tempFileName);
strcpy(textFileName,"temp.txt");
if(fileType == PDF){
ret = convertPdfToTxt(tempFileName,textFileName);
if(ret != SUCCESS){
++totalErrors;
++docId;
continue;
}
}
else if(fileType == DOC){
ret = convertDocToTxt(tempFileName,textFileName);
if(ret != SUCCESS){
++totalErrors;
++docId;
continue;
}
}
else if(fileType == ODT){
ret = convertOdtToTxt(tempFileName,textFileName);
if(ret != SUCCESS){
++totalErrors;
++docId;
continue;
}
}else if(fileType == TXT){
strcpy(textFileName,tempFileName);
}else if(fileType == 0){
++totalErrors;
++docId;
continue;
}
fp = fopen(textFileName,"r");
if(fp == NULL){
++totalErrors;
++docId;
continue;
}
// Read each filename from the file 'files.txt'
// For each filename, read each word and add to index trie.
while(readWord(fp,temp) != FAIL) {
convertToLowerCase(temp);
removeSpecialSymbols(temp);
// printf("%s ",temp);
if(temp[0] == '\0' || temp[0] == '\t' || temp[0] == ' ' || temp[0] == '\n')
continue;
if(checkForStopWords(temp) != SUCCESS) {
int i = 0;
// Presently on the words containing letters are allowed
while(temp[i] != '\0') {
if(temp[i] < 97 || temp[i] > 122)
break;
++i;
}
if(temp[i] == '\0') {
fileLen[docId]++;
// printf("%d %s\n",docId,temp);
addTerm(temp,docId);
}
//if(temp[0] >= 97 && temp[0]<=122) {
// addTerm(temp,docId);
//}
//printf("%s\n",temp);
}
}
++docId;
fclose(fp);
if(fileType != TXT){
system("rm temp.txt");
system("touch temp.txt");
}
printf("...Done\n");
}
//printf("\nTrie Traversal\n");
//traverseTerms();
numOfDocs = docId - 1;
printf("Number of docs : %d\n",numOfDocs);
printf("Number of Errors : %d\n",totalErrors);
// traverseTerms();
createIndexFile();
createStatusFile:
system("echo \"Index Status\n==================\nIndex created on :\n\" > INDEX/STATUS.txt");
system("date >> INDEX/STATUS.txt");
system("echo \"Directory indexed : \"#// >> INDEX/STATUS.txt");
sprintf(temp,"echo \"No of Documents indexed : %d\" >> INDEX/STATUS.txt",numOfDocs);
system(temp);
return 0;
}