int Deletetable(char* filename,char (*tableindex)[TABLE_NAME_MAX],Column** columnindex,Data*** database) { over=start=0; start=clock(); FILE* file = fopen(filename,"r+"); if(NULL == file) { printf("Error in opening the command file!\n"); return 0; } char buffer[COLUMN_NAME_MAX]; char* command=getwords(file,buffer); //Check Key word Delete if(mystrcmp("delete",command)) { printf("The file should be included the keyword update!\n"); return 0; } command=getwords(file,buffer); //Reading from if(mystrcmp("from",buffer)) { printf("The file should be included the keyword from!\n"); return 0; } //Reading table name command=getwords(file,buffer); int tableoperate = tablenow(buffer,tableindex); //The order of opertating table if(tableoperate==-1) { printf("Can't Locate the table!\n"); return 0; } int andor[AND_OR_MAX]; // and or ARRAY or=0 and=1 -1 is the end int likeequal[LIKE_EQUAL_MAX]; //like = Array -1 is the end 0=like 1 = = char colvalue[COL_READ_MAX][COLUMN_NAME_MAX]; //Recieve every column value int colname_do[COL_READ_MAX]; //Order of column to delete int col_delete=0; checkline2(file,andor,likeequal,colvalue,colname_do,tableoperate,columnindex); //Reading the last line fclose(file); //close file int* index = CreateIndex(tableoperate,colname_do,0,likeequal,colvalue,andor,columnindex,database) ; //Create Searching Index int loriginal = columnindex[tableoperate][0].length; //Reading data length of the original one Data** head = deleteatable(columnindex,database,tableoperate,index); int count=fprintalltable(columnindex[tableoperate],head,tableoperate,"074090_delete.txt"); //write to the file free(index); return loriginal-count; }
int main(int argc, char argv[]) { const char * str = "hello world welcom to our world and you are going to be greate persion"; int ret; ret = getwords(str); printf("this sentence is %d words.\n", ret); return 0; }
int * votefor_1_svc(char **argp, struct svc_req *rqstp) { char sent[100]; char name[100]; int nwords; static int result; sprintf(sent,"%s",*argp); nwords = getwords(sent,words,10); //for(i = 0; i < nwords; i++) //printf("%s\n", words[i]); strcpy(name,words[0]); int voterid; voterid = atoi(words[1]); for(j=0;j<vid_count;j++) { if(voterid == vid[j]) //Exists condition valid voter { flag = 1; } } if(flag==1) // Valid voter { for(j=0;j<voted_count;j++) { if(voterid == voted[j]) // Already voted { result = 1; flag = 0; } } if(flag==1) // Not voted yet { for(j=0;j<c_count;j++) { if(strcmp(candidate[j].name,name)==0) { result = 2; candidate[j].vote = candidate[j].vote + 1; voted[voted_count]=voterid; voted_count++; flag = 0; } } if(flag==1) // Candidate does not exist { result = 3; strcpy(candidate[c_count].name,name); candidate[c_count].vote = 0; candidate[c_count].vote = candidate[c_count].vote + 1; voted[voted_count]=voterid; voted_count++; c_count++; } } } else { result = 4; } flag = 0; return &result; }
int tablesearch(char* filename,char (*tableindex)[TABLE_NAME_MAX],Column** columnindex,Data*** database) { FILE* file; int isnosearch=0; // Is there no restriction to the column name int colname_print[COL_READ_MAX]; // Store the number of column to print -1 is the end int colname_do[COL_READ_MAX]; // the order os Column to operte -1 is the end char colnameprints[COL_READ_MAX][COLUMN_NAME_MAX];// recieve every columname to print char colvalue[COL_READ_MAX][COLUMN_NAME_MAX]; //recieve evey column_value int colname_order; //the order of column to sort by int colnumber=0; int andor[AND_OR_MAX]; // and or ARRAY or=0 and=1 -1 is the end int likeequal[LIKE_EQUAL_MAX]; //like = Array -1 is the end 0=like 1 = = // char buffer[LINE_MAX]; //Buffer of file int countavalible=0; //Items that has been read int tableoperate; // The order of operting table int countnumber=0; //How Many columns to print int numberofprint=0; //how many lines to print if 0 means all int asc=ASC; if((file=fopen(filename,"r"))==NULL) { printf("Error in opening the file!\n"); return 0; } start=over=(time_t)0; //count the time start=clock(); checkline1(file,colname_print,&numberofprint,colnameprints,&tableoperate ,tableindex,columnindex); if(database[tableoperate] == NULL ) {printf("The table hasn't been Initialized!\n"); return 0;} char *revalue=checkline2(file, andor, likeequal,colvalue,colname_do,tableoperate,columnindex); char* command=revalue; if(command==NULL) { colname_order=0; asc=ASC; } else { if(!mystrcmp(command,"order")) { char buffer[LINE_MAX]; command=getwords(file,buffer); //by if(mystrcmp("by",buffer)) { printf("You should follow order a by\n"); return 0; } command=getwords(file,buffer); //column_name colname_order= columnnow(buffer,tableoperate,columnindex); if(colname_order == -1) {printf("Error in lcating the %s column\n",buffer); return 0; } command=getwords(file,buffer); //ASC DESC or EOF if(command==NULL) asc=ASC; else if(!mystrcmp("ASC",buffer)) asc=ASC; else asc=DESC; } } fclose(file); int *index=CreateIndex(tableoperate,colname_do,colname_order,likeequal,colvalue,andor,columnindex,database); // Create index of table to print int _coltype= columnindex[tableoperate][colname_order].nametype; //Style of data to sort by int numberitems=0; //How many lines to print while( index[numberitems] != -1) numberitems++; shellsort(index ,numberitems,_coltype,asc,database[tableoperate][colname_order]); //Put the result to file and return how many has been searched int countsearch = fileprint("074090_select.txt",numberofprint,colname_print,database[tableoperate],columnindex[tableoperate],index); free(index); //Free the index return countsearch; }
char* checkline2(FILE* file,int* andor,int* likeequal,char (*colvalue)[COLUMN_NAME_MAX],int* colname_do,int tableoperate,Column** columnindex) { //check the key word Where char buffer[LINE_MAX]; char *command=getwords(file,buffer); //read if(command!=NULL&&!mystrcmp(buffer,"where")) { int countcolname=0; int countlike=0; int countand=0; int countcolvalue=0; command=getwords(file,buffer); //read the first columnname int isname=1; //The string is a name or a column value while(mystrcmp(command,LINEEND)!=0 && mystrcmp(command,"order")!=0) //没有读完一行 { if(mystrcmp(command,"like")==0) { likeequal[countlike++]=0; } else if(mystrcmp(command,"=")==0) { likeequal[countlike++]=1; } else if(mystrcmp(command,"AND")==0) { andor[countand++]=1; } else if(mystrcmp(command,"OR")==0) { andor[countand++]=0; } else if (isname) { colname_do[countcolname++]= columnnow(command,tableoperate,columnindex); isname=0; } else //It's the value of column { mystrcpy(colvalue[countcolvalue++],command); isname=1; } command=getwords(file,buffer); } likeequal[countlike]=-1; andor[countand]=-1; colname_do[countcolname]=-1; mystrcpy(colvalue[countcolvalue],buffer); colvalue[countcolvalue+1][0]='\0'; if(mystrcmp(command,"order")) command=getwords(file,buffer); return command; } else { likeequal[0]=-1; andor[0]=-1; colname_do[0]=-1; colvalue[0][0]='\0'; return command; } }
int checkline1(FILE* file,int* colname_print,int* numberofprint,char (*colnameprints)[COLUMN_NAME_MAX],int* tableoperate ,char (*tableindex)[TABLE_NAME_MAX],Column** columnindex) { char buffer[LINE_MAX]; //Buffer int isall=0; char* command=getwords(file,buffer); //read keyword select if(mystrcmp(command,"select")!=0) { printf("The file should be started by select\n"); return 0; } command=getwords(file,buffer); //Judge the existance of TOP if(mystrcmp(command,"TOP")==0) { command=getwords(file,buffer); //read the number after TOP *numberofprint=atoi(command); command=getwords(file,buffer); if(!mystrcmp("*",command)) { isall=1; //is all to print command=getwords(file,buffer);//read from if(mystrcmp("from",buffer)) { printf("you should write a from before your table name\n"); return 0; } command=getwords(file,buffer); //read table name } else //read columname { isall=0; int scount=0; while(mystrcmp(COLUMNEND,command)) { mystrcpy(colnameprints[scount++],command); command=getwords(file,buffer); } mystrcpy(colnameprints[scount],buffer); colnameprints[scount+1][0]='\0'; command=getwords(file,buffer);//read keyword from if(mystrcmp("from",buffer)) //not from { printf("you should write a from before your table name\n"); return 0; } command=getwords(file,buffer); //read table name } } else if(mystrcmp(command,"*")==0) { numberofprint=0; isall=1; command=getwords(file,buffer);//read keyword from if(mystrcmp("from",buffer)) { printf("you should write a from before your table name\n"); return 0; } command=getwords(file,buffer); //read table name } else //read column { numberofprint=0; isall=0; int scount=0; while(mystrcmp(COLUMNEND,command)) { mystrcpy(colnameprints[scount++],command); command=getwords(file,buffer); } mystrcpy(colnameprints[scount],buffer); colnameprints[scount+1][0]=0; command=getwords(file,buffer);//read from if(mystrcmp("from",buffer)) { printf("you should write a from before your table name\n"); return 0; } command=getwords(file,buffer); //read table name } *tableoperate = tablenow(buffer,tableindex); //decide the order of operting table if(isall) //if all are to print { int icount=0; //count how many columns while(columnindex[*tableoperate][icount].name[0]!='\0') icount++; for(int i=0;i<icount;i++) { colname_print[i]=i; } colname_print[icount]=-1;//END } else //Not all is to print { int count_i=0; while(colnameprints[count_i][0]!=0) { colname_print[count_i++]= columnnow(colnameprints[count_i],*tableoperate ,columnindex); } colname_print[count_i]=-1; //END } return 1; }
/* Analyze a two word sentence */ int english(void) { char *msg; int type1, type2, val1, val2; verb = object = motion = 0; type2 = val2 = -1; type1 = val1 = -1; msg = "bad grammar..."; getwords(); if (!(*word1)) return 0; /* ignore whitespace */ if (!analyze(word1, &type1, &val1)) /* check word1 */ return 0; /* didn't know it */ if (type1 == 2 && val1 == SAY) { verb = SAY; /* repeat word & act upon if.. */ object = 1; return 1; } if (*word2) if (!analyze(word2, &type2, &val2)) return 0; /* didn't know it */ /* check his grammar */ if ((type1 == 3) && (type2 == 3) && (val1 == 51) && (val2 == 51)) { outwords(); return 0; } else if (type1 == 3) { rspeak(val1); return 0; } else if (type2 == 3) { rspeak(val2); return 0; } else if (type1 == 0) { if (type2 == 0) { printf("%s\n", msg); return 0; } else motion = val1; } else if (type2 == 0) motion = val2; else if (type1 == 1) { object = val1; if (type2 == 2) verb = val2; if (type2 == 1) { printf("%s\n", msg); return 0; } } else if (type1 == 2) { verb = val1; if (type2 == 1) object = val2; if (type2 == 2) { printf("%s\n", msg); return 0; } } else bug(36); return 1; }
int main(int argc, char *argv[]) { FILE *inputfiles,*posting_file; int i=0; char *fileinput,*stemming_file,*posting_filename; if(argc < 2) { printf("\nIncorrect Usage. ./keywordengine <filelist.txt>\n"); return 0; } if((inputfiles=fopen(argv[1],"r+"))==NULL) { printf("\nCould not open %s. Exiting\n",argv[1]); exit(0); } if((posting_file=fopen("../output/posting_list_file_input.txt","w"))==NULL) { printf("\nFatal Error! Could not open/create posting_list_file_input.txt. Check output directory.\nErrorcode : %d\n",errno); exit(0); } int after_stemming=0; int before_stemming=0; double ratio=0.0; double array[20]; for(i=0; i<20; i++) { array[i]=0; } while(!feof(inputfiles)) { fileinput=(char *)malloc(sizeof(char)*FILENAME); fscanf(inputfiles,"%s\n",fileinput); stemming_file=(char *)malloc(sizeof(char)*(strlen(fileinput)+8)); strcpy(stemming_file,"output_"); strcat(stemming_file,fileinput); posting_filename=(char *)malloc(sizeof(char)*(strlen(stemming_file)+6)); strcpy(posting_filename,"stem_"); strcat(posting_filename,stemming_file); fprintf(posting_file,"%s\n",posting_filename); /* Tokenise and remove stopwords */ getwords(fileinput); /* Add to postings list */ initialize(); before_stemming=add_document_to_postingslist(stemming_file); /* Apply Porter's Stemmer */ stemmer(stemming_file); /* Add to postings list */ initialize(); after_stemming=add_document_to_postingslist(posting_filename); ratio=(double)after_stemming/before_stemming; //printf("\nbefore=%d and after=%d Ratio= %lf\n",before_stemming,after_stemming,ratio); if(0 <= ratio && 0.05 > ratio ) array[0]++; else if(0.75 <= ratio && 0.765 > ratio ) array[1]++; else if(0.765 <= ratio && 0.780 > ratio ) array[2]++; else if(0.780 <= ratio && 0.795 > ratio ) array[3]++; else if(0.795 <= ratio && 0.810 > ratio ) array[4]++; else if(0.810 <= ratio && 0.825 > ratio ) array[5]++; else if(0.825 <= ratio && 0.840 > ratio ) array[6]++; else if(0.840 <= ratio && 0.855 > ratio ) array[7]++; else if(0.855 <= ratio && 0.870 > ratio ) array[8]++; else if(0.870 <= ratio && 0.885 > ratio ) array[9]++; else if(0.885 <= ratio && 0.9 > ratio ) array[10]++; else if(0.9 <= ratio && 0.915 > ratio ) array[11]++; else if(0.915 <= ratio && 0.930 > ratio ) array[12]++; else if(0.930 <= ratio && 0.945 > ratio ) array[13]++; else if(0.945 <= ratio && 0.960 > ratio ) array[14]++; else if(0.960 <= ratio && 0.975 > ratio ) array[15]++; else if(0.975 <= ratio && 0.990 > ratio ) array[16]++; else if(0.990 <= ratio && 1.05 > ratio ) array[17]++; else if(1.05 <= ratio && 1.20 > ratio ) array[18]++; else if(1.20 <= ratio && 1.35 >= ratio ) array[19]++; i++; free(fileinput); fileinput=NULL; } fclose(posting_file); fclose(inputfiles); gnuplot_ctrl *h1; h1 = gnuplot_init() ; gnuplot_setstyle(h1, "lines"); gnuplot_set_xlabel(h1, "Compression"); gnuplot_set_ylabel(h1, "Frequency"); gnuplot_plot_x(h1, array ,20, "Ratio Graph") ; getchar(); /*Closing the files*/ gnuplot_close(h1); return 0; }