計算選字事件時,若遇到常用標點,將標點視為句尾

如此一來標點後的單字詞,在計算時,等同於句首第一詞。
This commit is contained in:
ovadmin 2017-10-02 01:10:59 +08:00 committed by Lukhnos Liu
parent aeb774a8ed
commit 789d2a5687
1 changed files with 29 additions and 12 deletions

View File

@ -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<NodeAnchor>& 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<NodeAnchor>& walkedNodes,
size_t cursorIndex) {
std::stringstream s;
@ -169,12 +174,18 @@ static string WalkedNodesToKey(const std::vector<NodeAnchor>& 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<NodeAnchor>& 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 << "()";
}