Updates comments and fixes a typo.
This commit is contained in:
parent
4e56f350e8
commit
c4259c4c4e
|
@ -131,7 +131,7 @@ bool McBopomofoLM::externalConverterEnabled()
|
||||||
return m_externalConverterEnabled;
|
return m_externalConverterEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void McBopomofoLM::setExternalConvrter(std::function<string(string)> externalConverter)
|
void McBopomofoLM::setExternalConverter(std::function<string(string)> externalConverter)
|
||||||
{
|
{
|
||||||
m_externalConverter = externalConverter;
|
m_externalConverter = externalConverter;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,27 +34,74 @@ namespace McBopomofo {
|
||||||
|
|
||||||
using namespace Formosa::Gramambular;
|
using namespace Formosa::Gramambular;
|
||||||
|
|
||||||
|
/// McBopomofoLM is a facade for managing a set of models including
|
||||||
|
/// the input method language model, user phrases and excluded phrases.
|
||||||
|
///
|
||||||
|
/// It is the primary model class that the input controller and grammer builder
|
||||||
|
/// of McBopomofo talk to. When the grammer builder starts to build a sentense
|
||||||
|
/// from a series of BPMF readings, it passes the readings to the model to see
|
||||||
|
/// if there are valid unigrams, and use returned unigrams to produce the final
|
||||||
|
/// results.
|
||||||
|
///
|
||||||
|
/// McBopomofoLM combine and transform the unigrams from the primary language
|
||||||
|
/// model and user phrases. The process is
|
||||||
|
///
|
||||||
|
/// 1) Get the original unigrams.
|
||||||
|
/// 2) Drop the unigrams whose value is contained in the exclusion map.
|
||||||
|
/// 3) Replace the values of the unigrams using the phrase replacement map.
|
||||||
|
/// 4) Replace the values of the unigrams using an external converter lambda.
|
||||||
|
/// 5) Drop the duplicated phrases.
|
||||||
|
///
|
||||||
|
/// The controller can ask the model to load the primary input method language
|
||||||
|
/// model while launching and to load the user phrases anytime if the custom
|
||||||
|
/// files are modified. It does not keep the reference of the data pathes but
|
||||||
|
/// you have to pass the paths when you ask it to do loading.
|
||||||
class McBopomofoLM : public LanguageModel {
|
class McBopomofoLM : public LanguageModel {
|
||||||
public:
|
public:
|
||||||
McBopomofoLM();
|
McBopomofoLM();
|
||||||
~McBopomofoLM();
|
~McBopomofoLM();
|
||||||
|
|
||||||
|
/// Asks to load the primary language model a the given path.
|
||||||
|
/// @param languageModelPath Thw path of the language model.
|
||||||
void loadLanguageModel(const char* languageModelPath);
|
void loadLanguageModel(const char* languageModelPath);
|
||||||
|
/// Asks to load the user phrases and excluded phrases at the given path.
|
||||||
|
/// @param userPhrasesPath The path of user phrases.
|
||||||
|
/// @param excludedPhrasesPath The path of excluded phrases.
|
||||||
void loadUserPhrases(const char* userPhrasesPath, const char* excludedPhrasesPath);
|
void loadUserPhrases(const char* userPhrasesPath, const char* excludedPhrasesPath);
|
||||||
|
/// Asks to load th phrase replacement table at the given path.
|
||||||
|
/// @param phraseReplacementPath The path of the phrase replacement table.
|
||||||
void loadPhraseReplacementMap(const char* phraseReplacementPath);
|
void loadPhraseReplacementMap(const char* phraseReplacementPath);
|
||||||
|
|
||||||
|
/// Not implemented since we do not have data to provide bigram function.
|
||||||
const vector<Bigram> bigramsForKeys(const string& preceedingKey, const string& key);
|
const vector<Bigram> bigramsForKeys(const string& preceedingKey, const string& key);
|
||||||
|
/// Returns a list of available unigram for the given key.
|
||||||
|
/// @param key A string represents the BPMF reading or a symbol key. For
|
||||||
|
/// example, it you pass "ㄇㄚ", it returns "嗎", "媽", and so on.
|
||||||
const vector<Unigram> unigramsForKey(const string& key);
|
const vector<Unigram> unigramsForKey(const string& key);
|
||||||
|
/// If the model has unigrams for the given key.
|
||||||
|
/// @param key The key.
|
||||||
bool hasUnigramsForKey(const string& key);
|
bool hasUnigramsForKey(const string& key);
|
||||||
|
|
||||||
|
/// Enables or disables phrase replacement.
|
||||||
void setPhraseReplacementEnabled(bool enabled);
|
void setPhraseReplacementEnabled(bool enabled);
|
||||||
|
/// If phrease replacement is enabled or not.
|
||||||
bool phraseReplacementEnabled();
|
bool phraseReplacementEnabled();
|
||||||
|
|
||||||
|
/// Enables or disables the external converter.
|
||||||
void setExternalConverterEnabled(bool enabled);
|
void setExternalConverterEnabled(bool enabled);
|
||||||
|
/// If the external converted is enabled or not.
|
||||||
bool externalConverterEnabled();
|
bool externalConverterEnabled();
|
||||||
void setExternalConvrter(std::function<string(string)> externalConverter);
|
/// Sets a lambda to let the values of unigrams could be converted by it.
|
||||||
|
void setExternalConverter(std::function<string(string)> externalConverter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Filters and converts the input unigrams and return a new list of unigrams.
|
||||||
|
///
|
||||||
|
/// @param unigrams The unigrams to be processed.
|
||||||
|
/// @param excludedValues The values to excluded unigrams.
|
||||||
|
/// @param insertedValues The values for unigrams already in the results.
|
||||||
|
/// It helps to prevent duplicated unigrams. Please note that the method
|
||||||
|
/// has a side effect that it inserts values to `insertedValues`.
|
||||||
const vector<Unigram> filterAndTransformUnigrams(const vector<Unigram> unigrams,
|
const vector<Unigram> filterAndTransformUnigrams(const vector<Unigram> unigrams,
|
||||||
const std::unordered_set<string>& excludedValues,
|
const std::unordered_set<string>& excludedValues,
|
||||||
std::unordered_set<string>& insertedValues);
|
std::unordered_set<string>& insertedValues);
|
||||||
|
|
|
@ -68,8 +68,8 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, McBopomo
|
||||||
return string(text.UTF8String);
|
return string(text.UTF8String);
|
||||||
};
|
};
|
||||||
|
|
||||||
gLanguageModelMcBopomofo.setExternalConvrter(converter);
|
gLanguageModelMcBopomofo.setExternalConverter(converter);
|
||||||
gLanguageModelPlainBopomofo.setExternalConvrter(converter);
|
gLanguageModelPlainBopomofo.setExternalConverter(converter);
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (BOOL)checkIfUserDataFolderExists
|
+ (BOOL)checkIfUserDataFolderExists
|
||||||
|
|
Loading…
Reference in New Issue