Example #1
0
void WFST::generate_misspelled_words(const vector<uint> &pos,int len,Segmentation &final_seg)
{
	const Lattice &words = *p_words;
	Lattice w;

	w.based_on(words);
	
	// 2. Compute the score, jump to 1. if score is too low (pruning 1)

	// create new (more compact) Lattice structure
	int i,n = words.get_word_count();
	for (i = 0;i < len;i ++) {
		const WordEntryRefs &fmap = words.get_fuzzy_map(pos[i]);
		int ii,nn = fmap.size();
		for (ii = 0;ii < nn;++ii)
			w.add(*fmap[ii]);
	}

	//cerr << w << endl;

	// 4. Create sections
	Sections sects;
	sects.construct(words);

	// 5. Call create_base_segmentation
	//Segmentation base_seg(words.we);
	//create_base_segmentation(words,sects,base_seg);


	// 6. Get the best segmentation of each section,
	// then merge to one big segment.
	n = sects.size();

	uint ii,nn;

	i = ii = 0;
	nn = words.get_word_count();
	
	final_seg.clear();
	while (ii < nn)
		if (i < n && sects[i].start == ii) {
			Segmentation seg;
			sects[i].segment_best(words,seg);
			copy(seg.begin(),
					 seg.end(),
					 back_insert_iterator< Segmentation >(final_seg));
			ii += sects[i].len;
			i ++;
		} else {
			// only word(i,*,0) exists
			final_seg.push_back(words.get_we(ii)[0]->id);
			ii += words.get_we(ii)[0]->len;
		}
}