Skip to content

Commit 8c293fc

Browse files
committed
Merge remote-tracking branch 'fork/master' into disconnect_userdict
2 parents 78f182d + 2f89098 commit 8c293fc

File tree

14 files changed

+82
-29
lines changed

14 files changed

+82
-29
lines changed

.github/workflows/linux-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
build:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-24.04
1313
strategy:
1414
fail-fast: false
1515
matrix:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Build dependencies
4141
- compiler with C++17 support
4242
- cmake>=3.12
4343
- libboost>=1.74
44-
- libglog (optional)
44+
- libglog>=0.7 (optional)
4545
- libleveldb
4646
- libmarisa
4747
- libopencc>=1.0.2
@@ -75,6 +75,7 @@ Official:
7575
Community:
7676
- [emacs-rime](https://github.com/DogLooksGood/emacs-rime): frontend for Emacs
7777
- [coc-rime](https://github.com/tonyfettes/coc-rime): frontend for Vim
78+
- [zsh-rime](https://github.com/Freed-Wu/zsh-rime): frontend for Zsh
7879
- [fcitx-rime](https://github.com/fcitx/fcitx-rime): Fcitx frontend for Linux
7980
- [fcitx5-rime](https://github.com/fcitx/fcitx5-rime): Fcitx5 frontend for Linux
8081
- [Hamster](https://github.com/imfuxiao/Hamster): frontend for iOS

src/rime/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include <list>
1515
#include <map>
1616
#include <memory>
17+
#include <optional>
1718
#include <set>
1819
#include <string>
19-
#include <utility>
2020
#include <unordered_map>
2121
#include <unordered_set>
2222
#include <utility>

src/rime/config/config_data.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ bool ConfigData::LoadFromFile(const path& file_path, ConfigCompiler* compiler) {
6666
modified_ = false;
6767
root.reset();
6868
if (!std::filesystem::exists(file_path)) {
69-
LOG(WARNING) << "nonexistent config file '" << file_path << "'.";
69+
if (!boost::ends_with(file_path.u8string(), ".custom.yaml"))
70+
LOG(WARNING) << "nonexistent config file '" << file_path << "'.";
7071
return false;
7172
}
7273
LOG(INFO) << "loading config file '" << file_path << "'.";
7374
try {
7475
YAML::Node doc = YAML::LoadFile(file_path.string());
7576
root = ConvertFromYaml(doc, compiler);
7677
} catch (YAML::Exception& e) {
77-
LOG(ERROR) << "Error parsing YAML: " << e.what();
78+
LOG(ERROR) << "Error parsing YAML \"" << file_path << "\" : " << e.what();
7879
return false;
7980
}
8081
return true;

src/rime/context.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,27 @@ bool Context::Highlight(size_t index) {
143143
return true;
144144
}
145145

146-
bool Context::DeleteCandidate(
147-
function<an<Candidate>(Segment& seg)> get_candidate) {
146+
bool Context::DeleteCandidate(std::optional<size_t> index) {
148147
if (composition_.empty())
149148
return false;
150149
Segment& seg(composition_.back());
151-
if (auto cand = get_candidate(seg)) {
152-
DLOG(INFO) << "Deleting candidate: '" << cand->text();
153-
delete_notifier_(this);
154-
return true; // CAVEAT: this doesn't mean anything is deleted for sure
150+
auto cand = index ? seg.GetCandidateAt(*index) : seg.GetSelectedCandidate();
151+
if (!cand)
152+
return false;
153+
DLOG(INFO) << "Deleting candidate: " << cand->text();
154+
if (index) {
155+
seg.selected_index = *index;
155156
}
156-
return false;
157+
delete_notifier_(this);
158+
return true; // CAVEAT: this doesn't mean anything is deleted for sure
157159
}
158160

159161
bool Context::DeleteCandidate(size_t index) {
160-
return DeleteCandidate(
161-
[index](Segment& seg) { return seg.GetCandidateAt(index); });
162+
return DeleteCandidate(std::optional{index});
162163
}
163164

164165
bool Context::DeleteCurrentSelection() {
165-
return DeleteCandidate(
166-
[](Segment& seg) { return seg.GetSelectedCandidate(); });
166+
return DeleteCandidate({});
167167
}
168168

169169
bool Context::ConfirmCurrentSelection() {

src/rime/context.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ class RIME_API Context {
7474
bool get_option(const string& name) const;
7575
void set_property(const string& name, const string& value);
7676
string get_property(const string& name) const;
77+
const map<string, bool>& options() const { return options_; }
78+
const map<string, string>& properties() const { return properties_; }
7779
// options and properties starting with '_' are local to schema;
7880
// others are session scoped.
7981
void ClearTransientOptions();
@@ -92,7 +94,7 @@ class RIME_API Context {
9294

9395
private:
9496
string GetSoftCursor() const;
95-
bool DeleteCandidate(function<an<Candidate>(Segment& seg)> get_candidate);
97+
bool DeleteCandidate(std::optional<size_t> index);
9698

9799
string input_;
98100
size_t caret_pos_ = 0;

src/rime/dict/entry_collector.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ void EntryCollector::LoadPresetVocabulary(DictSettings* settings) {
5656

5757
void EntryCollector::Collect(const path& dict_file) {
5858
LOG(INFO) << "collecting entries from " << dict_file;
59+
current_dict_file = dict_file.u8string();
60+
line_number = 0;
5961
// read table
6062
std::ifstream fin(dict_file.c_str());
6163
DictSettings settings;
@@ -69,13 +71,15 @@ void EntryCollector::Collect(const path& dict_file) {
6971
int weight_column = settings.GetColumnIndex("weight");
7072
int stem_column = settings.GetColumnIndex("stem");
7173
if (text_column == -1) {
72-
LOG(ERROR) << "missing text column definition.";
74+
LOG(ERROR) << "missing text column definition in file: " << dict_file
75+
<< ".";
7376
return;
7477
}
7578
bool enable_comment = true;
7679
string line;
7780
while (getline(fin, line)) {
7881
boost::algorithm::trim_right(line);
82+
line_number++;
7983
// skip empty lines and comments
8084
if (line.empty())
8185
continue;
@@ -90,7 +94,9 @@ void EntryCollector::Collect(const path& dict_file) {
9094
auto row = strings::split(line, "\t");
9195
int num_columns = static_cast<int>(row.size());
9296
if (num_columns <= text_column || row[text_column].empty()) {
93-
LOG(WARNING) << "Missing entry text at #" << num_entries << ".";
97+
LOG(WARNING) << "Missing entry text at #" << num_entries
98+
<< ", line: " << line_number
99+
<< " of file: " << current_dict_file << ".";
94100
continue;
95101
}
96102
const auto& word(row[text_column]);
@@ -168,15 +174,19 @@ void EntryCollector::CreateEntry(const string& word,
168174
try {
169175
percentage = std::stod(weight_str.substr(0, weight_str.length() - 1));
170176
} catch (...) {
171-
LOG(WARNING) << "invalid entry definition at #" << num_entries << ".";
177+
LOG(WARNING) << "invalid entry definition at #" << num_entries
178+
<< ", line: " << line_number
179+
<< " of file: " << current_dict_file << ".";
172180
percentage = 100.0;
173181
}
174182
e->weight *= percentage / 100.0;
175183
} else if (!weight_str.empty()) { // absolute weight
176184
try {
177185
e->weight = std::stod(weight_str);
178186
} catch (...) {
179-
LOG(WARNING) << "invalid entry definition at #" << num_entries << ".";
187+
LOG(WARNING) << "invalid entry definition at #" << num_entries
188+
<< ", line: " << line_number
189+
<< " of file: " << current_dict_file << ".";
180190
e->weight = 0.0;
181191
}
182192
}

src/rime/dict/entry_collector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ class EntryCollector : public PhraseCollector {
7171
set<string /* word */> collection;
7272
WordMap words;
7373
WeightMap total_weight;
74+
75+
private:
76+
string current_dict_file;
77+
size_t line_number;
7478
};
7579

7680
} // namespace rime

src/rime/gear/matcher.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ Matcher::Matcher(const Ticket& ticket) : Segmentor(ticket) {
1616
// read schema settings
1717
if (!ticket.schema)
1818
return;
19+
if (name_space_ == "segmentor") {
20+
name_space_ = "recognizer";
21+
}
1922
Config* config = ticket.schema->config();
20-
patterns_.LoadConfig(config);
23+
patterns_.LoadConfig(config, name_space_);
2124
}
2225

2326
bool Matcher::Proceed(Segmentation* segmentation) {

src/rime/gear/recognizer.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static void load_patterns(RecognizerPatterns* patterns, an<ConfigMap> map) {
3232
}
3333
}
3434

35-
void RecognizerPatterns::LoadConfig(Config* config) {
36-
load_patterns(this, config->GetMap("recognizer/patterns"));
35+
void RecognizerPatterns::LoadConfig(Config* config, const string& name_space) {
36+
load_patterns(this, config->GetMap(name_space + "/patterns"));
3737
}
3838

3939
RecognizerMatch RecognizerPatterns::GetMatch(
@@ -72,9 +72,12 @@ RecognizerMatch RecognizerPatterns::GetMatch(
7272
Recognizer::Recognizer(const Ticket& ticket) : Processor(ticket) {
7373
if (!ticket.schema)
7474
return;
75+
if (name_space_ == "processor") {
76+
name_space_ = "recognizer";
77+
}
7578
if (Config* config = ticket.schema->config()) {
76-
patterns_.LoadConfig(config);
77-
config->GetBool("recognizer/use_space", &use_space_);
79+
patterns_.LoadConfig(config, name_space_);
80+
config->GetBool(name_space_ + "/use_space", &use_space_);
7881
}
7982
}
8083

src/rime/gear/recognizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct RecognizerMatch {
2929

3030
class RecognizerPatterns : public map<string, boost::regex> {
3131
public:
32-
void LoadConfig(Config* config);
32+
void LoadConfig(Config* config, const string& name_space);
3333
RecognizerMatch GetMatch(const string& input,
3434
const Segmentation& segmentation) const;
3535
};

src/rime/gear/speller.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,17 @@ static inline bool is_table_entry(const an<Candidate>& cand) {
3838
return type == "table" || type == "user_table";
3939
}
4040

41+
static inline bool is_simple_candidate(const an<Candidate>& cand) {
42+
return bool(As<SimpleCandidate>(cand));
43+
}
44+
4145
static bool is_auto_selectable(const an<Candidate>& cand,
4246
const string& input,
4347
const string& delimiters) {
4448
return
4549
// reaches end of input
46-
cand->end() == input.length() && is_table_entry(cand) &&
50+
cand->end() == input.length() &&
51+
(is_table_entry(cand) || is_simple_candidate(cand)) &&
4752
// no delimiters
4853
input.find_first_of(delimiters, cand->start()) == string::npos;
4954
}

src/rime/setup.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ RIME_API void SetupLogging(const char* app_name,
8484
// Do not allow other users to read/write log files created by current
8585
// process.
8686
FLAGS_logfile_mode = 0600;
87-
google::InitGoogleLogging(app_name);
87+
if (google::IsGoogleLoggingInitialized()) {
88+
LOG(WARNING) << "Glog is already initialized.";
89+
} else {
90+
google::InitGoogleLogging(app_name);
91+
}
8892
#endif // RIME_ENABLE_LOGGING
8993
}
9094

tools/rime_api_console.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,26 @@ bool execute_special_command(const char* line, RimeSessionId session_id) {
165165
if (!strcmp(line, "synchronize")) {
166166
return rime->sync_user_data();
167167
}
168+
const char* kDeleteCandidateOnCurrentPage = "delete on current page ";
169+
command_length = strlen(kDeleteCandidateOnCurrentPage);
170+
if (!strncmp(line, kDeleteCandidateOnCurrentPage, command_length)) {
171+
const char* index_str = line + command_length;
172+
int index = atoi(index_str);
173+
if (!rime->delete_candidate_on_current_page(session_id, index)) {
174+
fprintf(stderr, "failed to delete\n");
175+
}
176+
return true;
177+
}
178+
const char* kDeleteCandidate = "delete ";
179+
command_length = strlen(kDeleteCandidate);
180+
if (!strncmp(line, kDeleteCandidate, command_length)) {
181+
const char* index_str = line + command_length;
182+
int index = atoi(index_str);
183+
if (!rime->delete_candidate(session_id, index)) {
184+
fprintf(stderr, "failed to delete\n");
185+
}
186+
return true;
187+
}
168188
return false;
169189
}
170190

0 commit comments

Comments
 (0)