Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(translator_commons): support excluding tags from translation #959

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rime/gear/script_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ an<Translation> ScriptTranslator::Query(const string& input,
const Segment& segment) {
if (!dict_ || !dict_->loaded())
return nullptr;
if (!segment.HasAnyTagIn(tags_))
if (!segment.HasAnyTagIn(tags_) || segment.HasAnyTagIn(exclude_tags_))
return nullptr;
DLOG(INFO) << "input = '" << input << "', [" << segment.start << ", "
<< segment.end << ")";
Expand Down
2 changes: 1 addition & 1 deletion src/rime/gear/table_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ static bool starts_with_completion(an<Translation> translation) {

an<Translation> TableTranslator::Query(const string& input,
const Segment& segment) {
if (!segment.HasAnyTagIn(tags_))
if (!segment.HasAnyTagIn(tags_) || segment.HasAnyTagIn(exclude_tags_))
return nullptr;
DLOG(INFO) << "input = '" << input << "', [" << segment.start << ", "
<< segment.end << ")";
Expand Down
4 changes: 4 additions & 0 deletions src/rime/gear/translator_commons.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ TranslatorOptions::TranslatorOptions(const Ticket& ticket) {
tags_.push_back(value->str());
if (tags_.empty())
tags_.push_back("abc");
if (auto list = config->GetList(ticket.name_space + "/exclude_tags"))
for (size_t i = 0; i < list->size(); ++i)
if (auto value = As<ConfigValue>(list->GetAt(i)))
exclude_tags_.push_back(value->str());
}
if (delimiters_.empty()) {
delimiters_ = " ";
Expand Down
3 changes: 3 additions & 0 deletions src/rime/gear/translator_commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class TranslatorOptions {
}
const string& tag() const { return tags_[0]; }
void set_tag(const string& tag) { tags_[0] = tag; }
vector<string> exclude_tags() const { return exclude_tags_; }
void set_exclude_tags(const vector<string>& tags) { exclude_tags_ = tags; }
bool contextual_suggestions() const { return contextual_suggestions_; }
void set_contextual_suggestions(bool enabled) {
contextual_suggestions_ = enabled;
Expand All @@ -171,6 +173,7 @@ class TranslatorOptions {
protected:
string delimiters_;
vector<string> tags_{"abc"}; // invariant: non-empty
vector<string> exclude_tags_{};
bool contextual_suggestions_ = false;
bool enable_completion_ = true;
bool strict_spelling_ = false;
Expand Down
Loading