Skip to content

Commit

Permalink
simplifier: move RandomConvertText to a separate branch
Browse files Browse the repository at this point in the history
  • Loading branch information
osfans authored and Prcuvu committed Oct 29, 2016
1 parent 117ab3b commit 57bf14a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
5 changes: 2 additions & 3 deletions include/rime/gear/simplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@ class Simplifier : public Filter, TagMatching {
return TagsMatch(segment);
}

void PushBack(const an<Candidate>& original,
CandidateQueue* result, const string& simplified);

bool Convert(const an<Candidate>& original,
CandidateQueue* result);

protected:
enum TipsLevel { kTipsNone, kTipsChar, kTipsAll };

void Initialize();
void PushBack(const an<Candidate>& original,
CandidateQueue* result, const string& simplified);

bool initialized_ = false;
the<Opencc> opencc_;
Expand Down
38 changes: 21 additions & 17 deletions src/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Opencc {
}
}

bool ConvertRandText(const string& text,
bool RandomConvertText(const string& text,
string* simplified) {
const char *phrase = text.c_str();
std::ostringstream buffer;
Expand Down Expand Up @@ -225,26 +225,30 @@ bool Simplifier::Convert(const an<Candidate>& original,
return false;
}
bool success = false;
vector<string> forms;
if (!random) success = opencc_->ConvertWord(original->text(), &forms);
if (success) {
for (size_t i = 0; i < forms.size(); ++i) {
if (forms[i] == original->text()) {
result->push_back(original);
} else {
PushBack(original, result, forms[i]);
}
}
} else {
if (random_) {
string simplified;
if (random_) {
success = opencc_->ConvertRandText(original->text(), &simplified);
} else {
success = opencc_->ConvertText(original->text(), &simplified);
}
success = opencc_->RandomConvertText(original->text(), &simplified);
if (success) {
PushBack(original, result, simplified);
}
} else { //!random_
vector<string> forms;
success = opencc_->ConvertWord(original->text(), &forms);
if (success) {
for (size_t i = 0; i < forms.size(); ++i) {
if (forms[i] == original->text()) {
result->push_back(original);
} else {
PushBack(original, result, forms[i]);
}
}
} else {
string simplified;
success = opencc_->ConvertText(original->text(), &simplified);
if (success) {
PushBack(original, result, simplified);
}
}
}
return success;
}
Expand Down

0 comments on commit 57bf14a

Please sign in to comment.