From 4001efb63a807fbb5e2b502829e0fac6f66e22ec Mon Sep 17 00:00:00 2001 From: fanlumaster <1730976608@qq.com> Date: Wed, 11 Mar 2026 12:20:32 +0800 Subject: [PATCH] increase max hanzi length --- src/include/dictdef.h | 5 ++++- src/include/dicttrie.h | 6 ++++-- src/include/matrixsearch.h | 10 ++++++---- tests/main.cpp | 7 +++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/include/dictdef.h b/src/include/dictdef.h index e765afa..3666372 100644 --- a/src/include/dictdef.h +++ b/src/include/dictdef.h @@ -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); diff --git a/src/include/dicttrie.h b/src/include/dicttrie.h index 37395bd..7b536aa 100644 --- a/src/include/dicttrie.h +++ b/src/include/dicttrie.h @@ -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(kMaxSearchSteps * 8); + static const int kMaxParsingMark = static_cast(kMaxSearchSteps * 64); static const MileStoneHandle kFirstValidMileStoneHandle = 1; friend class DictParser; diff --git a/src/include/matrixsearch.h b/src/include/matrixsearch.h index 697baf9..a6565bd 100644 --- a/src/include/matrixsearch.h +++ b/src/include/matrixsearch.h @@ -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_; diff --git a/tests/main.cpp b/tests/main.cpp index e14c90d..f9ea21a 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -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; -} \ No newline at end of file +}