Lines Matching refs:wmap

340   /* *pwmap->words = (ptr32*) CALLOC_CLR(wmap->max_words, sizeof(ptr32), "graph.wordmap.words"); */
369 wordID wordmap_add_word(wordmap* wmap, const char* word);
379 wordmap* wmap;
394 wordmap_create(&wmap, num_chars, num_words, num_words_to_add);
405 wm_wID = wordmap_add_word(wmap, word);
408 ASSERT(wmap->num_words == num_words);
412 if (!IS_SLOT_OLABEL(wmap->words[my_wID]))
415 wmap->num_slots = my_wID;
416 wordmap_setbase(wmap);
417 *pwmap = wmap;
418 if(wmap->num_slots > MAX_NUM_SLOTS)
424 int wordmap_destroy(wordmap** wmap)
426 if (wmap && *wmap)
428 wordmap_clean ( *wmap );
429 if (((*wmap)->wordIDForWord)) PHashTableDestroy((*wmap)->wordIDForWord);
430 if (((*wmap)->chars)) FREE((*wmap)->chars);
431 if (((*wmap)->words)) FREE((*wmap)->words);
432 if ((*wmap)) FREE((*wmap));
433 *wmap = 0;
438 int FST_UnloadWordMap(wordmap** wmap)
440 return wordmap_destroy(wmap);
444 int FST_DumpWordMap(PFile* fp, wordmap* wmap)
447 for (my_wID = 0; my_wID < wmap->num_words; my_wID++)
449 pfprintf(fp, "%s %hu\n", wmap->words[my_wID], my_wID);
454 wordID wordmap_find_index(wordmap* wmap, const char* word)
463 if (wmap->num_words == 0)
466 if (wmap->wordIDForWord)
468 rc = PHashTableGetValue(wmap->wordIDForWord, word, (void**)&wdID_void);
475 for (i = 0; i < wmap->num_words; i++)
477 if (!strcmp(wmap->words[i], word))
486 wordID wordmap_find_rule_index(wordmap* wmap, const char* rule)
490 for (i = wmap->num_slots; --i > 0;)
492 char* p = strstr(wmap->words[i], SLOTNAME_INDICATOR);
502 wordID wordmap_find_index_in_rule(wordmap* wmap, const char* word, wordID rule)
516 rc = PHashTableGetValue(wmap->wordIDForWord, word_dot_rule, (void**)&wdID_void);
532 int wordmap_whether_in_rule(wordmap* wmap, wordID word, wordID rule)
536 if (word > wmap->num_words) return 0;
537 word_chars = wmap->words[word];
545 void wordmap_setbase(wordmap* wmap)
547 wmap->num_base_words = wmap->num_words;
548 wmap->next_base_chars = wmap->next_chars;
551 void wordmap_ceiling(wordmap* wmap)
554 wmap->max_words = wmap->num_words;
555 wmap->max_chars = (wmap->next_chars - wmap->chars);
614 void wordmap_reset(wordmap* wmap)
620 if (wmap->num_base_words < wmap->num_words)
622 /*wordID i = (wordID)(wmap->num_base_words);*/
623 char* old_wmap_chars = wmap->chars;
624 int offset = wmap->next_base_chars - wmap->chars;
629 memcpy(tmp_chars,wmap->chars, offset * sizeof(char));
630 FREE(wmap->chars);
632 wmap->chars = tmp_chars;
633 wmap->next_base_chars = wmap->chars + (wmap->next_base_chars - old_wmap_chars);
634 wmap->max_chars = (wordID) offset;
635 wmap->next_chars = wmap->next_base_chars;
637 tmp_words = (char**) CALLOC_CLR(wmap->num_base_words, sizeof(char*), "srec.graph.wordmap.words");
641 memcpy( tmp_words, wmap->words, wmap->num_base_words * sizeof(char*));
642 FREE( wmap->words);
644 wmap->words = tmp_words;
645 wmap->max_words = wmap->num_base_words;
646 wmap->num_words = wmap->num_base_words;
648 for(i=0; i<wmap->num_words; i++)
649 wmap->words[i] = wmap->chars + (wmap->words[i] - old_wmap_chars);
652 reset_status = wordmap_clean ( wmap );
656 reset_status = wordmap_populate ( wmap, wmap->num_base_words );
660 wordmap_clean ( wmap );
673 wordID wordmap_add_word(wordmap* wmap, const char* word)
678 if (wmap->next_chars + len >= wmap->chars + wmap->max_chars)
681 int i,tmp_max_chars= wmap->max_chars * FST_GROW_FACTOR;
682 char* old_wmap__chars = wmap->chars;
683 if(tmp_max_chars - wmap->max_chars < FST_GROW_MINCHARS)
691 memcpy(tmp_chars,wmap->chars,wmap->max_chars * sizeof(char));
692 FREE(wmap->chars);
694 wmap->chars = tmp_chars;
695 wmap->next_chars = wmap->chars + (wmap->next_chars - old_wmap__chars);
696 wmap->next_base_chars = wmap->chars + (wmap->next_base_chars - old_wmap__chars);
697 wmap->max_chars = (wordID)tmp_max_chars;
699 wordmap_clean (wmap );
702 for(i=0; i<wmap->num_words; i++)
704 wmap->words[i] = wmap->chars + (wmap->words[i] - old_wmap__chars);
706 if (wmap->wordIDForWord)
708 ESR_ReturnCode rc = PHashTablePutValue ( wmap->wordIDForWord, wmap->words[i],
716 PLogError("error: char overflow in wmap %d max %d\n", (int)(wmap->next_chars - wmap->chars), wmap->max_chars);
721 if (wmap->num_words == wmap->max_words)
726 int itmp_max_words = wmap->max_words * FST_GROW_FACTOR;
728 if(itmp_max_words - wmap->max_words < FST_GROW_MINWORDS)
732 PLogError("error: word ptr overflow in wmap %d max %d\n", (int)wmap->num_words, wmap->max_words);
741 memcpy( tmp_words, wmap->words, wmap->num_words * sizeof(char*));
742 FREE( wmap->words);
743 wmap->words = tmp_words;
744 wmap->max_words = tmp_max_words;
746 PLogError("error: word ptr overflow in wmap %d max %d\n", (int)wmap->num_words, wmap->max_words);
752 strcpy(wmap->next_chars, word);
753 wmap->words[ wmap->num_words++] = wmap->next_chars;
754 wmap->next_chars += len;
755 wdID = (wordID)(wmap->num_words - (wordID)1);
756 if (wmap->wordIDForWord)
758 ESR_ReturnCode rc = PHashTablePutValue ( wmap->wordIDForWord, wmap->words[wdID],
766 PLogError("error: could not add word and wordID in wmap hash (%s -> %d)\n", word, wdID);
770 wordID wordmap_add_word_in_rule(wordmap* wmap, const char* word, wordID rule)
776 if (wmap->next_chars + len >= wmap->chars + wmap->max_chars)
779 int tmp_max_chars = wmap->max_chars * FST_GROW_FACTOR;
781 char* old_next_chars = wmap->next_chars;
782 char* old_chars = wmap->chars;
784 if(tmp_max_chars-wmap->max_chars < FST_GROW_MINCHARS )
786 if( wmap->chars + tmp_max_chars <= wmap->next_chars + len)
794 memcpy(tmp_chars, wmap->chars, wmap->max_chars * sizeof(char));
795 FREE(wmap->chars);
797 wmap->chars = tmp_chars;
798 wmap->next_chars = wmap->chars + (old_next_chars - old_chars) ;
799 wmap->next_base_chars = wmap->chars + (wmap->next_base_chars - old_chars);
800 wmap->max_chars = (wordID)tmp_max_chars;
803 wordmap_clean ( wmap );
806 for(i=0; i<wmap->num_words; i++)
808 wmap->words[i] = wmap->chars +(wmap->words[i] - old_chars) ;
810 if (wmap->wordIDForWord) {
811 ESR_ReturnCode rc = PHashTablePutValue ( wmap->wordIDForWord, wmap->words[i],
818 PLogError("error: char overflow in wmap %d max %d\n", (int)(wmap->next_chars - wmap->chars), wmap->max_chars);
822 if (wmap->num_words == wmap->max_words)
827 int itmp_max_words = wmap->max_words * FST_GROW_FACTOR;
828 if(itmp_max_words - wmap->max_words < FST_GROW_MINWORDS)
832 PLogError("error: word ptr overflow in wmap %d max %d\n", (int)wmap->num_words, wmap->max_words);
842 memcpy( tmp_words, wmap->words, wmap->num_words * sizeof(char*));
843 FREE( wmap->words);
844 wmap->words = tmp_words;
845 wmap->max_words = tmp_max_words;
847 PLogError("error: word ptr overflow in wmap %d max %d\n", (int)wmap->num_words, wmap->max_words);
856 for (p = wmap->next_chars, q = word; (*p = *q) != '\0'; p++, q++) ; /* basic strcpy() */
860 wmap->words[ wmap->num_words++] = wmap->next_chars;
861 wmap->next_chars += len;
862 wdID = (wordID)(wmap->num_words - (wordID)1);
863 if (wmap->wordIDForWord)
865 ESR_ReturnCode rc = PHashTablePutValue ( wmap->wordIDForWord, wmap->words[wdID],
873 PLogError("error: could not add word and wordID in wmap hash (%s -> %d)\n", word, wdID);
1815 atoken->label = (word_label == MAXwordID ? 0 : wmap->words[word_label]);
3212 PLogMessage("G2G done WR wmap %d", pftell(fp));
3481 PLogMessage("G2G done RD wmap %d", pftell(fp));