From 11be31f7311a9ad15358aa24eb91466bfa5e0931 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Mon, 28 Feb 2022 16:39:06 +0800 Subject: [PATCH] Repo // Remove a useless namespace. - The name "Taiyan" will be used as a new namespace instead. - Mandarin and Gramambular modules (from libFormosana) will use their individual namespaces instead without a shared root namespace. --- Source/3rdParty/OVMandarin/Mandarin.cpp | 3 +- Source/3rdParty/OVMandarin/Mandarin.h | 3 +- .../Modules/ControllerModules/KeyHandler.mm | 52 +++++++++---------- .../Modules/LangModelRelated/LMInstantiator.h | 10 ++-- .../LangModelRelated/LMInstantiator.mm | 40 +++++++------- .../SubLanguageModels/CoreLM.h | 8 +-- .../SubLanguageModels/CoreLM.mm | 10 ++-- .../SubLanguageModels/ParselessLM.cpp | 12 ++--- .../SubLanguageModels/ParselessLM.h | 6 +-- .../SubLanguageModels/UserOverrideModel.cpp | 14 ++--- .../SubLanguageModels/UserOverrideModel.h | 6 +-- .../SubLanguageModels/UserPhrasesLM.h | 6 +-- .../SubLanguageModels/UserPhrasesLM.mm | 10 ++-- .../LanguageParsers/Gramambular/Bigram.h | 3 +- .../Gramambular/BlockReadingBuilder.h | 3 +- .../LanguageParsers/Gramambular/Grid.h | 3 +- .../LanguageParsers/Gramambular/Grid.mm | 3 +- .../Gramambular/KeyValuePair.h | 3 +- .../Gramambular/LanguageModel.h | 3 +- .../LanguageParsers/Gramambular/Node.h | 3 +- .../LanguageParsers/Gramambular/NodeAnchor.h | 3 +- .../LanguageParsers/Gramambular/Span.h | 3 +- .../LanguageParsers/Gramambular/Unigram.h | 3 +- .../LanguageParsers/Gramambular/Walker.h | 3 +- 24 files changed, 100 insertions(+), 113 deletions(-) diff --git a/Source/3rdParty/OVMandarin/Mandarin.cpp b/Source/3rdParty/OVMandarin/Mandarin.cpp index d1f6d08e..53cbd299 100644 --- a/Source/3rdParty/OVMandarin/Mandarin.cpp +++ b/Source/3rdParty/OVMandarin/Mandarin.cpp @@ -22,7 +22,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include -namespace Taiyan { namespace Mandarin { class PinyinParseHelper { @@ -1034,5 +1033,5 @@ const BopomofoKeyboardLayout* BopomofoKeyboardLayout::HanyuPinyinLayout() { } } // namespace Mandarin -} // namespace Taiyan + diff --git a/Source/3rdParty/OVMandarin/Mandarin.h b/Source/3rdParty/OVMandarin/Mandarin.h index bb0ec5de..e8a24708 100644 --- a/Source/3rdParty/OVMandarin/Mandarin.h +++ b/Source/3rdParty/OVMandarin/Mandarin.h @@ -25,7 +25,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include -namespace Taiyan { namespace Mandarin { class BopomofoSyllable { @@ -471,6 +470,6 @@ protected: std::string pinyin_sequence_; }; } // namespace Mandarin -} // namespace Taiyan + #endif // MANDARIN_H_ diff --git a/Source/Modules/ControllerModules/KeyHandler.mm b/Source/Modules/ControllerModules/KeyHandler.mm index 78e760e8..a5d6effe 100644 --- a/Source/Modules/ControllerModules/KeyHandler.mm +++ b/Source/Modules/ControllerModules/KeyHandler.mm @@ -33,7 +33,7 @@ InputMode imeModeNULL = @"org.atelierInmu.inputmethod.vChewing.IMENULL"; static const double kEpsilon = 0.000001; -static double FindHighestScore(const std::vector &nodes, double epsilon) { +static double FindHighestScore(const std::vector &nodes, double epsilon) { double highestScore = 0.0; for (auto ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { double score = ni->node->highestUnigramScore(); @@ -46,7 +46,7 @@ static double FindHighestScore(const std::vectorkey().length() > b.node->key().length(); } @@ -62,7 +62,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; @implementation KeyHandler { // the reading buffer that takes user input - Taiyan::Mandarin::BopomofoReadingBuffer *_bpmfReadingBuffer; + Mandarin::BopomofoReadingBuffer *_bpmfReadingBuffer; // language model vChewing::LMInstantiator *_languageModel; @@ -71,10 +71,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; vChewing::UserOverrideModel *_userOverrideModel; // the grid (lattice) builder for the unigrams (and bigrams) - Taiyan::Gramambular::BlockReadingBuilder *_builder; + Gramambular::BlockReadingBuilder *_builder; // latest walked path (trellis) using the Viterbi algorithm - std::vector _walkedNodes; + std::vector _walkedNodes; NSString *_inputMode; } @@ -122,7 +122,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (_builder) { delete _builder; - _builder = new Taiyan::Gramambular::BlockReadingBuilder(_languageModel); + _builder = new Gramambular::BlockReadingBuilder(_languageModel); _builder->setJoinSeparator("-"); } @@ -148,7 +148,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; { self = [super init]; if (self) { - _bpmfReadingBuffer = new Taiyan::Mandarin::BopomofoReadingBuffer(Taiyan::Mandarin::BopomofoKeyboardLayout::StandardLayout()); + _bpmfReadingBuffer = new Mandarin::BopomofoReadingBuffer(Mandarin::BopomofoKeyboardLayout::StandardLayout()); // create the lattice builder _languageModel = [mgrLangModel lmCHT]; @@ -156,7 +156,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; _languageModel->setCNSEnabled(Preferences.cns11643Enabled); _userOverrideModel = [mgrLangModel userOverrideModelCHT]; - _builder = new Taiyan::Gramambular::BlockReadingBuilder(_languageModel); + _builder = new Gramambular::BlockReadingBuilder(_languageModel); // each Mandarin syllable is separated by a hyphen _builder->setJoinSeparator("-"); @@ -170,31 +170,31 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; NSInteger layout = Preferences.keyboardLayout; switch (layout) { case KeyboardLayoutStandard: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::StandardLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); break; case KeyboardLayoutEten: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::ETenLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETenLayout()); break; case KeyboardLayoutHsu: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::HsuLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HsuLayout()); break; case KeyboardLayoutEten26: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::ETen26Layout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::ETen26Layout()); break; case KeyboardLayoutIBM: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::IBMLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::IBMLayout()); break; case KeyboardLayoutMiTAC: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::MiTACLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::MiTACLayout()); break; case KeyboardLayoutFakeSeigyou: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::FakeSeigyouLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::FakeSeigyouLayout()); break; case KeyboardLayoutHanyuPinyin: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::HanyuPinyinLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::HanyuPinyinLayout()); break; default: - _bpmfReadingBuffer->setKeyboardLayout(Taiyan::Mandarin::BopomofoKeyboardLayout::StandardLayout()); + _bpmfReadingBuffer->setKeyboardLayout(Mandarin::BopomofoKeyboardLayout::StandardLayout()); Preferences.keyboardLayout = KeyboardLayoutStandard; } } @@ -203,7 +203,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; { size_t cursorIndex = [self _actualCandidateCursorIndex]; std::string stringValue(value.UTF8String); - Taiyan::Gramambular::NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue); + Gramambular::NodeAnchor selectedNode = _builder->grid().fixNodeSelectedCandidate(cursorIndex, stringValue); if (!Preferences.useSCPCTypingMode) { // 不要針對逐字選字模式啟用臨時半衰記憶模型。 // If the length of the readings and the characters do not match, // it often means it is a special symbol and it should not be stored @@ -383,7 +383,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (!overrideValue.empty()) { size_t cursorIndex = [self _actualCandidateCursorIndex]; - std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); + std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); double highestScore = FindHighestScore(nodes, kEpsilon); _builder->grid().overrideNodeScoreForSelectedCandidate(cursorIndex, overrideValue, static_cast(highestScore)); } @@ -1275,7 +1275,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // we must do some Unicode codepoint counting to find the actual cursor location for the client // i.e. we need to take UTF-16 into consideration, for which a surrogate pair takes 2 UniChars // locations - for (std::vector::iterator wi = _walkedNodes.begin(), we = _walkedNodes.end(); wi != we; ++wi) { + for (std::vector::iterator wi = _walkedNodes.begin(), we = _walkedNodes.end(); wi != we; ++wi) { if ((*wi).node) { std::string nodeStr = (*wi).node->currentKeyValue().value; NSString *valueString = [NSString stringWithUTF8String:nodeStr.c_str()]; @@ -1343,7 +1343,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; // retrieve the most likely trellis, i.e. a Maximum Likelihood Estimation // of the best possible Mandarain characters given the input syllables, // using the Viterbi algorithm implemented in the Gramambular library - Taiyan::Gramambular::Walker walker(&_builder->grid()); + Gramambular::Walker walker(&_builder->grid()); // the reverse walk traces the trellis from the end _walkedNodes = walker.reverseWalk(_builder->grid().width()); @@ -1376,7 +1376,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; if (_builder->grid().width() > (size_t) composingBufferSize) { if (_walkedNodes.size() > 0) { - Taiyan::Gramambular::NodeAnchor &anchor = _walkedNodes[0]; + Gramambular::NodeAnchor &anchor = _walkedNodes[0]; poppedText = [NSString stringWithUTF8String:anchor.node->currentKeyValue().value.c_str()]; _builder->removeHeadReadings(anchor.spanningLength); } @@ -1391,15 +1391,15 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot"; NSMutableArray *candidatesArray = [[NSMutableArray alloc] init]; size_t cursorIndex = [self _actualCandidateCursorIndex]; - std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); + std::vector nodes = _builder->grid().nodesCrossingOrEndingAt(cursorIndex); // sort the nodes, so that longer nodes (representing longer phrases) are placed at the top of the candidate list stable_sort(nodes.begin(), nodes.end(), NodeAnchorDescendingSorter()); // then use the C++ trick to retrieve the candidates for each node at/crossing the cursor - for (std::vector::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { - const std::vector &candidates = (*ni).node->candidates(); - for (std::vector::const_iterator ci = candidates.begin(), ce = candidates.end(); ci != ce; ++ci) { + for (std::vector::iterator ni = nodes.begin(), ne = nodes.end(); ni != ne; ++ni) { + const std::vector &candidates = (*ni).node->candidates(); + for (std::vector::const_iterator ci = candidates.begin(), ce = candidates.end(); ci != ce; ++ci) { [candidatesArray addObject:[NSString stringWithUTF8String:(*ci).value.c_str()]]; } } diff --git a/Source/Modules/LangModelRelated/LMInstantiator.h b/Source/Modules/LangModelRelated/LMInstantiator.h index 594cbe23..34507abc 100644 --- a/Source/Modules/LangModelRelated/LMInstantiator.h +++ b/Source/Modules/LangModelRelated/LMInstantiator.h @@ -32,7 +32,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH namespace vChewing { -using namespace Taiyan::Gramambular; +using namespace Gramambular; /// LMInstantiator is a facade for managing a set of models including /// the input method language model, user phrases and excluded phrases. @@ -56,7 +56,7 @@ using namespace Taiyan::Gramambular; /// 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 LMInstantiator : public Taiyan::Gramambular::LanguageModel { +class LMInstantiator : public Gramambular::LanguageModel { public: LMInstantiator(); ~LMInstantiator(); @@ -97,11 +97,11 @@ public: void loadPhraseReplacementMap(const char* phraseReplacementPath); /// Not implemented since we do not have data to provide bigram function. - const std::vector bigramsForKeys(const std::string& preceedingKey, const std::string& key); + const std::vector bigramsForKeys(const std::string& preceedingKey, const std::string& key); /// Returns a list of available unigram for the given key. /// @param key A std::string represents the BPMF reading or a symbol key. For /// example, it you pass "ㄇㄚ", it returns "嗎", "媽", and so on. - const std::vector unigramsForKey(const std::string& key); + const std::vector unigramsForKey(const std::string& key); /// If the model has unigrams for the given key. /// @param key The key. bool hasUnigramsForKey(const std::string& key); @@ -135,7 +135,7 @@ protected: /// @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 std::vector filterAndTransformUnigrams(const std::vector unigrams, + const std::vector filterAndTransformUnigrams(const std::vector unigrams, const std::unordered_set& excludedValues, std::unordered_set& insertedValues); diff --git a/Source/Modules/LangModelRelated/LMInstantiator.mm b/Source/Modules/LangModelRelated/LMInstantiator.mm index 4fe8d376..f9b0eb39 100644 --- a/Source/Modules/LangModelRelated/LMInstantiator.mm +++ b/Source/Modules/LangModelRelated/LMInstantiator.mm @@ -119,16 +119,16 @@ void LMInstantiator::loadPhraseReplacementMap(const char* phraseReplacementPath) } } -const std::vector LMInstantiator::bigramsForKeys(const std::string& preceedingKey, const std::string& key) +const std::vector LMInstantiator::bigramsForKeys(const std::string& preceedingKey, const std::string& key) { - return std::vector(); + return std::vector(); } -const std::vector LMInstantiator::unigramsForKey(const std::string& key) +const std::vector LMInstantiator::unigramsForKey(const std::string& key) { if (key == " ") { - std::vector spaceUnigrams; - Taiyan::Gramambular::Unigram g; + std::vector spaceUnigrams; + Gramambular::Unigram g; g.keyValue.key = " "; g.keyValue.value = " "; g.score = 0; @@ -136,24 +136,24 @@ const std::vector LMInstantiator::unigramsForKey(c return spaceUnigrams; } - std::vector allUnigrams; - std::vector miscUnigrams; - std::vector symbolUnigrams; - std::vector userUnigrams; - std::vector cnsUnigrams; + std::vector allUnigrams; + std::vector miscUnigrams; + std::vector symbolUnigrams; + std::vector userUnigrams; + std::vector cnsUnigrams; std::unordered_set excludedValues; std::unordered_set insertedValues; if (m_excludedPhrases.hasUnigramsForKey(key)) { - std::vector excludedUnigrams = m_excludedPhrases.unigramsForKey(key); + std::vector excludedUnigrams = m_excludedPhrases.unigramsForKey(key); transform(excludedUnigrams.begin(), excludedUnigrams.end(), inserter(excludedValues, excludedValues.end()), - [](const Taiyan::Gramambular::Unigram& u) { return u.keyValue.value; }); + [](const Gramambular::Unigram& u) { return u.keyValue.value; }); } if (m_userPhrases.hasUnigramsForKey(key)) { - std::vector rawUserUnigrams = m_userPhrases.unigramsForKey(key); + std::vector rawUserUnigrams = m_userPhrases.unigramsForKey(key); // 用這句指令讓使用者語彙檔案內的詞條優先順序隨著行數增加而逐漸增高。 // 這樣一來就可以在就地新增語彙時徹底複寫優先權。 std::reverse(rawUserUnigrams.begin(), rawUserUnigrams.end()); @@ -161,22 +161,22 @@ const std::vector LMInstantiator::unigramsForKey(c } if (m_languageModel.hasUnigramsForKey(key)) { - std::vector rawGlobalUnigrams = m_languageModel.unigramsForKey(key); + std::vector rawGlobalUnigrams = m_languageModel.unigramsForKey(key); allUnigrams = filterAndTransformUnigrams(rawGlobalUnigrams, excludedValues, insertedValues); } if (m_miscModel.hasUnigramsForKey(key)) { - std::vector rawMiscUnigrams = m_miscModel.unigramsForKey(key); + std::vector rawMiscUnigrams = m_miscModel.unigramsForKey(key); miscUnigrams = filterAndTransformUnigrams(rawMiscUnigrams, excludedValues, insertedValues); } if (m_symbolModel.hasUnigramsForKey(key)) { - std::vector rawSymbolUnigrams = m_symbolModel.unigramsForKey(key); + std::vector rawSymbolUnigrams = m_symbolModel.unigramsForKey(key); symbolUnigrams = filterAndTransformUnigrams(rawSymbolUnigrams, excludedValues, insertedValues); } if (m_cnsModel.hasUnigramsForKey(key) && m_cnsEnabled) { - std::vector rawCNSUnigrams = m_cnsModel.unigramsForKey(key); + std::vector rawCNSUnigrams = m_cnsModel.unigramsForKey(key); cnsUnigrams = filterAndTransformUnigrams(rawCNSUnigrams, excludedValues, insertedValues); } @@ -234,9 +234,9 @@ void LMInstantiator::setExternalConverter(std::function LMInstantiator::filterAndTransformUnigrams(const std::vector unigrams, const std::unordered_set& excludedValues, std::unordered_set& insertedValues) +const std::vector LMInstantiator::filterAndTransformUnigrams(const std::vector unigrams, const std::unordered_set& excludedValues, std::unordered_set& insertedValues) { - std::vector results; + std::vector results; for (auto&& unigram : unigrams) { // excludedValues filters out the unigrams with the original value. @@ -258,7 +258,7 @@ const std::vector LMInstantiator::filterAndTransfo value = replacement; } if (insertedValues.find(value) == insertedValues.end()) { - Taiyan::Gramambular::Unigram g; + Gramambular::Unigram g; g.keyValue.value = value; g.keyValue.key = unigram.keyValue.key; g.score = unigram.score; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.h b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.h index 178ee21a..0beffc83 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.h +++ b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.h @@ -31,11 +31,11 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH // to avoid creating new string objects; the parser is a simple DFA using namespace std; -using namespace Taiyan::Gramambular; +using namespace Gramambular; namespace vChewing { -class CoreLM : public Taiyan::Gramambular::LanguageModel { +class CoreLM : public Gramambular::LanguageModel { public: CoreLM(); ~CoreLM(); @@ -45,8 +45,8 @@ public: void close(); void dump(); - virtual const std::vector bigramsForKeys(const string& preceedingKey, const string& key); - virtual const std::vector unigramsForKey(const string& key); + virtual const std::vector bigramsForKeys(const string& preceedingKey, const string& key); + virtual const std::vector unigramsForKey(const string& key); virtual bool hasUnigramsForKey(const string& key); protected: diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm index 42cf9aae..2f84c4c3 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/CoreLM.mm @@ -25,7 +25,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include -using namespace Taiyan::Gramambular; +using namespace Gramambular; vChewing::CoreLM::CoreLM() : fd(-1) @@ -292,14 +292,14 @@ void vChewing::CoreLM::dump() } } -const std::vector vChewing::CoreLM::bigramsForKeys(const string& preceedingKey, const string& key) +const std::vector vChewing::CoreLM::bigramsForKeys(const string& preceedingKey, const string& key) { - return std::vector(); + return std::vector(); } -const std::vector vChewing::CoreLM::unigramsForKey(const string& key) +const std::vector vChewing::CoreLM::unigramsForKey(const string& key) { - std::vector v; + std::vector v; map >::const_iterator i = keyRowMap.find(key.c_str()); if (i != keyRowMap.end()) { diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.cpp b/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.cpp index 2fd63f03..92104c22 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.cpp +++ b/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.cpp @@ -80,23 +80,23 @@ void vChewing::ParselessLM::close() } } -const std::vector +const std::vector vChewing::ParselessLM::bigramsForKeys( const std::string& preceedingKey, const std::string& key) { - return std::vector(); + return std::vector(); } -const std::vector +const std::vector vChewing::ParselessLM::unigramsForKey(const std::string& key) { if (db_ == nullptr) { - return std::vector(); + return std::vector(); } - std::vector results; + std::vector results; for (const auto& row : db_->findRows(key + " ")) { - Taiyan::Gramambular::Unigram unigram; + Gramambular::Unigram unigram; // Move ahead until we encounter the first space. This is the key. auto it = row.begin(); diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.h b/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.h index df25c494..984054a2 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.h +++ b/Source/Modules/LangModelRelated/SubLanguageModels/ParselessLM.h @@ -29,7 +29,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH namespace vChewing { -class ParselessLM : public Taiyan::Gramambular::LanguageModel { +class ParselessLM : public Gramambular::LanguageModel { public: ~ParselessLM() override; @@ -37,9 +37,9 @@ public: bool open(const std::string_view& path); void close(); - const std::vector bigramsForKeys( + const std::vector bigramsForKeys( const std::string& preceedingKey, const std::string& key) override; - const std::vector unigramsForKey( + const std::vector unigramsForKey( const std::string& key) override; bool hasUnigramsForKey(const std::string& key) override; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.cpp b/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.cpp index 2e0a7096..8d30149a 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.cpp +++ b/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.cpp @@ -34,7 +34,7 @@ static double Score(size_t eventCount, double timestamp, double lambda); static bool IsEndingPunctuation(const std::string& value); -static std::string WalkedNodesToKey(const std::vector& walkedNodes, +static std::string WalkedNodesToKey(const std::vector& walkedNodes, size_t cursorIndex); UserOverrideModel::UserOverrideModel(size_t capacity, double decayConstant) @@ -43,7 +43,7 @@ UserOverrideModel::UserOverrideModel(size_t capacity, double decayConstant) m_decayExponent = log(0.5) / decayConstant; } -void UserOverrideModel::observe(const std::vector& walkedNodes, +void UserOverrideModel::observe(const std::vector& walkedNodes, size_t cursorIndex, const std::string& candidate, double timestamp) { @@ -76,7 +76,7 @@ void UserOverrideModel::observe(const std::vector& walkedNodes, +std::string UserOverrideModel::suggest(const std::vector& walkedNodes, size_t cursorIndex, double timestamp) { std::string key = WalkedNodesToKey(walkedNodes, cursorIndex); @@ -138,12 +138,12 @@ static bool IsEndingPunctuation(const std::string& value) { return value == "," || value == "。" || value== "!" || value == "?" || value == "」" || value == "』" || value== "”" || value == "’"; } -static std::string WalkedNodesToKey(const std::vector& walkedNodes, +static std::string WalkedNodesToKey(const std::vector& walkedNodes, size_t cursorIndex) { std::stringstream s; - std::vector n; + std::vector n; size_t ll = 0; - for (std::vector::const_iterator i = walkedNodes.begin(); + for (std::vector::const_iterator i = walkedNodes.begin(); i != walkedNodes.end(); ++i) { const auto& nn = *i; @@ -154,7 +154,7 @@ static std::string WalkedNodesToKey(const std::vector::const_reverse_iterator r = n.rbegin(); + std::vector::const_reverse_iterator r = n.rbegin(); if (r == n.rend()) { return ""; diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.h b/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.h index 7189f5d2..10824c4b 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.h +++ b/Source/Modules/LangModelRelated/SubLanguageModels/UserOverrideModel.h @@ -27,18 +27,18 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH namespace vChewing { -using namespace Taiyan::Gramambular; +using namespace Gramambular; class UserOverrideModel { public: UserOverrideModel(size_t capacity, double decayConstant); - void observe(const std::vector& walkedNodes, + void observe(const std::vector& walkedNodes, size_t cursorIndex, const std::string& candidate, double timestamp); - std::string suggest(const std::vector& walkedNodes, + std::string suggest(const std::vector& walkedNodes, size_t cursorIndex, double timestamp); diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.h b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.h index 33d57c61..05881911 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.h +++ b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.h @@ -27,7 +27,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH namespace vChewing { -class UserPhrasesLM : public Taiyan::Gramambular::LanguageModel +class UserPhrasesLM : public Gramambular::LanguageModel { public: UserPhrasesLM(); @@ -46,8 +46,8 @@ public: return 0.0; } - virtual const std::vector bigramsForKeys(const std::string& preceedingKey, const std::string& key); - virtual const std::vector unigramsForKey(const std::string& key); + virtual const std::vector bigramsForKeys(const std::string& preceedingKey, const std::string& key); + virtual const std::vector unigramsForKey(const std::string& key); virtual bool hasUnigramsForKey(const std::string& key); protected: diff --git a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm index 6ae55429..f530f21f 100644 --- a/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm +++ b/Source/Modules/LangModelRelated/SubLanguageModels/UserPhrasesLM.mm @@ -121,19 +121,19 @@ void UserPhrasesLM::dump() } } -const std::vector UserPhrasesLM::bigramsForKeys(const std::string& preceedingKey, const std::string& key) +const std::vector UserPhrasesLM::bigramsForKeys(const std::string& preceedingKey, const std::string& key) { - return std::vector(); + return std::vector(); } -const std::vector UserPhrasesLM::unigramsForKey(const std::string& key) +const std::vector UserPhrasesLM::unigramsForKey(const std::string& key) { - std::vector v; + std::vector v; auto iter = keyRowMap.find(key); if (iter != keyRowMap.end()) { const std::vector& rows = iter->second; for (const auto& row : rows) { - Taiyan::Gramambular::Unigram g; + Gramambular::Unigram g; g.keyValue.key = row.key; g.keyValue.value = row.value; g.score = overridedValue(); diff --git a/Source/Modules/LanguageParsers/Gramambular/Bigram.h b/Source/Modules/LanguageParsers/Gramambular/Bigram.h index 5995238d..16576b31 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Bigram.h +++ b/Source/Modules/LanguageParsers/Gramambular/Bigram.h @@ -24,7 +24,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "KeyValuePair.h" -namespace Taiyan { namespace Gramambular { class Bigram { public: @@ -88,6 +87,6 @@ inline bool Bigram::operator<(const Bigram& another) const { return false; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/BlockReadingBuilder.h b/Source/Modules/LanguageParsers/Gramambular/BlockReadingBuilder.h index a74a79f4..4ece863b 100644 --- a/Source/Modules/LanguageParsers/Gramambular/BlockReadingBuilder.h +++ b/Source/Modules/LanguageParsers/Gramambular/BlockReadingBuilder.h @@ -26,7 +26,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "Grid.h" #include "LanguageModel.h" -namespace Taiyan { namespace Gramambular { class BlockReadingBuilder { @@ -201,6 +200,6 @@ inline const std::string BlockReadingBuilder::Join( return result; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Grid.h b/Source/Modules/LanguageParsers/Gramambular/Grid.h index f81c9301..3fd5c206 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Grid.h +++ b/Source/Modules/LanguageParsers/Gramambular/Grid.h @@ -27,7 +27,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "NodeAnchor.h" #include "Span.h" -namespace Taiyan { namespace Gramambular { class Grid { @@ -218,6 +217,6 @@ inline void Grid::overrideNodeScoreForSelectedCandidate( } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Grid.mm b/Source/Modules/LanguageParsers/Gramambular/Grid.mm index ba76a6e0..9e96c28e 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Grid.mm +++ b/Source/Modules/LanguageParsers/Gramambular/Grid.mm @@ -22,7 +22,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include -namespace Taiyan { namespace Gramambular { std::string Grid::dumpDOT() { @@ -67,4 +66,4 @@ std::string Grid::dumpDOT() { } } // namespace Gramambular -} // namespace Taiyan + diff --git a/Source/Modules/LanguageParsers/Gramambular/KeyValuePair.h b/Source/Modules/LanguageParsers/Gramambular/KeyValuePair.h index e22a96bd..569687ed 100644 --- a/Source/Modules/LanguageParsers/Gramambular/KeyValuePair.h +++ b/Source/Modules/LanguageParsers/Gramambular/KeyValuePair.h @@ -23,7 +23,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include #include -namespace Taiyan { namespace Gramambular { class KeyValuePair { @@ -54,6 +53,6 @@ inline bool KeyValuePair::operator<(const KeyValuePair& another) const { return false; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/LanguageModel.h b/Source/Modules/LanguageParsers/Gramambular/LanguageModel.h index b24f7fff..bed61ab5 100644 --- a/Source/Modules/LanguageParsers/Gramambular/LanguageModel.h +++ b/Source/Modules/LanguageParsers/Gramambular/LanguageModel.h @@ -26,7 +26,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "Bigram.h" #include "Unigram.h" -namespace Taiyan { namespace Gramambular { class LanguageModel { @@ -39,6 +38,6 @@ public: virtual bool hasUnigramsForKey(const std::string& key) = 0; }; } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Node.h b/Source/Modules/LanguageParsers/Gramambular/Node.h index dfc961c5..42de5910 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Node.h +++ b/Source/Modules/LanguageParsers/Gramambular/Node.h @@ -27,7 +27,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "LanguageModel.h" -namespace Taiyan { namespace Gramambular { class Node { @@ -209,6 +208,6 @@ inline const KeyValuePair Node::currentKeyValue() const { } } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/NodeAnchor.h b/Source/Modules/LanguageParsers/Gramambular/NodeAnchor.h index f215c92e..485bb51f 100644 --- a/Source/Modules/LanguageParsers/Gramambular/NodeAnchor.h +++ b/Source/Modules/LanguageParsers/Gramambular/NodeAnchor.h @@ -24,7 +24,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "Node.h" -namespace Taiyan { namespace Gramambular { struct NodeAnchor { @@ -59,6 +58,6 @@ inline std::ostream& operator<<(std::ostream& stream, return stream; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Span.h b/Source/Modules/LanguageParsers/Gramambular/Span.h index e46df777..30c12692 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Span.h +++ b/Source/Modules/LanguageParsers/Gramambular/Span.h @@ -26,7 +26,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "Node.h" -namespace Taiyan { namespace Gramambular { class Span { public: @@ -88,6 +87,6 @@ inline Node* Span::nodeOfLength(size_t length) { inline size_t Span::maximumLength() const { return m_maximumLength; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Unigram.h b/Source/Modules/LanguageParsers/Gramambular/Unigram.h index b05e55f6..45b461d4 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Unigram.h +++ b/Source/Modules/LanguageParsers/Gramambular/Unigram.h @@ -24,7 +24,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "KeyValuePair.h" -namespace Taiyan { namespace Gramambular { class Unigram { @@ -86,6 +85,6 @@ inline bool Unigram::ScoreCompare(const Unigram& a, const Unigram& b) { return a.score > b.score; } } // namespace Gramambular -} // namespace Taiyan + #endif diff --git a/Source/Modules/LanguageParsers/Gramambular/Walker.h b/Source/Modules/LanguageParsers/Gramambular/Walker.h index fdb035d6..b694c7e7 100644 --- a/Source/Modules/LanguageParsers/Gramambular/Walker.h +++ b/Source/Modules/LanguageParsers/Gramambular/Walker.h @@ -25,7 +25,6 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH #include "Grid.h" -namespace Taiyan { namespace Gramambular { class Walker { @@ -80,6 +79,6 @@ inline const std::vector Walker::reverseWalk( return *result; } } // namespace Gramambular -} // namespace Taiyan + #endif