Moved tests to utils. Added .gitignore
[vspell.git] / libvspell / posgen.cpp
blobec4206a6f4e3948dd3d070cf37d0a70c97eb92a3
1 #include "posgen.h" // -*- tab-width: 2 mode: c++ -*-
3 using namespace std;
5 void Generator::init(const Sentence &_st)
7 int nr_misspelled,len;
8 nr_misspelled = 3; // REMEMBER THIS NUMBER
9 len = _st.get_syllable_count();
10 pgen.init(len,nr_misspelled);
13 void Generator::done()
15 pgen.done();
18 /**
19 Generate every possible 3-misspelled-positions.
20 Then call WFST::generate_misspelled_words.
23 bool Generator::step(vector<uint> &_pos,uint &_len)
25 return pgen.step(_pos,_len);
28 void PosGen::init(uint len_,uint n_)
30 n = n_;
31 len = len_;
33 pos.resize(n);
34 run = true;
36 // initialize
37 for (i = 0;i < n;i ++)
38 pos[i] = i;
40 i = 0;
43 void PosGen::done()
47 /**
48 Generate every possible 3-misspelled-positions.
49 Then call WFST::generate_misspelled_words.
52 bool PosGen::step(vector<uint> &_pos,uint &_len)
54 while (run) {
56 // move to the next counter
57 if (i+1 < n && pos[i] < len) {
58 i ++;
60 // do something here with misspelled_pos[i]
61 _pos = pos;
62 _len = i;
63 return true;
66 // the last counter is not full
67 if (pos[i] < len) {
68 // do something here with misspelled_pos[nr_misspelled]
69 _pos = pos;
70 _len = n;
71 pos[i] ++;
72 return true;
75 // the last counter is full, step back
76 while (i >= 0 && pos[i] == len) i --;
77 if (i < 0)
78 run = false;
79 else {
80 pos[i] ++;
81 for (ii = i+1;ii < n;ii ++)
82 pos[ii] = pos[ii-1]+1;
85 return false;