forked from NicoleJAVA/Vector-Space-Model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainV20.cpp
214 lines (137 loc) · 5.47 KB
/
mainV20.cpp
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* ver. 20 - main( )
1.) Ver. 20
stemByPorter[] 應該要從 i = 1 而非 i = 0 開始, 去做 insertNode ( )
Wrong code :
for( i = 0; i <= tokenSize; i++ ){
insertNode( dictNode, stemByPorter[ i ], i );
Corrct Code :
for( i = 1; i <= tokenSize; i++ ){
*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <strings.h>
#include <unistd.h>
#include <ctype.h>
#include "rmvstop.cpp"
// #include "porter.cpp"
#include "dictCpp.cpp"
#include "sort_firstDict.cpp"
#include "ir.hpp"
#define MAX_STR_LEN 30
#define MAX_STOP_SIZE 500
#define APPEND 0
#define RMV 1
#define MAX_WORD_
#ifndef DOC_NUM
#define DOC_NUM 1095
#endif
#define DICT_SIZE 1000/* dictionary size : total number of tokens of all docs.*/
using namespace std;
/*------------------------------------------------*/
int main()
{
FILE * stopFile;
FILE * aFile;
FILE * stemFile; /* pointer stemFile will be passed to poter( ) */
ListNode *dictNode; /* dictionary list node */
char stopArr[ MAX_STOP_SIZE ][ MAX_STR_LEN ];
char article[ 10000 ][ MAX_STR_LEN ];
char check[ 10000 ][ MAX_STR_LEN ];
char stemByPorter[ 10000 ][ MAX_STR_LEN ];
/* PPS. Don't name the array as "porter" because it would be confused */
/* with "poter.cpp" and "poter( );" */
char dict[ DICT_SIZE ][ MAX_STR_LEN ];
char **dptr = NULL; /* dictionary pointer */
dptr = (char**)malloc(sizeof(char*)*20);
int stopSize = 0;
int tokenSize = 0;
int stemSize = 0;
int currDictSize = 0;
int i = 0;
stopFile=fopen( "stopwordfile.txt", "r" );
txtToArray( stopFile, stopArr, stopSize );
/* Testing arrayToListNode */
printf("\n\n\n\n\n ------------------------------" );
printf("\n Testing arrayToListNode\n\n\n\n\n" );
clear_array( article );
rmvStop( article, stopArr, stopSize, tokenSize );
/* PPS. Now rmvStop() resets tokenSize to zero and then updates tokenSize*/
//printf("\nrmvStop( ) done ! " );
aFile = fopen( "afile.txt" , "w" );
if ( aFile==NULL ) perror ( "\n In main() : File Cannot Be Opened.\n" );
else
{
clear_array( stemByPorter );
/* -> write the stuff in article[][] into aFile */
while( i <= tokenSize ){ /* tokenSize has already been updated by rmvStop()*/
fprintf( aFile, "%s ", article[ i ] );
i++;
} /* End 3-while */
fclose( aFile );
/*--------------------------------------------------------*/
stemFile = fopen( "afile.txt" ,"r");
rewind(stemFile);
porter( 1, stemByPorter, tokenSize, stemFile );
fclose(stemFile);
printf("After porter(), tokenSize is %d\n", tokenSize );
/* pre-condition : after porter() is done, stemByPorter[][] now */
/* holds the stemming result of afile.txt. */
/* pre-condition : tokenSize is correctly updated*/
/* H E L L O */
printf("\n先把字典變成 listnode");
/* Ver. 14 開始, deprecate 這行 : arrayToListNode( stemByPorter, tokenSize, dictNode ); */
/* Ver. 14 開始, deprecate 這行 : arrayToDict( stemByPorter, tokenSize, dictNode ); */
printf("先看看作業 1 的 stemByPorter[1] 是 %s.", stemByPorter[1] );
for( i = 1; i <= tokenSize; i++ ){
//printf("先看看作業 1 的 stemByPorter[i] 是 %s.", stemByPorter[i] );
insertNode( dictNode, stemByPorter[ i ], i );
} /* end for */
/*--------------------------------------------------------*/
} /* END 2-if-else */
printf("\n\n E N D - Testing arrayToListNode - E N D - \n\n\n\n\n" );
/* E N D - Testing arrayToListNode - E N D - */
for( int docLoop = 1; docLoop <= 0; docLoop ++ )
{
printf("\n\n\n\n\n------------------------------" );
printf("\ndocument %d.txt", docLoop );
clear_array( article );
rmvStop( article, stopArr, stopSize, tokenSize );
/* PPS. Now rmvStop() resets tokenSize to zero and then updates tokenSize*/
printf("\nrmvStop( ) done ! " );
aFile = fopen( "afile.txt" , "w" );
printf("\nSuccessfully open file. aFile is now : %d", aFile);
printf("\naFile = fopen afile.txt, w" );
if ( aFile==NULL ) perror ( "\n In main() : File Cannot Be Opened.\n" );
else
{
clear_array( stemByPorter );
/* -> write the stuff in article[][] into aFile */
while( i <= tokenSize ){ /* tokenSize has already been updated by rmvStop()*/
fprintf( aFile, "%s ", article[ i ] );
i++;
} /* End 3-while */
fclose( aFile );
printf("\nIn main( ) : fclose aFile." );
/*--------------------------------------------------------*/
stemFile = fopen( "afile.txt" ,"r");
rewind(stemFile);
porter( 1, stemByPorter, tokenSize, stemFile );
fclose(stemFile);
printf("In main( ) : porter is done.\n And tokenSize is %d\n", tokenSize );
/* - - - - - - - - - - - - - - - */
/* dictCpp.cpp*/
/* - - - - - - - - - - - - - - - */
/* pre-condition : after porter() is done, stemByPorter[][] now */
/* holds the stemming result of afile.txt. */
/* pre-condition : tokenSize is correctly updated*/
/* - - - - - - - - - - - - - - - */
/*--------------------------------------------------------*/
} /* END 2-if-else */
} /* End 1-for */
printf( "\n\n\n\n\n\n\n" );
printf( " -------------\n" );
printf( " | Thank you! |\n" );
printf( " -------------\n\n\n\n\n\n\n\n\n\n\n\n\n" );
system("PAUSE");
} /* End main( ) */