Skip to content

Commit

Permalink
feat(script_translator): preedit for predicted word
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Mar 3, 2024
1 parent 253e0bd commit f907369
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/rime/gear/script_translator.cc
Expand Up @@ -311,7 +311,7 @@ string ScriptSyllabifier::GetPreeditString(const Phrase& cand) const {
const auto& delimiters = translator_->delimiters();
std::stack<size_t> lengths;
string output;
SyllabifyTask task{cand.code(), syllable_graph_, cand.end() - start_,
SyllabifyTask task{cand.matching_code(), syllable_graph_, cand.end() - start_,
[&](SyllabifyTask* task, size_t depth, size_t current_pos,
size_t next_pos) {
size_t len = output.length();
Expand Down
18 changes: 18 additions & 0 deletions src/rime/gear/translator_commons.h
Expand Up @@ -81,6 +81,24 @@ class Phrase : public Candidate {
Code& code() const { return entry_->code; }
const DictEntry& entry() const { return *entry_; }
const Language* language() const { return language_; }
size_t matching_code_size() const {
return entry_->matching_code_size != 0 ? entry_->matching_code_size
: entry_->code.size();
}
bool is_exact_match() const {
return entry_->matching_code_size == 0 ||
entry_->matching_code_size == entry_->code.size();
}
bool is_predicitve_match() const {
return entry_->matching_code_size != 0 &&
entry_->matching_code_size < entry_->code.size();
}
Code matching_code() const {
return entry_->matching_code_size == 0
? entry_->code
: Code(entry_->code.begin(),
entry_->code.begin() + entry_->matching_code_size);
}
Spans spans() {
return syllabifier_ ? syllabifier_->Syllabify(this) : Spans();
}
Expand Down

0 comments on commit f907369

Please sign in to comment.