forked from NicoleJAVA/Vector-Space-Model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainV25.cpp
144 lines (93 loc) · 3.67 KB
/
mainV25.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
/****************** Ver. 25 - main.cpp *********************
1.) Nicole does N O T want to write that sort-list-node STUFF ANYMORE !
************************************************************/
#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 ];
int stopSize = 0;
int tokenSize = 0;
int stemSize = 0;
int currDictSize = 0;
int i = 0;
int docloop = 1; // docloop ranges form [ 1 ---> 1095 ]
/*******************************/
/**** open stopFile ********/
/*******************************/
stopFile=fopen( "stopwordfile.txt", "r" );
txtToArray( stopFile, stopArr, stopSize );
clear_array( article );
rmvStop( article, stopArr, stopSize, tokenSize );
// After rmvStop(), rmvStop() first resets tokenSize to zero
//and then updates tokenSize
/**************************************/
/**** loop every "docloop.txt" *****/
/**************************************/
for( docloop = 1; docloop <= MAX_DOC_LOOP; docloop++ ){ // Start-0-for-loop
create_txtTitle( docloop );
beforeStemFile = fopen( "afile.txt" , "w" );
if ( beforeStemFile==NULL ) perror ( "\n In main() : File Cannot Be Opened.\n" );
else // 2-if-else
{
clear_array( stemByPorter );
//---while-loop to write the stuff in Winto aFile >>
//---BeforeEnter while-loop,tokenSize's alreadyBeenUpdated by rmvStop()
while( i <= tokenSize ){
/**************************************/
/**** write to beforeStemFile *****/
/**************************************/
fprintf( beforeStemFile, "%s ", article[ i ] );
i++;
} // End-3-while
fclose( beforeStemFile );
/*--------------------------------------------------------*/
stemFile = fopen( "afile.txt" ,"r");
rewind(stemFile);
porter( 1, stemByPorter, tokenSize, stemFile, stemmingResultFile );
fclose(stemFile);
printf("After porter(), tokenSize is %d\n", tokenSize );
/*--------------------------------------------------------*/
} // 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( ) */