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

Update McBopomofoLM API to sync with the macOS version #134

Merged
merged 3 commits into from
Mar 16, 2024
Merged
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
113 changes: 0 additions & 113 deletions data/derive_associated_phrases.py

This file was deleted.

2 changes: 2 additions & 0 deletions src/Engine/AssociatedPhrasesV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void AssociatedPhrasesV2::close() {
mmapedFile_.close();
}

bool AssociatedPhrasesV2::isLoaded() const { return db_ != nullptr; }

bool AssociatedPhrasesV2::open(std::unique_ptr<ParselessPhraseDB> db) {
if (db_ != nullptr) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/Engine/AssociatedPhrasesV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class AssociatedPhrasesV2 {

bool open(const char* path);
void close();
bool isLoaded() const;

// Allows the use of existing in-memory db.
bool open(std::unique_ptr<ParselessPhraseDB> db);
Expand Down
8 changes: 7 additions & 1 deletion src/Engine/McBopomofoLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void McBopomofoLM::loadLanguageModel(const char* languageModelDataPath) {
}
}

bool McBopomofoLM::isDataModelLoaded() { return languageModel_.isLoaded(); }
bool McBopomofoLM::isDataModelLoaded() const {
return languageModel_.isLoaded();
}

void McBopomofoLM::loadAssociatedPhrasesV2(const char* associatedPhrasesPath) {
if (associatedPhrasesPath) {
Expand All @@ -64,6 +66,10 @@ void McBopomofoLM::loadUserPhrases(const char* userPhrasesDataPath,
}
}

bool McBopomofoLM::isAssociatedPhrasesV2Loaded() const {
return associatedPhrasesV2_.isLoaded();
}

void McBopomofoLM::loadPhraseReplacementMap(const char* phraseReplacementPath) {
if (phraseReplacementPath) {
phraseReplacement_.close();
Expand Down
4 changes: 3 additions & 1 deletion src/Engine/McBopomofoLM.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ class McBopomofoLM : public Formosa::Gramambular2::LanguageModel {
// Loads (or reloads, if already loaded) the primary language model data file.
void loadLanguageModel(const char* languageModelDataPath);

bool isDataModelLoaded();
bool isDataModelLoaded() const;

// Loads (or reloads if already loaded) the associated phrases data file.
void loadAssociatedPhrasesV2(const char* associatedPhrasesPath);

bool isAssociatedPhrasesV2Loaded() const;

// Loads (or reloads if already loaded) both the user phrases and the excluded
// phrases files. If one argument is passed a nullptr, that file will not
// be loaded or reloaded.
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/ParselessLM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

namespace McBopomofo {

bool ParselessLM::isLoaded() { return mmapedFile_.data() != nullptr; }
bool ParselessLM::isLoaded() const { return db_ != nullptr; }

bool ParselessLM::open(const char* path) {
if (!mmapedFile_.open(path)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/ParselessLM.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ParselessLM : public Formosa::Gramambular2::LanguageModel {
ParselessLM& operator=(const ParselessLM&) = delete;
ParselessLM& operator=(ParselessLM&&) = delete;

bool isLoaded();
bool isLoaded() const;
bool open(const char* path);
void close();

Expand Down
6 changes: 3 additions & 3 deletions src/KeyHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ class KeyHandler {
// contain the prefix. This allows the following two scenarios:
//
// (1) the current walk is 得 and we want to pin the phrase 得到; in this
// case,
// the prefixReading is ㄉㄜˊ and prefixValue is 得, and the associated
// phrase's reading and value are ㄉㄜˊ-ㄉㄠˋ and 得到 respectively.
// case, the prefixReading is ㄉㄜˊ and prefixValue is 得, and the
// associated phrase's reading and value are ㄉㄜˊ-ㄉㄠˋ and 得到
// respectively.
// (2) the current walk is 得 but we want to pin the phrase 德性, coming from
// the choosing-candidate state; in this case, the prefix reading and
// value is now ㄉㄜˊ and 德, and the associated phrase is ㄉㄜˊ-ㄒㄧㄥˋ
Expand Down