From 461b5446896f34864c54ff24a1ce7178596d1627 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Wed, 9 Dec 2020 17:13:01 +0800 Subject: [PATCH] [BUGFIX] Fixes a bug when predict long sentences --- "chapter-3/\345\210\206\350\257\215.ipynb" | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git "a/chapter-3/\345\210\206\350\257\215.ipynb" "b/chapter-3/\345\210\206\350\257\215.ipynb" index 68de2058..438304f7 100644 --- "a/chapter-3/\345\210\206\350\257\215.ipynb" +++ "b/chapter-3/\345\210\206\350\257\215.ipynb" @@ -275,9 +275,14 @@ "hmm.train('./data/trainCorpus.txt_utf8')\n", "\n", "text = '这是一个非常棒的方案!'\n", - "res = hmm.cut(text)\n", + "res = []\n", + "for fragment in text.replace(\"。\", \",\").replace(\"《\", \",\").replace(\"》\", \",\").split(\",\"):\n", + " if fragment == '':\n", + " continue\n", + " for segment in list(hmm.cut(fragment)):\n", + " res.append(segment)\n", "print(text)\n", - "print(str(list(res)))" + "print(str(res))" ] }, {