v1.2.1 // Reorganizing project folder structure.

- The color contrast of the menu icon for Simplified Chinese mode has been tweaked for better legibility.
- Chinese localized name changed for both CHS and CHT input modes.
- Changed the way how Xcode manages the app versions.
- Renamed certain Window NIBs and their controllers to enforce Hungary naming convention.
- Rebrand FastLM to CoreLM.
- Rebrand LMManager to mgrLM.
This commit is contained in:
ShikiSuen 2022-02-04 21:44:49 +08:00
parent 215e118c8f
commit 339e677011
133 changed files with 558 additions and 641 deletions

View File

@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>CFEULAContent</key>
<string>License texts used in the customized about window.</string>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
@ -17,11 +15,13 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>APPL</string> <string>APPL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.2.0</string> <string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>MBIN</string> <string>MBIN</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>893</string> <string>$(CURRENT_PROJECT_VERSION)</string>
<key>CFEULAContent</key>
<string>License texts used in the customized about window.</string>
<key>LSApplicationCategoryType</key> <key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string> <string>public.app-category.utilities</string>
<key>LSHasLocalizedDisplayName</key> <key>LSHasLocalizedDisplayName</key>

View File

@ -91,7 +91,7 @@
<rect key="frame" x="91" y="166" width="427" height="160"/> <rect key="frame" x="91" y="166" width="427" height="160"/>
<clipView key="contentView" drawsBackground="NO" id="NrY-FL-PVu" userLabel="appEULAContentClip"> <clipView key="contentView" drawsBackground="NO" id="NrY-FL-PVu" userLabel="appEULAContentClip">
<rect key="frame" x="1" y="1" width="425" height="158"/> <rect key="frame" x="1" y="1" width="425" height="158"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask"/>
<subviews> <subviews>
<textView editable="NO" importsGraphics="NO" richText="NO" verticallyResizable="YES" findStyle="bar" smartInsertDelete="YES" id="47J-tO-8TZ" userLabel="appEULAContent"> <textView editable="NO" importsGraphics="NO" richText="NO" verticallyResizable="YES" findStyle="bar" smartInsertDelete="YES" id="47J-tO-8TZ" userLabel="appEULAContent">
<rect key="frame" x="0.0" y="-2" width="425" height="158"/> <rect key="frame" x="0.0" y="-2" width="425" height="158"/>

View File

@ -56,8 +56,8 @@
/* Class = "NSTextFieldCell"; title = "Derived from OpenVanilla McBopopmofo Project."; ObjectID = "QYf-Nf-hoi"; */ /* Class = "NSTextFieldCell"; title = "Derived from OpenVanilla McBopopmofo Project."; ObjectID = "QYf-Nf-hoi"; */
"QYf-Nf-hoi.title" = "Derived from OpenVanilla McBopopmofo Project."; "QYf-Nf-hoi.title" = "Derived from OpenVanilla McBopopmofo Project.";
/* Class = "NSTextFieldCell"; title = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.vChewing Phrase Database Maintained by Shiki Suen."; ObjectID = "VW8-s5-Wpn"; */ /* Class = "NSTextFieldCell"; title = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.\nvChewing Phrase Database Maintained by Shiki Suen."; ObjectID = "VW8-s5-Wpn"; */
"VW8-s5-Wpn.title" = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.vChewing Phrase Database Maintained by Shiki Suen."; "VW8-s5-Wpn.title" = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.\nvChewing Phrase Database Maintained by Shiki Suen.";
/* Class = "NSTextFieldCell"; title = "Placeholder for showing copyright information."; ObjectID = "eo3-TK-0rB"; */ /* Class = "NSTextFieldCell"; title = "Placeholder for showing copyright information."; ObjectID = "eo3-TK-0rB"; */
// "eo3-TK-0rB.title" = "Placeholder for showing copyright information."; // "eo3-TK-0rB.title" = "Placeholder for showing copyright information.";

View File

@ -56,7 +56,7 @@
/* Class = "NSTextFieldCell"; title = "Derived from OpenVanilla McBopopmofo Project."; ObjectID = "QYf-Nf-hoi"; */ /* Class = "NSTextFieldCell"; title = "Derived from OpenVanilla McBopopmofo Project."; ObjectID = "QYf-Nf-hoi"; */
"QYf-Nf-hoi.title" = "OpenVanilla 小麦注音プロジェクトから派生。"; "QYf-Nf-hoi.title" = "OpenVanilla 小麦注音プロジェクトから派生。";
/* Class = "NSTextFieldCell"; title = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.vChewing Phrase Database Maintained by Shiki Suen."; ObjectID = "VW8-s5-Wpn"; */ /* Class = "NSTextFieldCell"; title = "McBopomofo Engine by Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, et al.\nvChewing macOS Development Reinforced by Hiraku Wang.\nvChewing Phrase Database Maintained by Shiki Suen."; ObjectID = "VW8-s5-Wpn"; */
"VW8-s5-Wpn.title" = "小麦注音入力エンジン開発Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, など。\nmacOS 版の開発協力Hiraku Wang。\n威注音語彙データの維持孫志貴 (Shiki Suen)。"; "VW8-s5-Wpn.title" = "小麦注音入力エンジン開発Mengjuei Hsieh, Lukhnos Liu, Zonble Yang, など。\nmacOS 版の開発協力Hiraku Wang。\n威注音語彙データの維持孫志貴 (Shiki Suen)。";
/* Class = "NSTextFieldCell"; title = "Placeholder for showing copyright information."; ObjectID = "eo3-TK-0rB"; */ /* Class = "NSTextFieldCell"; title = "Placeholder for showing copyright information."; ObjectID = "eo3-TK-0rB"; */

Binary file not shown.

View File

@ -1,61 +0,0 @@
/*
* FastLM.h
*
* Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License).
* Some rights reserved. See "LICENSE.TXT" for details.
*/
#ifndef FASTLM_H
#define FASTLM_H
#include <string>
#include <map>
#include <iostream>
#include "LanguageModel.h"
// this class relies on the fact that we have a space-separated data
// format, and we use mmap and zero-out the separators and line feeds
// to avoid creating new string objects; the parser is a simple DFA
namespace Taiyan {
namespace Gramambular {
class FastLM : public LanguageModel
{
public:
FastLM();
~FastLM();
bool open(const char *path);
void close();
void dump();
virtual const vector<Bigram> bigramsForKeys(const string& preceedingKey, const string& key);
virtual const vector<Unigram> unigramsForKey(const string& key);
virtual bool hasUnigramsForKey(const string& key);
protected:
struct CStringCmp
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
struct Row {
const char *key;
const char *value;
const char *logProbability;
};
map<const char *, vector<Row>, CStringCmp> keyRowMap;
int fd;
void *data;
size_t length;
};
}
}
#endif

Binary file not shown.

View File

@ -12,7 +12,7 @@
#import <Foundation/Foundation.h> // @import Foundation; #import <Foundation/Foundation.h> // @import Foundation;
#import "SSZipArchive.h" // Zip Archive Support; #import "SSZipArchive.h" // Zip Archive Support;
@interface LanguageModelManager : NSObject @interface mgrLangModel : NSObject
+ (void)loadDataModels; + (void)loadDataModels;
+ (void)loadCNSData; + (void)loadCNSData;
+ (void)loadUserPhrases; + (void)loadUserPhrases;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -128,27 +128,27 @@ struct VersionUpdateApi {
} }
@objc(AppDelegate) @objc(AppDelegate)
class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControllerDelegate, FSEventStreamHelperDelegate { class AppDelegate: NSObject, NSApplicationDelegate, ctlNonModalAlertWindowDelegate, FSEventStreamHelperDelegate {
func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) { func helper(_ helper: FSEventStreamHelper, didReceive events: [FSEventStreamHelper.Event]) {
DispatchQueue.main.async { DispatchQueue.main.async {
if Preferences.shouldAutoReloadUserDataFiles { if Preferences.shouldAutoReloadUserDataFiles {
LanguageModelManager.loadUserPhrases() mgrLangModel.loadUserPhrases()
LanguageModelManager.loadUserPhraseReplacement() mgrLangModel.loadUserPhraseReplacement()
} }
} }
} }
@IBOutlet weak var window: NSWindow? @IBOutlet weak var window: NSWindow?
private var preferencesWindowController: PreferencesWindowController? private var ctlPrefWindowInstance: ctlPrefWindow?
private var aboutWindowController: frmAboutWindow? // New About Window private var ctlAboutWindowInstance: ctlAboutWindow? // New About Window
private var checkTask: URLSessionTask? private var checkTask: URLSessionTask?
private var updateNextStepURL: URL? private var updateNextStepURL: URL?
private var fsStreamHelper = FSEventStreamHelper(path: LanguageModelManager.dataFolderPath, queue: DispatchQueue(label: "User Phrases")) private var fsStreamHelper = FSEventStreamHelper(path: mgrLangModel.dataFolderPath, queue: DispatchQueue(label: "User Phrases"))
// dealloc // dealloc
deinit { deinit {
preferencesWindowController = nil ctlPrefWindowInstance = nil
aboutWindowController = nil ctlAboutWindowInstance = nil
checkTask = nil checkTask = nil
updateNextStepURL = nil updateNextStepURL = nil
fsStreamHelper.stop() fsStreamHelper.stop()
@ -156,10 +156,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
} }
func applicationDidFinishLaunching(_ notification: Notification) { func applicationDidFinishLaunching(_ notification: Notification) {
LanguageModelManager.loadDataModels() mgrLangModel.loadDataModels()
LanguageModelManager.loadCNSData() mgrLangModel.loadCNSData()
LanguageModelManager.loadUserPhrases() mgrLangModel.loadUserPhrases()
LanguageModelManager.loadUserPhraseReplacement() mgrLangModel.loadUserPhraseReplacement()
fsStreamHelper.delegate = self fsStreamHelper.delegate = self
_ = fsStreamHelper.start() _ = fsStreamHelper.start()
@ -172,20 +172,20 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
} }
@objc func showPreferences() { @objc func showPreferences() {
if (preferencesWindowController == nil) { if (ctlPrefWindowInstance == nil) {
preferencesWindowController = PreferencesWindowController(windowNibName: "preferences") ctlPrefWindowInstance = ctlPrefWindow.init(windowNibName: "frmPrefWindow")
} }
preferencesWindowController?.window?.center() ctlPrefWindowInstance?.window?.center()
preferencesWindowController?.window?.orderFrontRegardless() // ctlPrefWindowInstance?.window?.orderFrontRegardless() //
} }
// New About Window // New About Window
@objc func showAbout() { @objc func showAbout() {
if (aboutWindowController == nil) { if (ctlAboutWindowInstance == nil) {
aboutWindowController = frmAboutWindow.init(windowNibName: "frmAboutWindow") ctlAboutWindowInstance = ctlAboutWindow.init(windowNibName: "frmAboutWindow")
} }
aboutWindowController?.window?.center() ctlAboutWindowInstance?.window?.center()
aboutWindowController?.window?.orderFrontRegardless() // ctlAboutWindowInstance?.window?.orderFrontRegardless() //
} }
@objc(checkForUpdate) @objc(checkForUpdate)
@ -231,7 +231,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
report.remoteShortVersion, report.remoteShortVersion,
report.remoteVersion, report.remoteVersion,
report.versionDescription) report.versionDescription)
NonModalAlertWindowController.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self) ctlNonModalAlertWindow.shared.show(title: NSLocalizedString("New Version Available", comment: ""), content: content, confirmButtonTitle: NSLocalizedString("Visit Website", comment: ""), cancelButtonTitle: NSLocalizedString("Not Now", comment: ""), cancelAsDefault: false, delegate: self)
case .noNeedToUpdate, .ignored: case .noNeedToUpdate, .ignored:
break break
} }
@ -241,7 +241,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
let title = NSLocalizedString("Update Check Failed", comment: "") let title = NSLocalizedString("Update Check Failed", comment: "")
let content = String(format: NSLocalizedString("There may be no internet connection or the server failed to respond.\n\nError message: %@", comment: ""), message) let content = String(format: NSLocalizedString("There may be no internet connection or the server failed to respond.\n\nError message: %@", comment: ""), message)
let buttonTitle = NSLocalizedString("Dismiss", comment: "") let buttonTitle = NSLocalizedString("Dismiss", comment: "")
NonModalAlertWindowController.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil) ctlNonModalAlertWindow.shared.show(title: title, content: content, confirmButtonTitle: buttonTitle, cancelButtonTitle: nil, cancelAsDefault: false, delegate: nil)
default: default:
break break
} }
@ -249,14 +249,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, NonModalAlertWindowControlle
} }
} }
func nonModalAlertWindowControllerDidConfirm(_ controller: NonModalAlertWindowController) { func ctlNonModalAlertWindowDidConfirm(_ controller: ctlNonModalAlertWindow) {
if let updateNextStepURL = updateNextStepURL { if let updateNextStepURL = updateNextStepURL {
NSWorkspace.shared.open(updateNextStepURL) NSWorkspace.shared.open(updateNextStepURL)
} }
updateNextStepURL = nil updateNextStepURL = nil
} }
func nonModalAlertWindowControllerDidCancel(_ controller: NonModalAlertWindowController) { func ctlNonModalAlertWindowDidCancel(_ controller: ctlNonModalAlertWindow) {
updateNextStepURL = nil updateNextStepURL = nil
} }

View File

@ -10,7 +10,7 @@
#import "Gramambular.h" #import "Gramambular.h"
#import "vChewingLM.h" #import "vChewingLM.h"
#import "UserOverrideModel.h" #import "UserOverrideModel.h"
#import "LanguageModelManager.h" #import "mgrLangModel.h"
#import "KeyHandler.h" #import "KeyHandler.h"
#import "vChewing-Swift.h" #import "vChewing-Swift.h"
@ -87,12 +87,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
if ([value isKindOfClass:[NSString class]] && [value isEqual:kBopomofoModeIdentifierCHS]) { if ([value isKindOfClass:[NSString class]] && [value isEqual:kBopomofoModeIdentifierCHS]) {
newInputMode = kBopomofoModeIdentifierCHS; newInputMode = kBopomofoModeIdentifierCHS;
newLanguageModel = [LanguageModelManager languageModelCoreCHS]; newLanguageModel = [mgrLangModel languageModelCoreCHS];
newUserOverrideModel = [LanguageModelManager userOverrideModelCHS]; newUserOverrideModel = [mgrLangModel userOverrideModelCHS];
} else { } else {
newInputMode = kBopomofoModeIdentifierCHT; newInputMode = kBopomofoModeIdentifierCHT;
newLanguageModel = [LanguageModelManager languageModelCoreCHT]; newLanguageModel = [mgrLangModel languageModelCoreCHT];
newUserOverrideModel = [LanguageModelManager userOverrideModelCHT]; newUserOverrideModel = [mgrLangModel userOverrideModelCHT];
} }
// 自 Preferences 模組讀入自訂語彙置換功能開關狀態。 // 自 Preferences 模組讀入自訂語彙置換功能開關狀態。
@ -140,10 +140,10 @@ static NSString *const kGraphVizOutputfile = @"/tmp/vChewing-visualization.dot";
_bpmfReadingBuffer = new BopomofoReadingBuffer(BopomofoKeyboardLayout::StandardLayout()); _bpmfReadingBuffer = new BopomofoReadingBuffer(BopomofoKeyboardLayout::StandardLayout());
// create the lattice builder // create the lattice builder
_languageModel = [LanguageModelManager languageModelCoreCHT]; _languageModel = [mgrLangModel languageModelCoreCHT];
_languageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled); _languageModel->setPhraseReplacementEnabled(Preferences.phraseReplacementEnabled);
_languageModel->setCNSEnabled(Preferences.cns11643Enabled); _languageModel->setCNSEnabled(Preferences.cns11643Enabled);
_userOverrideModel = [LanguageModelManager userOverrideModelCHT]; _userOverrideModel = [mgrLangModel userOverrideModelCHT];
_builder = new BlockReadingBuilder(_languageModel); _builder = new BlockReadingBuilder(_languageModel);

View File

@ -1,5 +1,5 @@
/* /*
* InputMethodController.h * ctlInputMethod.h
* *
* Copyright 2021-2022 vChewing Project (3-Clause BSD License). * Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License). * Derived from 2011-2022 OpenVanilla Project (MIT License).
@ -10,6 +10,6 @@
#import <InputMethodKit/InputMethodKit.h> #import <InputMethodKit/InputMethodKit.h>
#import "vChewing-Swift.h" #import "vChewing-Swift.h"
@interface vChewingInputMethodController : IMKInputController @interface ctlInputMethod : IMKInputController
- (void)handleState:(InputState *)newState client:(id)client; - (void)handleState:(InputState *)newState client:(id)client;
@end @end

View File

@ -1,5 +1,5 @@
/* /*
* InputMethodController.mm * ctlInputMethod.mm
* *
* Copyright 2021-2022 vChewing Project (3-Clause BSD License). * Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License). * Derived from 2011-2022 OpenVanilla Project (MIT License).
@ -7,9 +7,9 @@
*/ */
#import "vChewingLM.h" #import "vChewingLM.h"
#import "InputMethodController.h" #import "ctlInputMethod.h"
#import "KeyHandler.h" #import "KeyHandler.h"
#import "LanguageModelManager.h" #import "mgrLangModel.h"
using namespace std; using namespace std;
using namespace vChewing; using namespace vChewing;
@ -23,7 +23,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
return s; return s;
} }
@interface vChewingInputMethodController () @interface ctlInputMethod ()
{ {
// the current text input client; we need to keep this when candidate panel is on // the current text input client; we need to keep this when candidate panel is on
id _currentCandidateClient; id _currentCandidateClient;
@ -36,13 +36,13 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
} }
@end @end
@interface vChewingInputMethodController (VTCandidateController) <VTCandidateControllerDelegate> @interface ctlInputMethod (VTCandidateController) <VTCandidateControllerDelegate>
@end @end
@interface vChewingInputMethodController (KeyHandlerDelegate) <KeyHandlerDelegate> @interface ctlInputMethod (KeyHandlerDelegate) <KeyHandlerDelegate>
@end @end
@interface vChewingInputMethodController (UI) @interface ctlInputMethod (UI)
+ (VTHorizontalCandidateController *)horizontalCandidateController; + (VTHorizontalCandidateController *)horizontalCandidateController;
+ (VTVerticalCandidateController *)verticalCandidateController; + (VTVerticalCandidateController *)verticalCandidateController;
+ (TooltipController *)tooltipController; + (TooltipController *)tooltipController;
@ -50,7 +50,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
- (void)_hideTooltip; - (void)_hideTooltip;
@end @end
@implementation vChewingInputMethodController @implementation ctlInputMethod
- (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client - (id)initWithServer:(IMKServer *)server delegate:(id)delegate client:(id)client
{ {
@ -398,11 +398,11 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
BOOL useVerticalMode = state.useVerticalMode; BOOL useVerticalMode = state.useVerticalMode;
if (useVerticalMode) { if (useVerticalMode) {
gCurrentCandidateController = [vChewingInputMethodController verticalCandidateController]; gCurrentCandidateController = [ctlInputMethod verticalCandidateController];
} else if (Preferences.useHorizontalCandidateList) { } else if (Preferences.useHorizontalCandidateList) {
gCurrentCandidateController = [vChewingInputMethodController horizontalCandidateController]; gCurrentCandidateController = [ctlInputMethod horizontalCandidateController];
} else { } else {
gCurrentCandidateController = [vChewingInputMethodController verticalCandidateController]; gCurrentCandidateController = [ctlInputMethod verticalCandidateController];
} }
// set the attributes for the candidate panel (which uses NSAttributedString) // set the attributes for the candidate panel (which uses NSAttributedString)
@ -495,19 +495,19 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
- (void)togglePhraseReplacementEnabled:(id)sender - (void)togglePhraseReplacementEnabled:(id)sender
{ {
if (_keyHandler.inputMode == kBopomofoModeIdentifierCHT){ if (_keyHandler.inputMode == kBopomofoModeIdentifierCHT){
[LanguageModelManager languageModelCoreCHT]->setPhraseReplacementEnabled([Preferences togglePhraseReplacementEnabled]); [mgrLangModel languageModelCoreCHT]->setPhraseReplacementEnabled([Preferences togglePhraseReplacementEnabled]);
} else { } else {
[LanguageModelManager languageModelCoreCHS]->setPhraseReplacementEnabled([Preferences togglePhraseReplacementEnabled]); [mgrLangModel languageModelCoreCHS]->setPhraseReplacementEnabled([Preferences togglePhraseReplacementEnabled]);
} }
} }
- (void)toggleCNS11643Enabled:(id)sender - (void)toggleCNS11643Enabled:(id)sender
{ {
if (_keyHandler.inputMode == kBopomofoModeIdentifierCHT){ if (_keyHandler.inputMode == kBopomofoModeIdentifierCHT){
[LanguageModelManager languageModelCoreCHT]->setCNSEnabled([Preferences toggleCNS11643Enabled]); [mgrLangModel languageModelCoreCHT]->setCNSEnabled([Preferences toggleCNS11643Enabled]);
} else { } else {
[LanguageModelManager languageModelCoreCHS]->setCNSEnabled([Preferences toggleCNS11643Enabled]); [mgrLangModel languageModelCoreCHS]->setCNSEnabled([Preferences toggleCNS11643Enabled]);
} }
// 注意上面這一行已經動過開關了,所以接下來就不要 toggle。 // 注意上面這一行已經動過開關了,所以接下來就不要 toggle。
[NotifierController notifyWithMessage:[NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"CNS11643 Mode", @""), @"\n", [Preferences cns11643Enabled] ? NSLocalizedString(@"NotificationSwitchON", @"") : NSLocalizedString(@"NotificationSwitchOFF", @"")] stay:NO]; [NotifierController notifyWithMessage:[NSString stringWithFormat:@"%@%@%@", NSLocalizedString(@"CNS11643 Mode", @""), @"\n", [Preferences cns11643Enabled] ? NSLocalizedString(@"NotificationSwitchON", @"") : NSLocalizedString(@"NotificationSwitchOFF", @"")] stay:NO];
@ -526,9 +526,9 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
- (BOOL)_checkUserFiles - (BOOL)_checkUserFiles
{ {
if (![LanguageModelManager checkIfUserLanguageModelFilesExist]) { if (![mgrLangModel checkIfUserLanguageModelFilesExist]) {
NSString *content = [NSString stringWithFormat:NSLocalizedString(@"Please check the permission of at \"%@\".", @""), [LanguageModelManager dataFolderPath]]; NSString *content = [NSString stringWithFormat:NSLocalizedString(@"Please check the permission of at \"%@\".", @""), [mgrLangModel dataFolderPath]];
[[NonModalAlertWindowController sharedInstance] showWithTitle:NSLocalizedString(@"Unable to create the user phrase file.", @"") content:content confirmButtonTitle:NSLocalizedString(@"OK", @"") cancelButtonTitle:nil cancelAsDefault:NO delegate:nil]; [[ctlNonModalAlertWindow sharedInstance] showWithTitle:NSLocalizedString(@"Unable to create the user phrase file.", @"") content:content confirmButtonTitle:NSLocalizedString(@"OK", @"") cancelButtonTitle:nil cancelAsDefault:NO delegate:nil];
return NO; return NO;
} }
@ -545,23 +545,23 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
- (void)openUserPhrases:(id)sender - (void)openUserPhrases:(id)sender
{ {
[self _openUserFile:[LanguageModelManager userPhrasesDataPath:_keyHandler.inputMode]]; [self _openUserFile:[mgrLangModel userPhrasesDataPath:_keyHandler.inputMode]];
} }
- (void)openExcludedPhrases:(id)sender - (void)openExcludedPhrases:(id)sender
{ {
[self _openUserFile:[LanguageModelManager excludedPhrasesDataPath:_keyHandler.inputMode]]; [self _openUserFile:[mgrLangModel excludedPhrasesDataPath:_keyHandler.inputMode]];
} }
- (void)openPhraseReplacement:(id)sender - (void)openPhraseReplacement:(id)sender
{ {
[self _openUserFile:[LanguageModelManager phraseReplacementDataPath:_keyHandler.inputMode]]; [self _openUserFile:[mgrLangModel phraseReplacementDataPath:_keyHandler.inputMode]];
} }
- (void)reloadUserPhrases:(id)sender - (void)reloadUserPhrases:(id)sender
{ {
[LanguageModelManager loadUserPhrases]; [mgrLangModel loadUserPhrases];
[LanguageModelManager loadUserPhraseReplacement]; [mgrLangModel loadUserPhraseReplacement];
} }
- (void)showAbout:(id)sender - (void)showAbout:(id)sender
@ -575,7 +575,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
#pragma mark - Voltaire #pragma mark - Voltaire
@implementation vChewingInputMethodController (VTCandidateController) @implementation ctlInputMethod (VTCandidateController)
- (NSUInteger)candidateCountForController:(VTCandidateController *)controller - (NSUInteger)candidateCountForController:(VTCandidateController *)controller
{ {
@ -623,7 +623,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
#pragma mark - Implementation #pragma mark - Implementation
@implementation vChewingInputMethodController (KeyHandlerDelegate) @implementation ctlInputMethod (KeyHandlerDelegate)
- (nonnull VTCandidateController *)candidateControllerForKeyHandler:(nonnull KeyHandler *)keyHandler - (nonnull VTCandidateController *)candidateControllerForKeyHandler:(nonnull KeyHandler *)keyHandler
{ {
@ -636,7 +636,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
return NO; return NO;
} }
NSString *userPhrase = state.userPhrase; NSString *userPhrase = state.userPhrase;
return [LanguageModelManager writeUserPhrase:userPhrase inputMode:_keyHandler.inputMode]; return [mgrLangModel writeUserPhrase:userPhrase inputMode:_keyHandler.inputMode];
return YES; return YES;
} }
@ -648,7 +648,7 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
@end @end
@implementation vChewingInputMethodController (UI) @implementation ctlInputMethod (UI)
+ (VTHorizontalCandidateController *)horizontalCandidateController + (VTHorizontalCandidateController *)horizontalCandidateController
{ {
@ -701,13 +701,13 @@ static inline NSString *LocalizationNotNeeded(NSString *s) {
NSLog(@"%@", exception); NSLog(@"%@", exception);
} }
[[vChewingInputMethodController tooltipController] showTooltip:tooltip atPoint:lineHeightRect.origin]; [[ctlInputMethod tooltipController] showTooltip:tooltip atPoint:lineHeightRect.origin];
} }
- (void)_hideTooltip - (void)_hideTooltip
{ {
if ([vChewingInputMethodController tooltipController].window.isVisible) { if ([ctlInputMethod tooltipController].window.isVisible) {
[[vChewingInputMethodController tooltipController] hide]; [[ctlInputMethod tooltipController] hide];
} }
} }

View File

@ -0,0 +1,64 @@
/*
* CoreLM.hh
*
* Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License).
* Some rights reserved. See "LICENSE.TXT" for details.
*/
#ifndef CoreLM_H
#define CoreLM_H
#include "LanguageModel.h"
#include <string>
#include <vector>
#include <map>
#include <iostream>
// this class relies on the fact that we have a space-separated data
// format, and we use mmap and zero-out the separators and line feeds
// to avoid creating new string objects; the parser is a simple DFA
using namespace std;
using namespace Taiyan::Gramambular;
namespace vChewing {
class CoreLM : public Taiyan::Gramambular::LanguageModel {
public:
CoreLM();
~CoreLM();
bool isLoaded();
bool open(const char *path);
void close();
void dump();
virtual const vector<Bigram> bigramsForKeys(const string& preceedingKey, const string& key);
virtual const vector<Unigram> unigramsForKey(const string& key);
virtual bool hasUnigramsForKey(const string& key);
protected:
struct CStringCmp
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
struct Row {
const char *key;
const char *value;
const char *logProbability;
};
map<const char *, vector<Row>, CStringCmp> keyRowMap;
int fd;
void *data;
size_t length;
};
}; // namespace vChewing
#endif

View File

@ -1,12 +1,12 @@
/* /*
* FastLM.mm * CoreLM.mm
* *
* Copyright 2021-2022 vChewing Project (3-Clause BSD License). * Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License). * Derived from 2011-2022 OpenVanilla Project (MIT License).
* Some rights reserved. See "LICENSE.TXT" for details. * Some rights reserved. See "LICENSE.TXT" for details.
*/ */
#include "FastLM.h" #include "CoreLM.h"
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -16,21 +16,29 @@
using namespace Taiyan::Gramambular; using namespace Taiyan::Gramambular;
FastLM::FastLM() vChewing::CoreLM::CoreLM()
: fd(-1) : fd(-1)
, data(0) , data(0)
, length(0) , length(0)
{ {
} }
FastLM::~FastLM() vChewing::CoreLM::~CoreLM()
{ {
if (data) { if (data) {
close(); close();
} }
} }
bool FastLM::open(const char *path) bool vChewing::CoreLM::isLoaded()
{
if (data) {
return true;
}
return false;
}
bool vChewing::CoreLM::open(const char *path)
{ {
if (data) { if (data) {
return false; return false;
@ -238,7 +246,7 @@ end:
return true; return true;
} }
void FastLM::close() void vChewing::CoreLM::close()
{ {
if (data) { if (data) {
munmap(data, length); munmap(data, length);
@ -249,7 +257,7 @@ void FastLM::close()
keyRowMap.clear(); keyRowMap.clear();
} }
void FastLM::dump() void vChewing::CoreLM::dump()
{ {
size_t rows = 0; size_t rows = 0;
for (map<const char *, vector<Row> >::const_iterator i = keyRowMap.begin(), e = keyRowMap.end(); i != e; ++i) { for (map<const char *, vector<Row> >::const_iterator i = keyRowMap.begin(), e = keyRowMap.end(); i != e; ++i) {
@ -262,12 +270,12 @@ void FastLM::dump()
} }
} }
const vector<Bigram> FastLM::bigramsForKeys(const string& preceedingKey, const string& key) const vector<Bigram> vChewing::CoreLM::bigramsForKeys(const string& preceedingKey, const string& key)
{ {
return vector<Bigram>(); return vector<Bigram>();
} }
const vector<Unigram> FastLM::unigramsForKey(const string& key) const vector<Unigram> vChewing::CoreLM::unigramsForKey(const string& key)
{ {
vector<Unigram> v; vector<Unigram> v;
map<const char *, vector<Row> >::const_iterator i = keyRowMap.find(key.c_str()); map<const char *, vector<Row> >::const_iterator i = keyRowMap.find(key.c_str());
@ -286,7 +294,7 @@ const vector<Unigram> FastLM::unigramsForKey(const string& key)
return v; return v;
} }
bool FastLM::hasUnigramsForKey(const string& key) bool vChewing::CoreLM::hasUnigramsForKey(const string& key)
{ {
return keyRowMap.find(key.c_str()) != keyRowMap.end(); return keyRowMap.find(key.c_str()) != keyRowMap.end();
} }

View File

@ -1,5 +1,5 @@
/* /*
* LanguageModelManager.h * mgrLangModel.h
* *
* Copyright 2021-2022 vChewing Project (3-Clause BSD License). * Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License). * Derived from 2011-2022 OpenVanilla Project (MIT License).
@ -7,7 +7,6 @@
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "FastLM.h"
#import "UserOverrideModel.h" #import "UserOverrideModel.h"
#import "vChewingLM.h" #import "vChewingLM.h"
#import "SSZipArchive.h" #import "SSZipArchive.h"
@ -15,7 +14,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface LanguageModelManager : NSObject @interface mgrLangModel : NSObject
+ (void)loadDataModels; + (void)loadDataModels;
+ (void)deployZipDataFile:(NSString *)filenameWithoutExtension; + (void)deployZipDataFile:(NSString *)filenameWithoutExtension;

View File

@ -1,12 +1,12 @@
/* /*
* LanguageModelManager.mm * mgrLangModel.mm
* *
* Copyright 2021-2022 vChewing Project (3-Clause BSD License). * Copyright 2021-2022 vChewing Project (3-Clause BSD License).
* Derived from 2011-2022 OpenVanilla Project (MIT License). * Derived from 2011-2022 OpenVanilla Project (MIT License).
* Some rights reserved. See "LICENSE.TXT" for details. * Some rights reserved. See "LICENSE.TXT" for details.
*/ */
#import "LanguageModelManager.h" #import "mgrLangModel.h"
using namespace std; using namespace std;
using namespace vChewing; using namespace vChewing;
@ -24,11 +24,11 @@ UserOverrideModel gUserOverrideModelCHT(kUserOverrideModelCapacity, kObservedOve
static NSString *const kBopomofoModeIdentifierCHT = @"org.atelierInmu.inputmethod.vChewing.TradBopomofo"; static NSString *const kBopomofoModeIdentifierCHT = @"org.atelierInmu.inputmethod.vChewing.TradBopomofo";
static NSString *const kBopomofoModeIdentifierCHS = @"org.atelierInmu.inputmethod.vChewing.SimpBopomofo"; static NSString *const kBopomofoModeIdentifierCHS = @"org.atelierInmu.inputmethod.vChewing.SimpBopomofo";
@implementation LanguageModelManager @implementation mgrLangModel
+ (void)deployZipDataFile:(NSString *)filenameWithoutExtension + (void)deployZipDataFile:(NSString *)filenameWithoutExtension
{ {
Class cls = NSClassFromString(@"vChewingInputMethodController"); Class cls = NSClassFromString(@"ctlInputMethod");
NSString *zipPath = [[NSBundle bundleForClass:cls] pathForResource:filenameWithoutExtension ofType:@"zip"]; NSString *zipPath = [[NSBundle bundleForClass:cls] pathForResource:filenameWithoutExtension ofType:@"zip"];
NSString *destinationPath = [self dataFolderPath]; NSString *destinationPath = [self dataFolderPath];
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath]; [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];
@ -39,7 +39,7 @@ static NSString *const kBopomofoModeIdentifierCHS = @"org.atelierInmu.inputmetho
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewingLM &lm) static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, vChewingLM &lm)
{ {
Class cls = NSClassFromString(@"vChewingInputMethodController"); Class cls = NSClassFromString(@"ctlInputMethod");
NSString *dataPath = [[NSBundle bundleForClass:cls] pathForResource:filenameWithoutExtension ofType:@"txt"]; NSString *dataPath = [[NSBundle bundleForClass:cls] pathForResource:filenameWithoutExtension ofType:@"txt"];
lm.loadLanguageModel([dataPath UTF8String]); lm.loadLanguageModel([dataPath UTF8String]);
} }

View File

@ -10,7 +10,7 @@
#define VCHEWINGLM_H #define VCHEWINGLM_H
#include <stdio.h> #include <stdio.h>
#include "FastLM.h" #include "CoreLM.h"
#include "CNSLM.h" #include "CNSLM.h"
#include "UserPhrasesLM.h" #include "UserPhrasesLM.h"
#include "PhraseReplacementMap.h" #include "PhraseReplacementMap.h"
@ -45,7 +45,7 @@ protected:
const std::unordered_set<string>& excludedValues, const std::unordered_set<string>& excludedValues,
std::unordered_set<string>& insertedValues); std::unordered_set<string>& insertedValues);
FastLM m_languageModel; CoreLM m_languageModel;
CNSLM m_cnsModel; CNSLM m_cnsModel;
UserPhrasesLM m_userPhrases; UserPhrasesLM m_userPhrases;
UserPhrasesLM m_excludedPhrases; UserPhrasesLM m_excludedPhrases;

BIN
Source/Resources/Beep.m4a Normal file

Binary file not shown.

BIN
Source/Resources/Fart.m4a Normal file

Binary file not shown.

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

Before

Width:  |  Height:  |  Size: 101 KiB

After

Width:  |  Height:  |  Size: 101 KiB

View File

Before

Width:  |  Height:  |  Size: 188 KiB

After

Width:  |  Height:  |  Size: 188 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 157 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 60 KiB

View File

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

View File

Before

Width:  |  Height:  |  Size: 139 KiB

After

Width:  |  Height:  |  Size: 139 KiB

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -1,6 +1,6 @@
CFBundleName = "威注音"; CFBundleName = "威注音";
CFBundleDisplayName = "威注音"; CFBundleDisplayName = "威注音";
NSHumanReadableCopyright = "© 2011-2022 OpenVanilla Project & © 2021-2022 vChewing Project."; NSHumanReadableCopyright = "© 2011-2022 OpenVanilla Project & © 2021-2022 vChewing Project.";
"org.atelierInmu.inputmethod.vChewing.TradBopomofo" = "威註音"; "org.atelierInmu.inputmethod.vChewing.TradBopomofo" = "威注音-繁";
"org.atelierInmu.inputmethod.vChewing.SimpBopomofo" = "威注音"; "org.atelierInmu.inputmethod.vChewing.SimpBopomofo" = "威注音-简";
CFEULAContent = "该授权条款,在使用者符合以下诸条件之情形下,授予使用者使用及再散播本软件套件装原始码及二进位可执行形式之权利,无论此包装是否经改作皆然:\n\n对于本软件原始码之再散播必须保留上述之著作权宣告、此诸条件表列以及下述之免责声明。\n对于本套件二进位可执行形式之再散播必须连带以档案以及或者其他附于散播包装中之媒介方式重制上述之著作权宣告、此诸条件表列以及下述之免责声明。\n未获事前取得书面授权不得使用威注音或本软件贡献者之名称来为本软件之衍生物做任何表示支援、认可或推广、促销之行为。\n\n免责声明本软件由威注音及本软件之贡献者以现状「as is」提供本软件套件装不负任何明示或默示之担保责任包括但不限于就适售性以及特定目之之适用性为默示性担保。威注音及本软件之贡献者无论任何条件、无论成因或任何责任主义、无论此责任为因合约关系、无过失责任主义或因非违约之侵权包括过失或其他原因等而起对于任何因使用本软件套件装所产生之任何直接性、间接性、偶发性、特殊性、惩罚性或任何结果之损害包括但不限于替代商品或劳务之购用、使用损失、资料损失、利益损失、业务中断等等不负任何责任即在该种使用已获事前告知可能会造成此类损害之情形下亦然。\n"; CFEULAContent = "该授权条款,在使用者符合以下诸条件之情形下,授予使用者使用及再散播本软件套件装原始码及二进位可执行形式之权利,无论此包装是否经改作皆然:\n\n对于本软件原始码之再散播必须保留上述之著作权宣告、此诸条件表列以及下述之免责声明。\n对于本套件二进位可执行形式之再散播必须连带以档案以及或者其他附于散播包装中之媒介方式重制上述之著作权宣告、此诸条件表列以及下述之免责声明。\n未获事前取得书面授权不得使用威注音或本软件贡献者之名称来为本软件之衍生物做任何表示支援、认可或推广、促销之行为。\n\n免责声明本软件由威注音及本软件之贡献者以现状「as is」提供本软件套件装不负任何明示或默示之担保责任包括但不限于就适售性以及特定目之之适用性为默示性担保。威注音及本软件之贡献者无论任何条件、无论成因或任何责任主义、无论此责任为因合约关系、无过失责任主义或因非违约之侵权包括过失或其他原因等而起对于任何因使用本软件套件装所产生之任何直接性、间接性、偶发性、特殊性、惩罚性或任何结果之损害包括但不限于替代商品或劳务之购用、使用损失、资料损失、利益损失、业务中断等等不负任何责任即在该种使用已获事前告知可能会造成此类损害之情形下亦然。\n";

Some files were not shown because too many files have changed in this diff Show More