-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
210 lines (131 loc) · 5.55 KB
/
main.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
/****************** Ver. 26 - main.cpp *********************
1.)
In txtToArray( )
must return the result 'twoDimArr[][]',
or must pass by address of the argument 'twoDimArr[][] !
************************************************************/
#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"
#include "doctxtname.cpp"
#define MAX_STR_LEN 30
#define MAX_STOP_SIZE 500
#define APPEND 0
#define RMV 1
#define MAX_DOC_LOOP 10
#define DICT_SIZE 1000//dictionary size:total number of tokens of all docs
using namespace std;
ListNode *dummyS; // global dummy pointer for Sorting
/*------------------------------------------------*/
int main()
{
FILE * stopFile;
FILE * beforeStemFile;//After rmvstop( ), write article[] to beforStemFile
FILE * stemFile;// R E A D - O N L Y ! stemFile's only for reading
FILE * stemmingResultFile;//porter( ) writes result into stemmingResultFile
FILE * newsFile;
FILE * vectorFile;
ListNode *dictNode; /* dictionary list node */
std::string newsSourceTitle ; // const char * newsSourceTitle;
std::string stemResultTitle ; // const char * stemResultTitle;
std::string vectorTitle ; // const char * vectorTitle;
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 NEWSbeforeRmvStop[ 10000 ][ MAX_STR_LEN ];
// Before rmvStop( ), run the following :
// Within every loop==docloop, NEWSbeforeRmvStop will be cleared
// and then be passed to txtToArray(fileTitle, $this, token# )
int stopSize = 0;
int stopTokenSize = 0;
int stemSize = 0;
int currDictSize = 0;
int NEWStokenSize = 0;
int i = 0;
int docloop = 1; // docloop ranges form [ 1 ---> 1095 ]
/*******************************/
/**** open stopFile ********/
/*******************************/
stopFile=fopen( "stopwordfile.txt", "r" );
printf("\nStopFile's opened. Now txtToArray(stopfile)." );
txtToArray( stopFile, stopArr, stopSize );
// txtToArray updates stopSize
printf("\nHello main >> stopArr[2] is %s.", stopArr[2] );
clear_array( article );
// Ver. 26 Discard : rmvStop( article, stopArr, stopSize, stopTokenSize, );
// After rmvStop(), rmvStop() first resets stopTokenSize to zero
//and then updates stopTokenSize
puts("\n\n");
/********************************************************* M A G I C ****/
beforeStemFile = fopen( "happy.txt" , "r" );
// old >> aFile = fopen( "afile.txt" , "w" );
txtToArray( beforeStemFile, NEWSbeforeRmvStop, NEWStokenSize );
// txtToArray updates NEWStokenSize
printf("\nHello main >> NEWStokenSize is %d.", NEWStokenSize );
printf("\nHello main >> beforeStemFile[20] is %s.", beforeStemFile[20] );
clear_array( article );
rmvStop( article, stopArr, stopSize, NEWStokenSize, NEWSbeforeRmvStop );
puts("\nEnd M A G I C \n\n");
/********************************************************** M A G I C ******/
/**************************************/
/**** loop every "docloop.txt" *****/
/**************************************/
for( docloop = 1; docloop <= 0; docloop++ ){ // Start-0-for-loop
printf("\n\nNow it's in %d-th doloop.\n", docloop );
newsSourceTitle = create_txtTitle( docloop, 1 );
stemResultTitle = create_txtTitle( docloop, 0 );
puts( newsSourceTitle.c_str() );
puts( stemResultTitle.c_str() );
beforeStemFile = fopen( newsSourceTitle.c_str() , "w" );
// old >> aFile = fopen( "afile.txt" , "w" );
txtToArray( beforeStemFile, NEWSbeforeRmvStop, NEWStokenSize );
printf("\nHello main >> beforeStemFile[2] is %s.", beforeStemFile[2] );
clear_array( article );
rmvStop( article, stopArr, stopSize, NEWStokenSize, NEWSbeforeRmvStop );
if ( beforeStemFile==NULL ) perror ( "\n In main() : File Cannot Be Opened.\n" );
else // 2-if-else
{
clear_array( stemByPorter );
i = 0;
//---while-loop to write the stuff in Winto aFile >>
//---BeforeEnter while-loop,tokenSize's alreadyBeenUpdated by rmvStop()
while( i <= stopTokenSize ){
/**************************************/
/**** write to beforeStemFile *****/
/**************************************/
fprintf( beforeStemFile, "%s ", article[ i ] );
// old >> fprintf( aFile, "%s ", article[ i ] );
i++;
} // End-3-while
fclose( beforeStemFile );
/*--------------------------------------------------------*/
stemFile = fopen( newsSourceTitle.c_str() ,"r");
stemmingResultFile = fopen( stemResultTitle.c_str(), "w" );
// old >> stemFile = fopen( "afile.txt" ,"r");
rewind(stemFile);
porter( 1, stemByPorter, stopTokenSize, stemFile, stemmingResultFile );
fclose(stemFile);
fclose(stemmingResultFile);
printf("\nHello main >> After porter(), tokenSize is %d\n", stopTokenSize );
/*--------------------------------------------------------*/
puts("\n------- \n");
} // End-2-if-else
} // End-0-for-loop
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( ) */