Use the new LM class.

This commit is contained in:
Lukhnos Liu 2012-09-10 22:56:21 -07:00
parent 67775e3ccf
commit 08e7b14f3e
3 changed files with 16 additions and 30 deletions

View File

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A0421A615FEF3F50061ED63 /* FastLM.cpp */; };
6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; }; 6A0D4EA715FC0D2D00ABF4B3 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; };
6A0D4ED015FC0D6400ABF4B3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC415FC0D6400ABF4B3 /* AppDelegate.m */; }; 6A0D4ED015FC0D6400ABF4B3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC415FC0D6400ABF4B3 /* AppDelegate.m */; };
6A0D4ED215FC0D6400ABF4B3 /* InputMethodController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC715FC0D6400ABF4B3 /* InputMethodController.mm */; }; 6A0D4ED215FC0D6400ABF4B3 /* InputMethodController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC715FC0D6400ABF4B3 /* InputMethodController.mm */; };
@ -68,6 +69,8 @@
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
6A0421A615FEF3F50061ED63 /* FastLM.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FastLM.cpp; sourceTree = "<group>"; };
6A0421A715FEF3F50061ED63 /* FastLM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastLM.h; sourceTree = "<group>"; };
6A0D4EA215FC0D2D00ABF4B3 /* McBopomofo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6A0D4EA215FC0D2D00ABF4B3 /* McBopomofo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofo.app; sourceTree = BUILT_PRODUCTS_DIR; };
6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
6A0D4EA915FC0D2D00ABF4B3 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; 6A0D4EA915FC0D2D00ABF4B3 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@ -330,6 +333,8 @@
6A0D4F2215FC0EB100ABF4B3 /* OpenVanilla */, 6A0D4F2215FC0EB100ABF4B3 /* OpenVanilla */,
6A0D4F4315FC0EB100ABF4B3 /* SimpleLM.cpp */, 6A0D4F4315FC0EB100ABF4B3 /* SimpleLM.cpp */,
6A0D4F4415FC0EB100ABF4B3 /* SimpleLM.h */, 6A0D4F4415FC0EB100ABF4B3 /* SimpleLM.h */,
6A0421A615FEF3F50061ED63 /* FastLM.cpp */,
6A0421A715FEF3F50061ED63 /* FastLM.h */,
); );
name = Engine; name = Engine;
path = Source/Engine; path = Source/Engine;
@ -606,7 +611,7 @@
/* Begin PBXShellScriptBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */
6AE306DD15FC18BB00C264C8 /* Run Script (Install Input Method When Under Debug Configuration) */ = { 6AE306DD15FC18BB00C264C8 /* Run Script (Install Input Method When Under Debug Configuration) */ = {
isa = PBXShellScriptBuildPhase; isa = PBXShellScriptBuildPhase;
buildActionMask = 12; buildActionMask = 8;
files = ( files = (
); );
inputPaths = ( inputPaths = (
@ -614,7 +619,7 @@
name = "Run Script (Install Input Method When Under Debug Configuration)"; name = "Run Script (Install Input Method When Under Debug Configuration)";
outputPaths = ( outputPaths = (
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 1;
shellPath = /bin/sh; shellPath = /bin/sh;
shellScript = "FROM=\"$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME\"\nPREVIOUS=\"$HOME/Library/Input Methods/$FULL_PRODUCT_NAME\"\nTO=\"$HOME/Library/Input Methods/\"\nEXE=\"$HOME/Library/Input Methods/$EXECUTABLE_FOLDER_PATH/$EXECUTABLE_NAME\"\n\nif [ $CONFIGURATION = \"Debug\" ]\nthen\n echo Stopping $PRODUCT_NAME\n killall \"$PRODUCT_NAME\"\n\n echo Removing the installed version at $PREVIOUS\n rm -rf \"$PREVIOUS\"\n\n echo Copying built product from $FROM to $TO\n cp -R \"$FROM\" \"$TO\"\n\n echo Invoking $EXE to activate $PRODUCT_NAME\n \"$EXE\" install\n\n echo Restarting SystemUIServer to reflect icon changes\n killall SystemUIServer\nfi\n"; shellScript = "FROM=\"$BUILT_PRODUCTS_DIR/$FULL_PRODUCT_NAME\"\nPREVIOUS=\"$HOME/Library/Input Methods/$FULL_PRODUCT_NAME\"\nTO=\"$HOME/Library/Input Methods/\"\nEXE=\"$HOME/Library/Input Methods/$EXECUTABLE_FOLDER_PATH/$EXECUTABLE_NAME\"\n\nif [ $CONFIGURATION = \"Debug\" ]\nthen\n echo Stopping $PRODUCT_NAME\n killall \"$PRODUCT_NAME\"\n\n echo Removing the installed version at $PREVIOUS\n rm -rf \"$PREVIOUS\"\n\n echo Copying built product from $FROM to $TO\n cp -R \"$FROM\" \"$TO\"\n\n echo Invoking $EXE to activate $PRODUCT_NAME\n \"$EXE\" install\n\n echo Restarting SystemUIServer to reflect icon changes\n killall SystemUIServer\nfi\n";
}; };
@ -639,6 +644,7 @@
6A0D4F0315FC0DA600ABF4B3 /* VTVerticalKeyLabelStripView.m in Sources */, 6A0D4F0315FC0DA600ABF4B3 /* VTVerticalKeyLabelStripView.m in Sources */,
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */, 6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
6A0D4F4615FC0EB100ABF4B3 /* SimpleLM.cpp in Sources */, 6A0D4F4615FC0EB100ABF4B3 /* SimpleLM.cpp in Sources */,
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -37,6 +37,7 @@
#import "Mandarin.h" #import "Mandarin.h"
#import "Gramambular.h" #import "Gramambular.h"
#import "SimpleLM.h" #import "SimpleLM.h"
#import "FastLM.h"
@interface McBopomofoInputMethodController : IMKInputController @interface McBopomofoInputMethodController : IMKInputController
{ {
@ -45,7 +46,7 @@
Formosa::Mandarin::BopomofoReadingBuffer* _bpmfReadingBuffer; Formosa::Mandarin::BopomofoReadingBuffer* _bpmfReadingBuffer;
// language model // language model
Formosa::Gramambular::SimpleLM *_languageModel; Formosa::Gramambular::FastLM *_languageModel;
// the grid (lattice) builder for the unigrams (and bigrams) // the grid (lattice) builder for the unigrams (and bigrams)
Formosa::Gramambular::BlockReadingBuilder* _builder; Formosa::Gramambular::BlockReadingBuilder* _builder;

View File

@ -107,8 +107,8 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
#endif #endif
// shared language model object that stores our phrase-term probability database // shared language model object that stores our phrase-term probability database
SimpleLM gLanguageModel; FastLM gLanguageModel;
SimpleLM gLanguageModelPlainBopomofo; FastLM gLanguageModelPlainBopomofo;
// private methods // private methods
@interface McBopomofoInputMethodController () <VTCandidateControllerDelegate> @interface McBopomofoInputMethodController () <VTCandidateControllerDelegate>
@ -1317,34 +1317,13 @@ public:
@end @end
static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, SimpleLM &lm) static void LTLoadLanguageModelFile(NSString *filenameWithoutExtension, FastLM &lm)
{ {
// load the language model; the performance of this function can be greatly improved
// with better loading/parsing methods
NSDate *__unused startTime = [NSDate date];
NSString *dataPath = [[NSBundle bundleForClass:[McBopomofoInputMethodController class]] pathForResource:filenameWithoutExtension ofType:@"txt"]; NSString *dataPath = [[NSBundle bundleForClass:[McBopomofoInputMethodController class]] pathForResource:filenameWithoutExtension ofType:@"txt"];
bool result = lm.open([dataPath UTF8String]);
ifstream ifs; if (!result) {
ifs.open([dataPath UTF8String]); NSLog(@"Failed opening language model: %@", dataPath);
while (ifs.good()) {
string line;
getline(ifs, line);
if (!line.size() || (line.size() && line[0] == '#')) {
continue;
} }
vector<string> p = OVStringHelper::SplitBySpacesOrTabs(line);
if (p.size() == 3) {
lm.add(p[1], p[0], atof(p[2].c_str()));
}
}
ifs.close();
// insert an empty entry for BOS/EOS markers
lm.add(" ", " ", 0.0);
} }