Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this question please, below is what i have. myword.h #include mystring.h #define MAX_WORD 30 #define MAX_LINE_LEN 1000 #define MAX_WORDS 1000 typedef

image text in transcribed

I need help with this question please, below is what i have.

myword.h

#include "mystring.h" #define MAX_WORD 30 #define MAX_LINE_LEN 1000 #define MAX_WORDS 1000 typedef struct word { char word[MAX_WORD]; int frequency; } WORD; typedef struct words { WORD word_array[MAX_WORDS]; int line_count; int word_count; int keyword_count; } WORDSUMMARY; void set_stopword(char *filename, char *stopwordsp[]); int contain_word(char *stopwords[], char *word); int str_contain_word(char *str, char *word); int process_word(char *filename, WORDSUMMARY *words, char *stopwords[]); int save_to_file(char *filename, WORDSUMMARY *words);

#include "myword.h" void set_stopword(char *filename, char *stopwords[]) { // your implementation, refer to class code example 22 -- csv file read with string value } // this function check if the word is contained in directory stopwords[] // returns 1 if yes, 0 otherwise. It use function str_contain_word() int contain_word(char *stopwords[], char *word) { // your code } // this function check if word is a word in string str, // returns 1 if yes, 0 otherwise int str_contain_word(char *str, char *word) { if (str == NULL || word == NULL) return 0; // your code return 0; } int process_word(char *filename, WORDSUMMARY *words, char *stopwords[]) { const char delimiters[] = " .,;:!()&?- "'"; // your implementation } int save_to_file(char *filename, WORDSUMMARY *words) { // your implementation, use the following formats // fprintf(??, "%-20s %8d ", "Line count", words->line_count); // fprintf(??, "%-18s %10s ", "Keyword", "frequency"); return 0; }

Common_english_words.txt a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,isn,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,s,said,say,says,she,should,since,so,some,t,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your

a4q2.c

#include  #include  #include "mystring.h" #include "myword.h" int main(int argc, char *args[]) { char infilename[40] = "textdata.txt"; //default input file name char outfilename[40] = "result.txt"; //default output file name char stopwordfilename[40] = "common-english-words.txt"; //default stop word file if (argc > 1) { if (argc >= 2) strcpy(infilename, args[1]); if (argc >= 3) strcpy(outfilename, args[2]); if (argc >= 4) strcpy(stopwordfilename, args[3]); } //stop word model: as array of strings char stopword_arrays[26][100] = {0}; char *stopwords[26]; int i; for (i=0; i 

mystring.h

*/ #include  int str_length(char *); int word_count(char *); void lower_case(char *); void trim(char *); 

mystring.c

#include "mystring.h" int str_length(char *s) { if (s == NULL) return -1; int counter = 0; while (*s) {counter++; s++;} return counter; } int word_count(char *s) { if (s == NULL || *s == '
Develop a C program which reads and processes an input text file like this textdata.txt. It retrieves information nuim number of all words, number of distinct non-common words, . non-common words and their frequencies. Note that common words, are also known as stop words, like words in this file). It outputs the retrieved information to a file like this result.txt. Specilically, writc C souree programsmyword.h and myword.c containing the following: I, structure definitions typedef struct word 1 char wordt3e NORO typedef struct words WORD word array101; int line count int word count; int kayword_count 2. void set_stopword (char *filename, char *stopwords[])is functions reads stop words from the common word file by filename, and puts them in the stop word dictionary data structure as an array of 26 strings, each string holds all stop words starting with the same alphabet, separated by comma ".". The array of strings is passed parameter char "stopwordsl] stopwords|i] holds the pointer of the i-th string 3. int contain_word(char *stopwords[], char *word); this function checks if the given word is contained in stop word dictionary char stopwords[] t retus if true otherwise 0 4. int str_contain_word (char *str, char *word); this checks if the given *word is contained in a given string str, returns 1 if yes and 0 otherwise. For example, if str is "the,this,tha", word is this", then it returns 1 5. int process_word(char *filename, WORDSUMMARY *words, char *stopwords[]); this function opens and reads text file of name passed by filename line by line. For each line, it gets each word, if it is not a stop word, check if it is already in array words->word array, if yes, increases its frequency by 1, otherwise inserts it to the end of the word array and set its frequency 1. Meantime, it updates the count infomation. 6. int save_to_file(char *filename, WORDSUMMARY *words); this saves the data of WORDSUMMARY words to file of name passed by *filename in specified format. 7. Use the provided main function file a4q2.c to test your programs as the following Develop a C program which reads and processes an input text file like this textdata.txt. It retrieves information nuim number of all words, number of distinct non-common words, . non-common words and their frequencies. Note that common words, are also known as stop words, like words in this file). It outputs the retrieved information to a file like this result.txt. Specilically, writc C souree programsmyword.h and myword.c containing the following: I, structure definitions typedef struct word 1 char wordt3e NORO typedef struct words WORD word array101; int line count int word count; int kayword_count 2. void set_stopword (char *filename, char *stopwords[])is functions reads stop words from the common word file by filename, and puts them in the stop word dictionary data structure as an array of 26 strings, each string holds all stop words starting with the same alphabet, separated by comma ".". The array of strings is passed parameter char "stopwordsl] stopwords|i] holds the pointer of the i-th string 3. int contain_word(char *stopwords[], char *word); this function checks if the given word is contained in stop word dictionary char stopwords[] t retus if true otherwise 0 4. int str_contain_word (char *str, char *word); this checks if the given *word is contained in a given string str, returns 1 if yes and 0 otherwise. For example, if str is "the,this,tha", word is this", then it returns 1 5. int process_word(char *filename, WORDSUMMARY *words, char *stopwords[]); this function opens and reads text file of name passed by filename line by line. For each line, it gets each word, if it is not a stop word, check if it is already in array words->word array, if yes, increases its frequency by 1, otherwise inserts it to the end of the word array and set its frequency 1. Meantime, it updates the count infomation. 6. int save_to_file(char *filename, WORDSUMMARY *words); this saves the data of WORDSUMMARY words to file of name passed by *filename in specified format. 7. Use the provided main function file a4q2.c to test your programs as the following

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions