Skip to content

Commit

Permalink
Merge pull request #134 from openvanilla/dev/update-api
Browse files Browse the repository at this point in the history
Update McBopomofoLM API to sync with the macOS version
  • Loading branch information
zonble authored Mar 16, 2024
2 parents 8172a09 + ca6619e commit f1aab54
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 120 deletions.
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

0 comments on commit f1aab54

Please sign in to comment.