int main(int argc, char *argv[])
{
WORD *dict;
FILE *dictfile;
WORD sentence[40];
int isQuestion;
int n_dict, i, j, w;
int pattern[4];
printf("Team 043\nfinal(.c | .o)\nbuild #1\nby Jeremy Pepper\n\n");
printf("Loading dictionary..."); fflush(stdout);
dictfile = fopen("final.dict", "r");
if(!dictfile)
{
printf("or not...\nfinal.dict not found!\n");
return -1;
}
fscanf(dictfile, "%d", &n_dict);
printf("%i entries...", n_dict); fflush(stdout);
dict = malloc(n_dict * sizeof(WORD));
if(!dict)
{
printf("or not...\nOut of memory? Wazzup???\n");
}
for(i = 0; i < n_dict; i++)
{
fscanf(dictfile, "%s", dict[i].word);
for(j = 0; j < 11; j++)
{
fscanf(dictfile, "%d", &dict[i].p_code[j]);
}
}
fclose(dictfile);
printf("done!\n\n");
printf("I currently know nothing but grammar. Be patient.\n");
printf("Be advised--I can't read clauses or phrases yet.\n");
for(;;) /* Loop on Ctrl+C --yes, very unclean */
{
isQuestion = 0;
printf("Please say something: "); fflush(stdout);
w = 0; j = 0; /* j is now a flag */
for(;!j;) /* Exits on end punctuation */
{
scanf("%s", sentence[w].word);
switch(sentence[w].word[strlen(sentence[w].word)-1])
{
case ';':
case ',':
sentence[w].post_punct = sentence[w].word[strlen(
sentence[w].word)-1];
sentence[w].word[strlen(sentence[w].word)-1] = '\0';
break;
case '?':
isQuestion = -1; /* Is meant to pass through */
case '!':
case '.':
sentence[w].post_punct = sentence[w].word[strlen(
sentence[w].word)-1];
sentence[w].word[strlen(sentence[w].word)-1] = '\0';
j = -1;
}
w++;
}
printf("Looking up words in dictionary..."); fflush(stdout);
flagger(sentence, w, dict, n_dict);
printf("done!\nWord possible types:\n");
for(i = 0; i < w; i++)
{
printf("%s: ", sentence[i].word);
for(j = 0; j < 11; j++)
{
switch(sentence[i].p_code[j])
{
case NOUN:
printf("NOUN ");
break;
case PRONOUN:
printf("PRONOUN ");
break;
case VERB:
printf(" LINKING VERB ");
break;
case AVERB:
printf("VERB ");
break;
case ADJECTIVE:
printf("ADJECTIVE ");
break;
case ADVERB:
printf("ADVERB ");
break;
}
}
printf("\n");
}
printf("Scanning sentence structure..."); fflush(stdout);
pdetect(sentence, w, pattern);
printf("done!\nPattern seen: ");
for(i = 0; i < 4; i++)
{
switch(pattern[i])
{
case SUBJECT:
printf("SUBJECT ");
break;
case VERB:
printf("VERB ");
break;
case IO:
printf(" INDIRECT OBJECT ");
break;
case DO:
printf(" DIRECT OBJECT ");
}
}
parseSentence(sentence, w, pattern);
printf("\nParts of speech: ");
for(i = 0; i < w; i++)
{
switch(sentence[i].code)
{
case NOUN:
printf("NOUN ");
break;
case VERB:
case AVERB:
printf("VERB ");
break;
case PRONOUN:
printf("PRONOUN ");
break;
case ADJECTIVE:
printf("ADJECTIVE ");
break;
case ADVERB:
printf("ADVERB ");
break;
}
printf("(%i) ", sentence[i].code);
}
if(isQuestion)
{
printf("Querying database...\n");
databaseRetrieve(sentence, w, MAX_RESPONSE);
}
else
{
printf("Thanks for the knowledge... storing...\n");
databaseAdd(sentence, w);
}
printf("Was that cool now or what?\n\n");
}
return 0;
}
|