From 789d2a5687f6c3194795f2e05992df9286239119 Mon Sep 17 00:00:00 2001 From: ovadmin Date: Mon, 2 Oct 2017 01:10:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A8=88=E7=AE=97=E9=81=B8=E5=AD=97=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=99=82=EF=BC=8C=E8=8B=A5=E9=81=87=E5=88=B0=E5=B8=B8?= =?UTF-8?q?=E7=94=A8=E6=A8=99=E9=BB=9E=EF=BC=8C=E5=B0=87=E6=A8=99=E9=BB=9E?= =?UTF-8?q?=E8=A6=96=E7=82=BA=E5=8F=A5=E5=B0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如此一來標點後的單字詞,在計算時,等同於句首第一詞。 --- Source/UserOverrideModel.cpp | 41 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Source/UserOverrideModel.cpp b/Source/UserOverrideModel.cpp index 9f38cf1d..8b2df522 100644 --- a/Source/UserOverrideModel.cpp +++ b/Source/UserOverrideModel.cpp @@ -41,6 +41,7 @@ static double Score(size_t eventCount, double eventTimestamp, double timestamp, double lambda); +static bool IsEndingPunctuation(const string& value); static string WalkedNodesToKey(const std::vector& walkedNodes, size_t cursorIndex); @@ -141,6 +142,10 @@ static double Score(size_t eventCount, return prob * decay; } +static bool IsEndingPunctuation(const string& value) { + return value == "," || value == "。" || value== "!" || value == "?" || + value == "」" || value == "』" || value== "”" || value == "”"; +} static string WalkedNodesToKey(const std::vector& walkedNodes, size_t cursorIndex) { std::stringstream s; @@ -169,12 +174,18 @@ static string WalkedNodesToKey(const std::vector& walkedNodes, s.clear(); s.str(std::string()); if (r != n.rend()) { - s << "(" - << (*r).node->currentKeyValue().key - << "," - << (*r).node->currentKeyValue().value - << ")"; - ++r; + string value = (*r).node->currentKeyValue().value; + if (IsEndingPunctuation(value)) { + s << "()"; + r = n.rend(); + } else { + s << "(" + << (*r).node->currentKeyValue().key + << "," + << value + << ")"; + ++r; + } } else { s << "()"; } @@ -183,12 +194,18 @@ static string WalkedNodesToKey(const std::vector& walkedNodes, s.clear(); s.str(std::string()); if (r != n.rend()) { - s << "(" - << (*r).node->currentKeyValue().key - << "," - << (*r).node->currentKeyValue().value - << ")"; - ++r; + string value = (*r).node->currentKeyValue().value; + if (IsEndingPunctuation(value)) { + s << "()"; + r = n.rend(); + } else { + s << "(" + << (*r).node->currentKeyValue().key + << "," + << value + << ")"; + ++r; + } } else { s << "()"; }