IME // Rebrand vChewingLM to LMInstantiator.

This commit is contained in:
ShikiSuen 2022-02-20 19:52:43 +08:00
parent fd143e323c
commit 4d2756105c
6 changed files with 47 additions and 47 deletions

View File

@ -19,7 +19,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#import "Mandarin.h"
#import "Gramambular.h"
#import "vChewingLM.h"
#import "LMInstantiator.h"
#import "UserOverrideModel.h"
#import "mgrLangModel_Privates.h"
#import "KeyHandler.h"
@ -71,7 +71,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
Taiyan::Mandarin::BopomofoReadingBuffer *_bpmfReadingBuffer;
// language model
vChewing::vChewingLM *_languageModel;
vChewing::LMInstantiator *_languageModel;
// user override model
vChewing::UserOverrideModel *_userOverrideModel;
@ -96,7 +96,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
- (void)setInputMode:(NSString *)value
{
NSString *newInputMode;
vChewingLM *newLanguageModel;
LMInstantiator *newLanguageModel;
UserOverrideModel *newUserOverrideModel;
if ([value isKindOfClass:[NSString class]] && [value isEqual:imeModeCHS]) {

View File

@ -17,8 +17,8 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABI
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef VCHEWINGLM_H
#define VCHEWINGLM_H
#ifndef LMInstantiator_H
#define LMInstantiator_H
#include <stdio.h>
#include "UserPhrasesLM.h"
@ -32,7 +32,7 @@ namespace vChewing {
using namespace Taiyan::Gramambular;
/// vChewingLM is a facade for managing a set of models including
/// LMInstantiator 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 grammar builder
@ -41,7 +41,7 @@ using namespace Taiyan::Gramambular;
/// if there are valid unigrams, and use returned unigrams to produce the final
/// results.
///
/// vChewingLM combine and transform the unigrams from the primary language
/// LMInstantiator combine and transform the unigrams from the primary language
/// model and user phrases. The process is
///
/// 1) Get the original unigrams.
@ -54,10 +54,10 @@ 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 vChewingLM : public LanguageModel {
class LMInstantiator : public LanguageModel {
public:
vChewingLM();
~vChewingLM();
LMInstantiator();
~LMInstantiator();
/// Asks to load the primary language model at the given path.
/// @param languageModelPath The path of the language model.

View File

@ -17,17 +17,17 @@ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABI
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "vChewingLM.h"
#include "LMInstantiator.h"
#include <algorithm>
#include <iterator>
using namespace vChewing;
vChewingLM::vChewingLM()
LMInstantiator::LMInstantiator()
{
}
vChewingLM::~vChewingLM()
LMInstantiator::~LMInstantiator()
{
m_languageModel.close();
m_userPhrases.close();
@ -37,7 +37,7 @@ vChewingLM::~vChewingLM()
m_associatedPhrases.close();
}
void vChewingLM::loadLanguageModel(const char* languageModelDataPath)
void LMInstantiator::loadLanguageModel(const char* languageModelDataPath)
{
if (languageModelDataPath) {
m_languageModel.close();
@ -45,12 +45,12 @@ void vChewingLM::loadLanguageModel(const char* languageModelDataPath)
}
}
bool vChewingLM::isDataModelLoaded()
bool LMInstantiator::isDataModelLoaded()
{
return m_languageModel.isLoaded();
}
void vChewingLM::loadCNSData(const char* cnsDataPath)
void LMInstantiator::loadCNSData(const char* cnsDataPath)
{
if (cnsDataPath) {
m_cnsModel.close();
@ -58,12 +58,12 @@ void vChewingLM::loadCNSData(const char* cnsDataPath)
}
}
bool vChewingLM::isCNSDataLoaded()
bool LMInstantiator::isCNSDataLoaded()
{
return m_cnsModel.isLoaded();
}
void vChewingLM::loadUserPhrases(const char* userPhrasesDataPath,
void LMInstantiator::loadUserPhrases(const char* userPhrasesDataPath,
const char* excludedPhrasesDataPath)
{
if (userPhrasesDataPath) {
@ -76,7 +76,7 @@ void vChewingLM::loadUserPhrases(const char* userPhrasesDataPath,
}
}
void vChewingLM::loadUserAssociatedPhrases(const char *userAssociatedPhrasesPath)
void LMInstantiator::loadUserAssociatedPhrases(const char *userAssociatedPhrasesPath)
{
if (userAssociatedPhrasesPath) {
m_associatedPhrases.close();
@ -84,7 +84,7 @@ void vChewingLM::loadUserAssociatedPhrases(const char *userAssociatedPhrasesPath
}
}
void vChewingLM::loadPhraseReplacementMap(const char* phraseReplacementPath)
void LMInstantiator::loadPhraseReplacementMap(const char* phraseReplacementPath)
{
if (phraseReplacementPath) {
m_phraseReplacement.close();
@ -92,12 +92,12 @@ void vChewingLM::loadPhraseReplacementMap(const char* phraseReplacementPath)
}
}
const vector<Bigram> vChewingLM::bigramsForKeys(const string& preceedingKey, const string& key)
const vector<Bigram> LMInstantiator::bigramsForKeys(const string& preceedingKey, const string& key)
{
return vector<Bigram>();
}
const vector<Unigram> vChewingLM::unigramsForKey(const string& key)
const vector<Unigram> LMInstantiator::unigramsForKey(const string& key)
{
if (key == " ") {
vector<Unigram> spaceUnigrams;
@ -143,7 +143,7 @@ const vector<Unigram> vChewingLM::unigramsForKey(const string& key)
return allUnigrams;
}
bool vChewingLM::hasUnigramsForKey(const string& key)
bool LMInstantiator::hasUnigramsForKey(const string& key)
{
if (key == " ") {
return true;
@ -156,41 +156,41 @@ bool vChewingLM::hasUnigramsForKey(const string& key)
return unigramsForKey(key).size() > 0;
}
void vChewingLM::setPhraseReplacementEnabled(bool enabled)
void LMInstantiator::setPhraseReplacementEnabled(bool enabled)
{
m_phraseReplacementEnabled = enabled;
}
bool vChewingLM::phraseReplacementEnabled()
bool LMInstantiator::phraseReplacementEnabled()
{
return m_phraseReplacementEnabled;
}
void vChewingLM::setCNSEnabled(bool enabled)
void LMInstantiator::setCNSEnabled(bool enabled)
{
m_cnsEnabled = enabled;
}
bool vChewingLM::cnsEnabled()
bool LMInstantiator::cnsEnabled()
{
return m_cnsEnabled;
}
void vChewingLM::setExternalConverterEnabled(bool enabled)
void LMInstantiator::setExternalConverterEnabled(bool enabled)
{
m_externalConverterEnabled = enabled;
}
bool vChewingLM::externalConverterEnabled()
bool LMInstantiator::externalConverterEnabled()
{
return m_externalConverterEnabled;
}
void vChewingLM::setExternalConverter(std::function<string(string)> externalConverter)
void LMInstantiator::setExternalConverter(std::function<string(string)> externalConverter)
{
m_externalConverter = externalConverter;
}
const vector<Unigram> vChewingLM::filterAndTransformUnigrams(const vector<Unigram> unigrams, const unordered_set<string>& excludedValues, unordered_set<string>& insertedValues)
const vector<Unigram> LMInstantiator::filterAndTransformUnigrams(const vector<Unigram> unigrams, const unordered_set<string>& excludedValues, unordered_set<string>& insertedValues)
{
vector<Unigram> results;
@ -225,12 +225,12 @@ const vector<Unigram> vChewingLM::filterAndTransformUnigrams(const vector<Unigra
return results;
}
const vector<std::string> vChewingLM::associatedPhrasesForKey(const string& key)
const vector<std::string> LMInstantiator::associatedPhrasesForKey(const string& key)
{
return m_associatedPhrases.valuesForKey(key);
}
bool vChewingLM::hasAssociatedPhrasesForKey(const string& key)
bool LMInstantiator::hasAssociatedPhrasesForKey(const string& key)
{
return m_associatedPhrases.hasValuesForKey(key);
}

View File

@ -28,8 +28,8 @@ using namespace vChewing;
static const int kUserOverrideModelCapacity = 500;
static const double kObservedOverrideHalflife = 5400.0;
static vChewingLM gLangModelCHT;
static vChewingLM gLangModelCHS;
static LMInstantiator gLangModelCHT;
static LMInstantiator gLangModelCHS;
static UserOverrideModel gUserOverrideModelCHT(kUserOverrideModelCapacity, kObservedOverrideHalflife);
static UserOverrideModel gUserOverrideModelCHS(kUserOverrideModelCapacity, kObservedOverrideHalflife);
@ -41,7 +41,7 @@ static NSString *const kTemplateExtension = @".txt";
@implementation mgrLangModel
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewingLM &lm)
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, LMInstantiator &lm)
{
Class cls = NSClassFromString(@"ctlInputMethod");
NSString *dataPath = [[NSBundle bundleForClass:cls] pathForResource:filenameWithoutExtension ofType:@"txt"];
@ -317,12 +317,12 @@ static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewing
return [[NSBundle bundleForClass:cls] pathForResource:@"char-kanji-cns" ofType:@"txt"];
}
+ (vChewingLM *)lmCHT
+ (LMInstantiator *)lmCHT
{
return &gLangModelCHT;
}
+ (vChewingLM *)lmCHS
+ (LMInstantiator *)lmCHS
{
return &gLangModelCHS;
}

View File

@ -19,13 +19,13 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#import "mgrLangModel.h"
#import "UserOverrideModel.h"
#import "vChewingLM.h"
#import "LMInstantiator.h"
NS_ASSUME_NONNULL_BEGIN
@interface mgrLangModel ()
@property (class, readonly, nonatomic) vChewing::vChewingLM *lmCHT;
@property (class, readonly, nonatomic) vChewing::vChewingLM *lmCHS;
@property (class, readonly, nonatomic) vChewing::LMInstantiator *lmCHT;
@property (class, readonly, nonatomic) vChewing::LMInstantiator *lmCHS;
@property (class, readonly, nonatomic) vChewing::UserOverrideModel *userOverrideModelCHS;
@property (class, readonly, nonatomic) vChewing::UserOverrideModel *userOverrideModelCHT;
@end

View File

@ -68,7 +68,7 @@
6ACC3D442793701600F1B140 /* ParselessPhraseDB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6ACC3D402793701600F1B140 /* ParselessPhraseDB.cpp */; };
6ACC3D452793701600F1B140 /* ParselessLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6ACC3D422793701600F1B140 /* ParselessLM.cpp */; };
D41355D8278D74B5005E5CBD /* mgrLangModel.mm in Sources */ = {isa = PBXBuildFile; fileRef = D41355D7278D7409005E5CBD /* mgrLangModel.mm */; };
D41355DB278E6D17005E5CBD /* vChewingLM.mm in Sources */ = {isa = PBXBuildFile; fileRef = D41355D9278E6D17005E5CBD /* vChewingLM.mm */; };
D41355DB278E6D17005E5CBD /* LMInstantiator.mm in Sources */ = {isa = PBXBuildFile; fileRef = D41355D9278E6D17005E5CBD /* LMInstantiator.mm */; };
D41355DE278EA3ED005E5CBD /* UserPhrasesLM.mm in Sources */ = {isa = PBXBuildFile; fileRef = D41355DC278EA3ED005E5CBD /* UserPhrasesLM.mm */; };
D427F76C278CA2B0004A2160 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D427F76B278CA1BA004A2160 /* AppDelegate.swift */; };
D44FB74D2792189A003C80A6 /* PhraseReplacementMap.mm in Sources */ = {isa = PBXBuildFile; fileRef = D44FB74B2792189A003C80A6 /* PhraseReplacementMap.mm */; };
@ -243,8 +243,8 @@
6ACC3D432793701600F1B140 /* ParselessLM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParselessLM.h; sourceTree = "<group>"; };
D41355D6278D7409005E5CBD /* mgrLangModel.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mgrLangModel.h; sourceTree = "<group>"; };
D41355D7278D7409005E5CBD /* mgrLangModel.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = mgrLangModel.mm; sourceTree = "<group>"; };
D41355D9278E6D17005E5CBD /* vChewingLM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = vChewingLM.mm; sourceTree = "<group>"; };
D41355DA278E6D17005E5CBD /* vChewingLM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = vChewingLM.h; sourceTree = "<group>"; };
D41355D9278E6D17005E5CBD /* LMInstantiator.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = LMInstantiator.mm; sourceTree = "<group>"; };
D41355DA278E6D17005E5CBD /* LMInstantiator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LMInstantiator.h; sourceTree = "<group>"; };
D41355DC278EA3ED005E5CBD /* UserPhrasesLM.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UserPhrasesLM.mm; sourceTree = "<group>"; };
D41355DD278EA3ED005E5CBD /* UserPhrasesLM.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UserPhrasesLM.h; sourceTree = "<group>"; };
D427A9BF25ED28CC005D43E0 /* vChewing-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "vChewing-Bridging-Header.h"; sourceTree = "<group>"; };
@ -423,12 +423,12 @@
5B62A32427AE757300A19448 /* LangModelRelated */ = {
isa = PBXGroup;
children = (
D41355D9278E6D17005E5CBD /* LMInstantiator.mm */,
D41355DA278E6D17005E5CBD /* LMInstantiator.h */,
D41355D6278D7409005E5CBD /* mgrLangModel.h */,
D495583A27A5C6C4006ADE1C /* mgrLangModel_Privates.h */,
D41355D7278D7409005E5CBD /* mgrLangModel.mm */,
5B62A32527AE758000A19448 /* SubLanguageModels */,
D41355D9278E6D17005E5CBD /* vChewingLM.mm */,
D41355DA278E6D17005E5CBD /* vChewingLM.h */,
);
path = LangModelRelated;
sourceTree = "<group>";
@ -937,7 +937,7 @@
5B11328927B94CFB00E58451 /* AppleKeyboardConverter.swift in Sources */,
5B62A31827AE73A700A19448 /* zip.m in Sources */,
5B62A32E27AE78B000A19448 /* CNSLM.mm in Sources */,
D41355DB278E6D17005E5CBD /* vChewingLM.mm in Sources */,
D41355DB278E6D17005E5CBD /* LMInstantiator.mm in Sources */,
5B62A31A27AE73A700A19448 /* mztools.m in Sources */,
5B62A32927AE77D100A19448 /* FSEventStreamHelper.swift in Sources */,
D47F7DD3278C1263002F9DD7 /* UserOverrideModel.cpp in Sources */,