/* * BOOLEAN *find_synonym(char *word, FILE *p_dictionary, long *letters, char *buff) * * Finds Identical word in the dictionary file. * Returns a true if found a synonym(that will be saved to buff) or false * if failed. * * params: char *word - the word that needs to be replaced. * FILE *p_dictionary - pointer to the dictionary text file. * long *letters - Array that the function set_letters_pos returned. * char *buff - the string that the synonym will be saved to. * */ BOOLEAN find_synonym(char *word, FILE *p_dictionary, long *letters, char *buff) { long char_pos; char first_letter = char_to_upper(*word); /* set file pointer position to that letter if it exists */ if((char_pos = *(letters + first_letter - CAP_A)) == -1) { if(PRINT_ERROR) { fprintf(stderr, "%c wasn't found\n", first_letter); PRINT_FILE_LINE(); } return false; } fseek(p_dictionary, char_pos, SEEK_SET); /* set file pointer to next line and start comparing */ next_line(p_dictionary); if(cmp_words(word, p_dictionary) == false) { return false; } return get_synonym(p_dictionary, buff); }
/*replace all words with synonyms*/ void replace_words(FILE *fp_sc, FILE *fp_dict, char *search_array , char** after_replace) { char word[WORD_SIZE] = ""; int word_location = -1; /*get file length*/ fseek(fp_sc, 0L, SEEK_END); size_t file_size = ftell(fp_sc); fseek(fp_sc, 0L, SEEK_SET); /*in case the synonyms are bigger than origianl word allocate more memory*/ char *whole_file = malloc(file_size*1.5); strcpy(whole_file, ""); while (!feof(fp_sc) && get_next_word(fp_sc, word) != NULL){ if (word != "") { word_location = find_word_index(word, search_array, word_amount); if (word_location >= 0) {/* found */ strcat(whole_file, get_synonym(fp_dict, word_location)); } else { strcat(whole_file, word); } } strcat(whole_file, get_non_alpha(fp_sc)); strcpy(word, ""); /* clear the word*/ } *after_replace = whole_file; }
NLM_EXTERN Boolean find_synonym(SeqFeatPtr sfp, CharPtr syn) { GeneRefPtr grp; if(sfp->data.choice != 1) return FALSE; grp = sfp->data.value.ptrvalue; return get_synonym(grp->syn, syn); }