Reset // Bringing back the CNS11643 support.
This commit is contained in:
parent
d82c97b8d9
commit
3af1dafb28
|
@ -151,6 +151,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
|
|||
// create the lattice builder
|
||||
_languageModel = [mgrLangModel lmCHT];
|
||||
_languageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled);
|
||||
_languageModel->setCNSEnabled(Preferences.cns11643Enabled);
|
||||
_userOverrideModel = [mgrLangModel userOverrideModelCHT];
|
||||
|
||||
_builder = new BlockReadingBuilder(_languageModel);
|
||||
|
|
|
@ -212,10 +212,7 @@ class ctlInputMethod: IMKInputController {
|
|||
}
|
||||
|
||||
@objc func toggleCNS11643Enabled(_ sender: Any?) {
|
||||
// let enabled = Preferences.toggleCNS11643Enabled()
|
||||
// mgrLangModel.cnsEnabledCHS = enabled
|
||||
// mgrLangModel.cnsEnabledCHT = enabled
|
||||
_ = Preferences.toggleCNS11643Enabled()
|
||||
mgrLangModel.setCNSEnabled(Preferences.toggleCNS11643Enabled())
|
||||
NotifierController.notify(message: String(format: "%@%@%@", NSLocalizedString("CNS11643 Mode", comment: ""), "\n", Preferences.cns11643Enabled ? NSLocalizedString("NotificationSwitchON", comment: "") : NSLocalizedString("NotificationSwitchOFF", comment: "")))
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
CNSLM();
|
||||
~CNSLM();
|
||||
|
||||
bool isLoaded();
|
||||
bool open(const char *path);
|
||||
void close();
|
||||
void dump();
|
||||
|
|
|
@ -44,6 +44,14 @@ CNSLM::~CNSLM()
|
|||
}
|
||||
}
|
||||
|
||||
bool CNSLM::isLoaded()
|
||||
{
|
||||
if (data) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNSLM::open(const char *path)
|
||||
{
|
||||
if (data) {
|
||||
|
|
|
@ -33,8 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
+ (BOOL)checkIfUserPhraseExist:(NSString *)userPhrase key:(NSString *)key NS_SWIFT_NAME(checkIfExist(userPhrase:key:));
|
||||
+ (BOOL)writeUserPhrase:(NSString *)userPhrase inputMode:(InputMode)mode;
|
||||
+ (void)setPhraseReplacementEnabled:(BOOL)phraseReplacementEnabled;
|
||||
+ (BOOL)cnsEnabled:(InputMode)mode;
|
||||
+ (void)setCNSEnabled:(BOOL)cnsEnabled inputMode:(InputMode)mode;
|
||||
+ (void)setCNSEnabled:(BOOL)cnsEnabled;
|
||||
+ (NSString *)userPhrasesDataPath:(InputMode)mode;
|
||||
+ (NSString *)excludedPhrasesDataPath:(InputMode)mode;
|
||||
+ (NSString *)phraseReplacementDataPath:(InputMode)mode;
|
||||
|
|
|
@ -58,9 +58,18 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHT.isDataModelLoaded()) {
|
||||
LTLoadLanguageModelFile(@"data-cht", gLangModelCHT);
|
||||
}
|
||||
if (!gLangModelCHT.isCNSDataLoaded()){
|
||||
gLangModelCHT.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHT.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHT);
|
||||
}
|
||||
if (!gLangModelCHS.isDataModelLoaded()) {
|
||||
LTLoadLanguageModelFile(@"data-chs", gLangModelCHS);
|
||||
}
|
||||
if (!gLangModelCHS.isCNSDataLoaded()){
|
||||
gLangModelCHS.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHS.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHS);
|
||||
}
|
||||
|
@ -72,6 +81,9 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHT.isDataModelLoaded()) {
|
||||
LTLoadLanguageModelFile(@"data-cht", gLangModelCHT);
|
||||
}
|
||||
if (!gLangModelCHT.isCNSDataLoaded()){
|
||||
gLangModelCHT.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHT.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHT);
|
||||
}
|
||||
|
@ -81,6 +93,9 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
if (!gLangModelCHS.isDataModelLoaded()) {
|
||||
LTLoadLanguageModelFile(@"data-chs", gLangModelCHS);
|
||||
}
|
||||
if (!gLangModelCHS.isCNSDataLoaded()){
|
||||
gLangModelCHS.loadCNSData([[self cnsDataPath] UTF8String]);
|
||||
}
|
||||
if (!gLangModelCHS.isAssociatedPhrasesLoaded()) {
|
||||
LTLoadAssociatedPhrases(gLangModelCHS);
|
||||
}
|
||||
|
@ -285,6 +300,12 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
return [[self dataFolderPath] stringByAppendingPathComponent:fileName];
|
||||
}
|
||||
|
||||
+ (NSString *)cnsDataPath
|
||||
{
|
||||
Class cls = NSClassFromString(@"ctlInputMethod");
|
||||
return [[NSBundle bundleForClass:cls] pathForResource:@"char-kanji-cns" ofType:@"txt"];
|
||||
}
|
||||
|
||||
+ (vChewingLM *)lmCHT
|
||||
{
|
||||
return &gLangModelCHT;
|
||||
|
@ -311,4 +332,10 @@ static void LTLoadAssociatedPhrases(vChewingLM &lm)
|
|||
gLangModelCHS.setPhraseReplacementEnabled(phraseReplacementEnabled);
|
||||
}
|
||||
|
||||
+ (void)setCNSEnabled:(BOOL)cnsEnabled
|
||||
{
|
||||
gLangModelCHT.setCNSEnabled(cnsEnabled);
|
||||
gLangModelCHS.setCNSEnabled(cnsEnabled);
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -31,6 +31,7 @@ vChewingLM::~vChewingLM()
|
|||
{
|
||||
m_languageModel.close();
|
||||
m_userPhrases.close();
|
||||
m_cnsModel.close();
|
||||
m_excludedPhrases.close();
|
||||
m_phraseReplacement.close();
|
||||
m_associatedPhrases.close();
|
||||
|
@ -62,6 +63,19 @@ bool vChewingLM::isAssociatedPhrasesLoaded()
|
|||
return m_associatedPhrases.isLoaded();
|
||||
}
|
||||
|
||||
void vChewingLM::loadCNSData(const char* cnsDataPath)
|
||||
{
|
||||
if (cnsDataPath) {
|
||||
m_cnsModel.close();
|
||||
m_cnsModel.open(cnsDataPath);
|
||||
}
|
||||
}
|
||||
|
||||
bool vChewingLM::isCNSDataLoaded()
|
||||
{
|
||||
return m_cnsModel.isLoaded();
|
||||
}
|
||||
|
||||
void vChewingLM::loadUserPhrases(const char* userPhrasesDataPath,
|
||||
const char* excludedPhrasesDataPath)
|
||||
{
|
||||
|
@ -102,6 +116,7 @@ const vector<Unigram> vChewingLM::unigramsForKey(const string& key)
|
|||
|
||||
vector<Unigram> allUnigrams;
|
||||
vector<Unigram> userUnigrams;
|
||||
vector<Unigram> cnsUnigrams;
|
||||
|
||||
unordered_set<string> excludedValues;
|
||||
unordered_set<string> insertedValues;
|
||||
|
@ -123,7 +138,13 @@ const vector<Unigram> vChewingLM::unigramsForKey(const string& key)
|
|||
allUnigrams = filterAndTransformUnigrams(rawGlobalUnigrams, excludedValues, insertedValues);
|
||||
}
|
||||
|
||||
if (m_cnsModel.hasUnigramsForKey(key) && m_cnsEnabled) {
|
||||
vector<Unigram> rawCNSUnigrams = m_cnsModel.unigramsForKey(key);
|
||||
cnsUnigrams = filterAndTransformUnigrams(rawCNSUnigrams, excludedValues, insertedValues);
|
||||
}
|
||||
|
||||
allUnigrams.insert(allUnigrams.begin(), userUnigrams.begin(), userUnigrams.end());
|
||||
allUnigrams.insert(allUnigrams.end(), cnsUnigrams.begin(), cnsUnigrams.end());
|
||||
return allUnigrams;
|
||||
}
|
||||
|
||||
|
@ -150,6 +171,15 @@ bool vChewingLM::phraseReplacementEnabled()
|
|||
return m_phraseReplacementEnabled;
|
||||
}
|
||||
|
||||
void vChewingLM::setCNSEnabled(bool enabled)
|
||||
{
|
||||
m_cnsEnabled = enabled;
|
||||
}
|
||||
bool vChewingLM::cnsEnabled()
|
||||
{
|
||||
return m_cnsEnabled;
|
||||
}
|
||||
|
||||
void vChewingLM::setExternalConverterEnabled(bool enabled)
|
||||
{
|
||||
m_externalConverterEnabled = enabled;
|
||||
|
|
|
@ -23,6 +23,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
|
|||
#include <stdio.h>
|
||||
#include "UserPhrasesLM.h"
|
||||
#include "ParselessLM.h"
|
||||
#include "CNSLM.h"
|
||||
#include "PhraseReplacementMap.h"
|
||||
#include "AssociatedPhrases.h"
|
||||
#include <unordered_set>
|
||||
|
@ -64,6 +65,12 @@ public:
|
|||
/// If the data model is already loaded.
|
||||
bool isDataModelLoaded();
|
||||
|
||||
/// Asks to load the primary language model at the given path.
|
||||
/// @param cnsDataPath The path of the CNS data model.
|
||||
void loadCNSData(const char* cnsDataPath);
|
||||
/// If the data model is already loaded.
|
||||
bool isCNSDataLoaded();
|
||||
|
||||
/// Asks to load the associated phrases at the given path.
|
||||
/// @param associatedPhrasesPath The path of the associated phrases.
|
||||
void loadAssociatedPhrases(const char* associatedPhrasesPath);
|
||||
|
@ -93,6 +100,11 @@ public:
|
|||
/// If phrase replacement is enabled or not.
|
||||
bool phraseReplacementEnabled();
|
||||
|
||||
/// Enables or disables CNS11643 input.
|
||||
void setCNSEnabled(bool enabled);
|
||||
/// If CNS11643 input is enabled or not.
|
||||
bool cnsEnabled();
|
||||
|
||||
/// Enables or disables the external converter.
|
||||
void setExternalConverterEnabled(bool enabled);
|
||||
/// If the external converted is enabled or not.
|
||||
|
@ -117,11 +129,13 @@ protected:
|
|||
std::unordered_set<string>& insertedValues);
|
||||
|
||||
ParselessLM m_languageModel;
|
||||
CNSLM m_cnsModel;
|
||||
UserPhrasesLM m_userPhrases;
|
||||
UserPhrasesLM m_excludedPhrases;
|
||||
PhraseReplacementMap m_phraseReplacement;
|
||||
AssociatedPhrases m_associatedPhrases;
|
||||
bool m_phraseReplacementEnabled;
|
||||
bool m_cnsEnabled;
|
||||
bool m_externalConverterEnabled;
|
||||
std::function<string(string)> m_externalConverter;
|
||||
};
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
5BBBB77527AED70B0023B93A /* MenuIcon-SCVIM.png in Resources */ = {isa = PBXBuildFile; fileRef = 5BBBB77127AED70B0023B93A /* MenuIcon-SCVIM.png */; };
|
||||
5BBBB77627AED70B0023B93A /* MenuIcon-TCVIM.png in Resources */ = {isa = PBXBuildFile; fileRef = 5BBBB77227AED70B0023B93A /* MenuIcon-TCVIM.png */; };
|
||||
5BBBB77A27AEDC690023B93A /* clsSFX.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBBB77927AEDC690023B93A /* clsSFX.swift */; };
|
||||
5BD05B8127B22F3C004C4F1D /* char-kanji-cns.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5BD05B8027B22F3C004C4F1D /* char-kanji-cns.txt */; };
|
||||
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4F2015FC0EB100ABF4B3 /* Mandarin.cpp */; };
|
||||
6A187E2616004C5900466B2E /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6A187E2816004C5900466B2E /* MainMenu.xib */; };
|
||||
6A225A1F23679F2600F685C6 /* NotarizedArchives in Resources */ = {isa = PBXBuildFile; fileRef = 6A225A1E23679F2600F685C6 /* NotarizedArchives */; };
|
||||
|
@ -140,6 +141,7 @@
|
|||
5BBBB77227AED70B0023B93A /* MenuIcon-TCVIM.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "MenuIcon-TCVIM.png"; sourceTree = "<group>"; };
|
||||
5BBBB77727AEDB290023B93A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/MainMenu.strings; sourceTree = "<group>"; };
|
||||
5BBBB77927AEDC690023B93A /* clsSFX.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = clsSFX.swift; sourceTree = "<group>"; };
|
||||
5BD05B8027B22F3C004C4F1D /* char-kanji-cns.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = "char-kanji-cns.txt"; path = "Data/components/common/char-kanji-cns.txt"; sourceTree = "<group>"; };
|
||||
6A0D4EA215FC0D2D00ABF4B3 /* vChewing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = vChewing.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
6A0D4EF515FC0DA600ABF4B3 /* IME-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "IME-Info.plist"; sourceTree = "<group>"; };
|
||||
6A0D4EF615FC0DA600ABF4B3 /* vChewing-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "vChewing-Prefix.pch"; sourceTree = "<group>"; };
|
||||
|
@ -445,9 +447,10 @@
|
|||
5B62A35027AE7F6600A19448 /* Data */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
5B2DB17127AF8771006D874E /* Makefile */,
|
||||
5BD05B8027B22F3C004C4F1D /* char-kanji-cns.txt */,
|
||||
5B2DB16D27AF6891006D874E /* data-chs.txt */,
|
||||
5B2DB16E27AF6891006D874E /* data-cht.txt */,
|
||||
5B2DB17127AF8771006D874E /* Makefile */,
|
||||
);
|
||||
name = Data;
|
||||
sourceTree = "<group>";
|
||||
|
@ -705,6 +708,7 @@
|
|||
5BBBB76D27AED5DB0023B93A /* frmAboutWindow.xib in Resources */,
|
||||
5BBBB77527AED70B0023B93A /* MenuIcon-SCVIM.png in Resources */,
|
||||
5B7BC4B027AFFBE800F66C24 /* frmPrefWindow.xib in Resources */,
|
||||
5BD05B8127B22F3C004C4F1D /* char-kanji-cns.txt in Resources */,
|
||||
5B2DB17027AF6891006D874E /* data-cht.txt in Resources */,
|
||||
5BBBB77327AED70B0023B93A /* MenuIcon-TCVIM@2x.png in Resources */,
|
||||
5BBBB77627AED70B0023B93A /* MenuIcon-TCVIM.png in Resources */,
|
||||
|
|
Loading…
Reference in New Issue