Skip to content

Commit

Permalink
Fix #328: Propagate partial suggestion info.
Browse files Browse the repository at this point in the history
Rewritten candidates need to take partial suggestion into account.

BUG=#328
TEST=unittest
REF_BUG=19470020
REF_CL=86929261
  • Loading branch information
Toshiyuki Hanaoka authored and yukawa committed Nov 9, 2015
1 parent 1640b6b commit 4668b98
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mozc_version_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=17
BUILD=2219
BUILD=2220
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
Expand Down
3 changes: 3 additions & 0 deletions src/rewriter/number_rewriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,13 @@ RewriteType GetRewriteTypeAndBase(
arabic_candidate->content_value = arabic_number + number_suffix;
arabic_candidate->key = c.key;
arabic_candidate->content_key = c.content_key;
arabic_candidate->consumed_key_size = c.consumed_key_size;
arabic_candidate->cost = c.cost;
arabic_candidate->structure_cost = c.structure_cost;
arabic_candidate->lid = c.lid;
arabic_candidate->rid = c.rid;
arabic_candidate->attributes |=
c.attributes & Segment::Candidate::PARTIALLY_KEY_CONSUMED;
DCHECK(arabic_candidate->IsValid());
return KANJI_FIRST;
}
Expand Down
47 changes: 47 additions & 0 deletions src/rewriter/number_rewriter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1222,4 +1222,51 @@ TEST_F(NumberRewriterTest, RewriteForPartialSuggestion_b16765535) {
}
}

TEST_F(NumberRewriterTest, RewriteForPartialSuggestion_b19470020) {
std::unique_ptr<NumberRewriter> number_rewriter(CreateNumberRewriter());

const char kBubun[] = "\xE9\x83\xA8\xE5\x88\x86"; // "部分"
Segments segments;
{
Segment *seg = segments.push_back_segment();
// "ひとりひとぱっく"
seg->set_key("\xe3\x81\xb2\xe3\x81\xa8\xe3\x82\x8a\xe3\x81\xb2"
"\xe3\x81\xa8\xe3\x81\xb1\xe3\x81\xa3\xe3\x81\x8f");
Segment::Candidate *candidate = seg->add_candidate();
candidate->Init();
candidate->lid = pos_matcher_->GetNumberId();
candidate->rid = pos_matcher_->GetNumberId();
// "ひとり"
candidate->key = "\xe3\x81\xb2\xe3\x81\xa8\xe3\x82\x8a";
// "一人"
candidate->value = "\xe4\xb8\x80\xe4\xba\xba";
// "ひとり"
candidate->content_key = "\xe3\x81\xb2\xe3\x81\xa8\xe3\x82\x8a";
// "一人"
candidate->content_value = "\xe4\xb8\x80\xe4\xba\xba";
candidate->description = kBubun;
candidate->attributes = Segment::Candidate::PARTIALLY_KEY_CONSUMED;
candidate->consumed_key_size = 3;
}
EXPECT_TRUE(number_rewriter->Rewrite(default_request_, &segments));

ASSERT_EQ(1, segments.conversion_segments_size());
const Segment &seg = segments.conversion_segment(0);
ASSERT_LE(2, seg.candidates_size());
bool found_halfwidth = false;
for (size_t i = 0; i < seg.candidates_size(); ++i) {
const Segment::Candidate &candidate = seg.candidate(i);
// "1人"
if (candidate.value != "\x31\xe4\xba\xba") {
continue;
}
found_halfwidth = true;
EXPECT_EQ(3, candidate.consumed_key_size);
EXPECT_TRUE(Util::StartsWith(candidate.description, kBubun));
EXPECT_TRUE(
candidate.attributes & Segment::Candidate::PARTIALLY_KEY_CONSUMED);
}
EXPECT_TRUE(found_halfwidth);
}

} // namespace mozc

0 comments on commit 4668b98

Please sign in to comment.