i need to write a code on how can break a sentence into word and find out the word belong to.
example :
when user input a sentence cindy walk slow.
1.break the sentence into cindy,walk,slow.
2.get each word belong to and display.
- cindy is a noun
- walk is a verb
- slow is a adjective.
i had make 2 file text:
1. verb .txt
2. adjective
verb.txt
eat
walk
ran
sleep
adjective
fast
slow
pretty
this is the code i had done:
const size=100; //size of string
char string[size],temp[size][32];
char *tokenPtr;
int i=0;
cout<<"input string\n";
cin.getline(string,size);//read line of string
/*function char *strtok(char *s1,const char *s2) breaks s1 into token(word)
separated by character in s2
*/
tokenPtr =strtok(string," ");//pointer to first token
while (tokenPtr != NULL)
{
strcpy(temp[i],tokenPtr);//save the token to array
i++;
tokenPtr=strtok(NULL," ");
}
for(int j=0;j<i;j++)
{
char word1[30],word2[30];
ifstream dictionary1("verb.txt");
ifstream dictionary2("adjective.txt");
while (dictionary1>>word1)
if (strcmp(word1,temp[j])==0)
cout<<temp[j]<<" is a verb \n";
while (dictionary2>>word2)
if (strcmp(word2,temp[j])==0)
cout<<temp[j]<<" is a adjective \n";
}
return 0;
}
the output:
input string
ali walk slow
walk is a verb
slow is a adjective
what i want to know is how i can get word ali belong to?
i didn't want to make a text file that contain of the noun.
if the word not in the verb.txt and adjective.txt,therefore it is a noun..
please help me..
anyway thank you.