Skip to content

Commit

Permalink
Renamed the method names to keep consistency with sub components.
Browse files Browse the repository at this point in the history
- CheckCompositionSpelling -> CorrectComposition
- MaybeApplyHomonymCorrection -> PostCorrect

PiperOrigin-RevId: 633096127
  • Loading branch information
taku910 authored and hiroyuki-komatsu committed May 13, 2024
1 parent 98fd861 commit a93e389
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/engine/supplemental_model_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ class SupplementalModelInterface {
// Returns std::nullopt when the composition spellchecker is not
// enabled/available.
virtual std::optional<std::vector<composer::TypeCorrectedQuery>>
CheckCompositionSpelling(absl::string_view query, absl::string_view context,
bool disable_toggle_correction,
const commands::Request &request) const {
CorrectComposition(absl::string_view query, absl::string_view context,
bool disable_toggle_correction,
const commands::Request &request) const {
return std::nullopt;
}

// Performs homonym spelling correction.
virtual void MaybeApplyHomonymCorrection(Segments *segments) const {}
// Performs general post correction on `segments`.
virtual void PostCorrect(Segments *segments) const {}
};

} // namespace mozc::engine
Expand Down
6 changes: 3 additions & 3 deletions src/prediction/dictionary_prediction_aggregator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1704,9 +1704,9 @@ void DictionaryPredictionAggregator::AggregateTypingCorrectedPrediction(

const std::string asis = request.composer().GetStringForTypeCorrection();
const std::optional<std::vector<TypeCorrectedQuery>> corrected =
supplemental_model->CheckCompositionSpelling(
asis, segments.history_key(), disable_toggle_correction(request),
request.request());
supplemental_model->CorrectComposition(asis, segments.history_key(),
disable_toggle_correction(request),
request.request());
if (!corrected) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/prediction/dictionary_prediction_aggregator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2051,10 +2051,11 @@ TEST_F(DictionaryPredictionAggregatorTest,
class MockSupplementalModel : public engine::SupplementalModelInterface {
public:
MOCK_METHOD(std::optional<std::vector<TypeCorrectedQuery>>,
CheckCompositionSpelling,
CorrectComposition,
(absl::string_view, absl::string_view, bool,
const commands::Request &),
(const, override));
MOCK_METHOD(void, PostCorrect, (Segments *), (const, override));
};

std::unique_ptr<MockDataAndAggregator> data_and_aggregator =
Expand Down Expand Up @@ -2086,8 +2087,7 @@ TEST_F(DictionaryPredictionAggregatorTest,
TypeCorrectedQuery::KANA_MODIFIER_INSENTIVE_ONLY);

auto mock = std::make_unique<MockSupplementalModel>();
EXPECT_CALL(*mock,
CheckCompositionSpelling("よろさく", "ほんじつは", false, _))
EXPECT_CALL(*mock, CorrectComposition("よろさく", "ほんじつは", false, _))
.WillOnce(Return(expected));

data_and_aggregator->set_supplemental_model(mock.get());
Expand Down
8 changes: 4 additions & 4 deletions src/prediction/dictionary_predictor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ bool DictionaryPredictor::AddPredictionToCandidates(
merged_types, segment->push_back_candidate());
}

// TODO(b/320221782): Add unit tests for MaybeApplyHomonymCorrection.
MaybeApplyHomonymCorrection(modules_, segments);
// TODO(b/320221782): Add unit tests for MaybeApplyPostCorrection.
MaybeApplyPostCorrection(modules_, segments);

if (!fix_literal_on_top) {
MaybeSuppressAggressiveTypingCorrection(
Expand Down Expand Up @@ -667,14 +667,14 @@ void DictionaryPredictor::MaybeSuppressAggressiveTypingCorrection2(
}

// static
void DictionaryPredictor::MaybeApplyHomonymCorrection(
void DictionaryPredictor::MaybeApplyPostCorrection(
const engine::Modules &modules, Segments *segments) {
const engine::SupplementalModelInterface *supplemental_model =
modules.GetSupplementalModel();
if (supplemental_model == nullptr) {
return;
}
supplemental_model->MaybeApplyHomonymCorrection(segments);
supplemental_model->PostCorrect(segments);
}

int DictionaryPredictor::CalculateSingleKanjiCostOffset(
Expand Down
4 changes: 2 additions & 2 deletions src/prediction/dictionary_predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ class DictionaryPredictor : public PredictorInterface {
const TypingCorrectionMixingParams &typing_correction_mixing_params,
std::vector<absl::Nonnull<const Result *>> *results);

static void MaybeApplyHomonymCorrection(const engine::Modules &modules,
Segments *segments);
static void MaybeApplyPostCorrection(const engine::Modules &modules,
Segments *segments);

void MaybeRescoreResults(const ConversionRequest &request,
const Segments &segments,
Expand Down

0 comments on commit a93e389

Please sign in to comment.