increase max hanzi length

This commit is contained in:
fanlumaster
2026-03-11 12:20:32 +08:00
parent 5c27ca03e9
commit 4001efb63a
4 changed files with 19 additions and 9 deletions
+4 -1
View File
@@ -56,7 +56,10 @@ const size_t kHalfSpellingIdNum = 29;
// stored.
// -1 is because that 0 is never used.
const size_t kMaxSpellingNum = 512 - kHalfSpellingIdNum - 1;
const size_t kMaxSearchSteps = 40;
// Increased to allow longer Pinyin input and longer sentence output.
// Note: changing this requires adjusting related pools in matrixsearch.h
// and dicttrie.h to avoid search failures under long input.
const size_t kMaxSearchSteps = 128;
// One character predicts its following characters.
const size_t kMaxPredictSize = (kMaxLemmaSize - 1);
+4 -2
View File
@@ -136,8 +136,10 @@ class DictTrie : AtomDictBase {
bool save_dict(FILE *fp);
#endif // ___BUILD_MODEL___
static const int kMaxMileStone = 100;
static const int kMaxParsingMark = 600;
// Increase limits to support longer Pinyin input.
// If kMaxSearchSteps is increased, these must scale accordingly.
static const int kMaxMileStone = static_cast<int>(kMaxSearchSteps * 8);
static const int kMaxParsingMark = static_cast<int>(kMaxSearchSteps * 64);
static const MileStoneHandle kFirstValidMileStoneHandle = 1;
friend class DictParser;
+6 -4
View File
@@ -144,14 +144,16 @@ class MatrixSearch {
static const size_t kMaxNodeARow = 5;
// The maximum length of the sentence candidates counted in chinese
// characters
static const size_t kMaxSentenceLength = 16;
// characters.
static const size_t kMaxSentenceLength = 64;
// The size of the matrix node pool.
static const size_t kMtrxNdPoolSize = 200;
// Scale with kMaxSearchSteps to avoid pool exhaustion for long input.
static const size_t kMtrxNdPoolSize = kMaxRowNum * kMaxNodeARow;
// The size of the DMI node pool.
static const size_t kDmiPoolSize = 800;
// Scale with kMaxSearchSteps to avoid pool exhaustion for long input.
static const size_t kDmiPoolSize = kMaxRowNum * 20;
// Used to indicate whether this object has been initialized.
bool inited_;
+5 -2
View File
@@ -97,7 +97,8 @@ int main() {
#ifdef _WIN32
SetConsoleOutputCP(CP_UTF8);
#endif
ime_pinyin::im_set_max_lens(64, 32);
// Keep output up to 64 Hanzi; input length up to 128 Pinyin chars.
ime_pinyin::im_set_max_lens(128, 64);
if (!ime_pinyin::im_open_decoder("./data/dict_pinyin.dat", "./data/user_dict.dat")) {
std::cout << "fany bug.\n";
return 0;
@@ -119,5 +120,7 @@ int main() {
test_pinyin_search_when_retriving_first_element("ni'shuo'ne'ma'de");
test_pinyin_search_when_retriving_first_element("wei'ni'qian'gua'bu'bian");
test_pinyin_search_when_retriving_first_element("wo'lai'kan'kan'zhe'ge'zui'duo'neng'shu'ru'duo'shao'ge'zi'kan'shang'qu'shi'bi'jiao'he'li'de");
test_pinyin_search_when_retriving_first_element("zheshikeyishuodemawojuedehaishiyaoweiwanyidianbijiaohaobanishuoneqishizhongguorenshizhegeyangzide");
test_pinyin_search_when_retriving_first_element("chulichangjuzishishenme");
return 0;
}
}