/*********************************************************************************** * File: conj.c * Created: 18 NO 2000 * Author: R. DeArmond. * * This file contains the adj struct and array declaration for conjunctions in the lexicon, and * the prototypes for all of the functions specific n. * The current implementation, using an array to store the lexical entries for each * type of word is adequate for now, but if the lexicon is to be allowed to grow to * any size, this will have to change. In that case, the lexicon will have to be * used in the file, and file access performed whenever the lexicon is to be used. * Currently, a maximum number of adjs (MAX_CONJ = 4) is imposed so that the * array can be declared. ***********************************************************************************/ /*********************************************************************************** * includes ***********************************************************************************/ #include #include #include "conj.h" #include "lib.h" #include "lexicon.h" #include "functions.h" /*********************************************************************************** * local function prototypes ***********************************************************************************/ void print_conj_features(struct conj_struct* conj); /*********************************************************************************** * input: an conjunction struct for which the features are to be displayed. * description: uses printf to display the features to stdout. ***********************************************************************************/ void set_conj_defaults(int n, char *s); /*********************************************************************************** * input: 's' is a string holding the name of the conjunction word. * n is the position in the array that it will be inserted. * description: copies s into the conjunction word in the position in the array indicated * by n. ***********************************************************************************/ /*********************************************************************************** * file scope variables ***********************************************************************************/ // there probably should be better ways to do things than using these, but I don't // understand the linguistic aspects well enough yet. /********************************************/ int conj_cat; int conj_intern_arg; int conj_extern_arg; char conj_word[STRING_SIZE]; char conj_cat_form[STRING_SIZE]; /*********************************************************************************** * extern function implementations ***********************************************************************************/ int find_conj_index(char *s) // iterate through the conj_list, comparing the string passed in via the parameter // to each conjunction word, until the conjunction word is found, or the end of the list is reached. { int i; for(i=0;iconj_intern_arg=0; c->conj_extern_arg=0; c->conj_cat = 0; } void display_conj() // Finds a word in the array, if it exists, displays the features. { char conj_entered[32]; // for searching for a conjunction word. int index; printf("Enter the conjunction word you are looking for: "); scanf("%s", conj_entered); index = find_conj_index(conj_entered); if (index == -1) printf("That conjunction word is not in the lexicon.\n"); else print_conj_features(&conj_list[index]); } void edit_conj() // prompt for the conjunction word to be edited. display its features. prompt for the new conjunction word // if it exists, and is not the one we are editing, stop. else call get_qnt to get // the new features, then sort and get the new index for the conjunction word. { char conj_entered[32]; // for searching for a conjunction word int index, index2; printf("Enter the conjunction word to be edited: "); scanf("%s", conj_entered); index = find_conj_index(conj_entered); if (index == -1) printf("That conjunction word is not in the lexicon.\n"); else { print_conj_features(&conj_list[index]); printf("\n\nType in the correct conjunction word: "); scanf(" %s",conj_entered); index2 = find_conj_index(conj_entered); if((index2==-1)||(index2==index)) { strcpy(conj_list[index].conj_word/*adject*/, conj_entered); //so we can find the new index for the conjunction word. get_conj(&conj_list[index]); sort_conj(); index = find_conj_index(conj_entered); save_lexicon(0); printf("The new features of the conjunction word are:\n"); print_conj_features(&conj_list[index]); } else printf("That conjunction word already exists in the Lexicon.\n"); } } void enter_conj(char *s) // copy the conjunction word into the first empty struct in the array, then call get_conj to fill // the features. Sort the array. { int conj_index; int i; if(s[0]!=0) { conj_index=conjunctions; conjunctions++; set_conj_defaults(conj_index,s); i = get_conj(&conj_list[conj_index]); } if (i == -1) //the re-entered conjunction word was in the lexicon, so get rid of this one. conjunctions--; else sort_conj(); } int get_conj(struct conj_struct *d) // Prompt for the features of the conjunction word, and store them in the conj_struct that is passed in. // The rules are Dr. D's. { // blank out the features conj_defaults(d); printf("what is the categorial symbol for the conjunction word lexical modifier? "); scanf("%s",d->conj_cat_form); printf("[%s %s] is a conjunction linking like arguments. \n\n",d->conj_cat_form,d->conj_word); return 0; } void list_conj() { int i; printf("There are %d conjunction words\n",conjunctions); for(i=0;i=0;i--) for(j=0;j0) { memmove(&temp_conj,&conj_list[j],sizeof(struct conj_struct)); memmove(&conj_list[j],&conj_list[j+1],sizeof(struct conj_struct)); memmove(&conj_list[j+1],&temp_conj,sizeof(struct conj_struct)); } } } /*********************************************************************************** * internal function definitions ***********************************************************************************/ void print_conj_features(struct conj_struct* c) { printf("\tconjunction word:\t\t\t%s\n", c->conj_word); printf("\tCategory symbol:\t\t%s\n", c->conj_cat_form); } void set_conj_defaults(int n, char *s) { strcpy(conj_list[n].conj_word, s); } void do_conj(char* conj_entered) { char head[MAXLINE], tail[MAXLINE]; // for breaking up strings like 'four hundred five' int index; strcpy(tail, conj_entered); while(parse(head,tail, MAXLINE) != -1){ index = find_conj_index(head); if (index == -1){ printf("now entering %s:\n",head); enter_conj(head); save_lexicon(0); } else printf("%s is already in the lexicon.\n", head); } // parse returns -1 when no is found, so there is one word left to enter. index = find_conj_index(head); if (index == -1){ printf("now entering %s:\n",head); enter_conj(head); save_lexicon(0); } else printf("%s is already in the lexicon.\n", head); }