Skip to content

Commit

Permalink
follow up librime changes to path
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 5, 2024
1 parent 4f2b3b9 commit 72e4d71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/predict_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const string kPredictFormat = "Rime::Predict/1.0";
const string kPredictFormatPrefix = "Rime::Predict/";

bool PredictDb::Load() {
LOG(INFO) << "loading predict db: " << file_name();
LOG(INFO) << "loading predict db: " << file_path();

if (IsOpen())
Close();

if (!OpenReadOnly()) {
LOG(ERROR) << "error opening predict db '" << file_name() << "'.";
LOG(ERROR) << "error opening predict db '" << file_path() << "'.";
return false;
}

Expand Down Expand Up @@ -58,7 +58,7 @@ bool PredictDb::Load() {
}

bool PredictDb::Save() {
LOG(INFO) << "saving predict db: " << file_name();
LOG(INFO) << "saving predict db: " << file_path();
if (!key_trie_->total_size()) {
LOG(ERROR) << "the trie has not been constructed!";
return false;
Expand Down Expand Up @@ -106,12 +106,12 @@ bool PredictDb::Build(const predict::RawData& data) {
string_table.Build();
size_t value_trie_image_size = string_table.BinarySize();
if (!Create(value_trie_image_size)) {
LOG(ERROR) << "Error creating predict db file '" << file_name() << "'.";
LOG(ERROR) << "Error creating predict db file '" << file_path() << "'.";
return false;
}
// create metadata in the beginning of file
if (!Allocate<predict::Metadata>()) {
LOG(ERROR) << "Error creating metadata in file '" << file_name() << "'.";
LOG(ERROR) << "Error creating metadata in file '" << file_path() << "'.";
return false;
}

Expand Down
7 changes: 2 additions & 5 deletions src/predict_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ using RawData = map<string, vector<RawEntry>>;

class PredictDb : public MappedFile {
public:
PredictDb(const string& file_name)
: MappedFile(file_name),
file_name_(file_name),
PredictDb(const path& file_path)
: MappedFile(file_path),
key_trie_(new Darts::DoubleArray),
value_trie_(new StringTable) {}

Expand All @@ -45,13 +44,11 @@ class PredictDb : public MappedFile {
bool Build(const predict::RawData& data);
predict::Candidates* Lookup(const string& query);
string GetEntryText(const ::rime::table::Entry& entry);
const string file_name() { return file_name_; }

private:
int WriteCandidates(const vector<predict::RawEntry>& candidates,
const table::Entry* entry);

const string file_name_;
predict::Metadata* metadata_ = nullptr;
the<Darts::DoubleArray> key_trie_;
the<StringTable> value_trie_;
Expand Down
10 changes: 5 additions & 5 deletions tools/build_predict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ int main(int argc, char* argv[]) {
data[key].push_back(std::move(entry));
}

string file_name = argc > 1 ? string(argv[1]) : string("predict.db");
PredictDb db(file_name);
LOG(INFO) << "creating " << db.file_name();
path file_path = argc > 1 ? path(argv[1]) : path{"predict.db"};
PredictDb db(file_path);
LOG(INFO) << "creating " << db.file_path();
if (!db.Build(data) || !db.Save()) {
LOG(ERROR) << "failed to build " << db.file_name();
LOG(ERROR) << "failed to build " << db.file_path();
return 1;
}
LOG(INFO) << "created: " << db.file_name();
LOG(INFO) << "created: " << db.file_path();
return 0;
}

0 comments on commit 72e4d71

Please sign in to comment.