Use the new LM class.
This commit is contained in:
parent
67775e3ccf
commit
08e7b14f3e
|
@ -7,6 +7,7 @@
|
|||
objects = {
|
||||
|
||||
/* 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 */; };
|
||||
6A0D4ED015FC0D6400ABF4B3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC415FC0D6400ABF4B3 /* AppDelegate.m */; };
|
||||
6A0D4ED215FC0D6400ABF4B3 /* InputMethodController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6A0D4EC715FC0D6400ABF4B3 /* InputMethodController.mm */; };
|
||||
|
@ -68,6 +69,8 @@
|
|||
/* End PBXContainerItemProxy 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; };
|
||||
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; };
|
||||
|
@ -330,6 +333,8 @@
|
|||
6A0D4F2215FC0EB100ABF4B3 /* OpenVanilla */,
|
||||
6A0D4F4315FC0EB100ABF4B3 /* SimpleLM.cpp */,
|
||||
6A0D4F4415FC0EB100ABF4B3 /* SimpleLM.h */,
|
||||
6A0421A615FEF3F50061ED63 /* FastLM.cpp */,
|
||||
6A0421A715FEF3F50061ED63 /* FastLM.h */,
|
||||
);
|
||||
name = Engine;
|
||||
path = Source/Engine;
|
||||
|
@ -606,7 +611,7 @@
|
|||
/* Begin PBXShellScriptBuildPhase section */
|
||||
6AE306DD15FC18BB00C264C8 /* Run Script (Install Input Method When Under Debug Configuration) */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 12;
|
||||
buildActionMask = 8;
|
||||
files = (
|
||||
);
|
||||
inputPaths = (
|
||||
|
@ -614,7 +619,7 @@
|
|||
name = "Run Script (Install Input Method When Under Debug Configuration)";
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
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";
|
||||
};
|
||||
|
@ -639,6 +644,7 @@
|
|||
6A0D4F0315FC0DA600ABF4B3 /* VTVerticalKeyLabelStripView.m in Sources */,
|
||||
6A0D4F4515FC0EB100ABF4B3 /* Mandarin.cpp in Sources */,
|
||||
6A0D4F4615FC0EB100ABF4B3 /* SimpleLM.cpp in Sources */,
|
||||
6A0421A815FEF3F50061ED63 /* FastLM.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#import "Mandarin.h"
|
||||
#import "Gramambular.h"
|
||||
#import "SimpleLM.h"
|
||||
#import "FastLM.h"
|
||||
|
||||
@interface McBopomofoInputMethodController : IMKInputController
|
||||
{
|
||||
|
@ -45,7 +46,7 @@
|
|||
Formosa::Mandarin::BopomofoReadingBuffer* _bpmfReadingBuffer;
|
||||
|
||||
// language model
|
||||
Formosa::Gramambular::SimpleLM *_languageModel;
|
||||
Formosa::Gramambular::FastLM *_languageModel;
|
||||
|
||||
// the grid (lattice) builder for the unigrams (and bigrams)
|
||||
Formosa::Gramambular::BlockReadingBuilder* _builder;
|
||||
|
|
|
@ -107,8 +107,8 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
|
|||
#endif
|
||||
|
||||
// shared language model object that stores our phrase-term probability database
|
||||
SimpleLM gLanguageModel;
|
||||
SimpleLM gLanguageModelPlainBopomofo;
|
||||
FastLM gLanguageModel;
|
||||
FastLM gLanguageModelPlainBopomofo;
|
||||
|
||||
// private methods
|
||||
@interface McBopomofoInputMethodController () <VTCandidateControllerDelegate>
|
||||
|
@ -1317,34 +1317,13 @@ public:
|
|||
|
||||
@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"];
|
||||
|
||||
ifstream ifs;
|
||||
ifs.open([dataPath UTF8String]);
|
||||
while (ifs.good()) {
|
||||
string line;
|
||||
getline(ifs, line);
|
||||
|
||||
if (!line.size() || (line.size() && line[0] == '#')) {
|
||||
continue;
|
||||
bool result = lm.open([dataPath UTF8String]);
|
||||
if (!result) {
|
||||
NSLog(@"Failed opening language model: %@", dataPath);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue