Skip to content

Commit 8d4236f

Browse files
tianjianjiangclaude
andcommitted
feat: integrate contextual user model into KeyHandler
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cbb3870 commit 8d4236f

5 files changed

Lines changed: 330 additions & 192 deletions

File tree

McBopomofo.xcodeproj/project.pbxproj

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
6A2E40F9253A6AA000D1AE1D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6A2E40F5253A69DA00D1AE1D /* Images.xcassets */; };
1818
6A38BC1515FC117A00A8A51F /* data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A38BBF615FC117A00A8A51F /* data.txt */; };
1919
6A4F5F982879E838008C4307 /* reading_grid.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A4F5F932879E838008C4307 /* reading_grid.cpp */; };
20+
A71A7066B7F904D314C65992 /* contextual_user_model.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C960E407C381A6E5F4100F2 /* contextual_user_model.cpp */; };
21+
9BFBCAEED2ED8369BC7D6ED5 /* walk_strategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9CBDA16D485EE2E7F11D171B /* walk_strategy.cpp */; };
2022
6A660A702EAF371000D53D7B /* ByteBlockBackedDictionary.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6A660A6F2EAF371000D53D7B /* ByteBlockBackedDictionary.cpp */; };
21-
6A68C1C32EC7F2C0005284A0 /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */; };
2223
6A6ED16B2797650A0012872E /* template-phrases-replacement.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1632797650A0012872E /* template-phrases-replacement.txt */; };
2324
6A6ED16C2797650A0012872E /* template-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1652797650A0012872E /* template-data.txt */; };
2425
6A6ED16D2797650A0012872E /* template-exclude-phrases-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */; };
@@ -53,7 +54,6 @@
5354
D427F7B4279086DC004A2160 /* InputSourceHelper in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7B3279086DC004A2160 /* InputSourceHelper */; };
5455
D427F7B6279086F6004A2160 /* InputSourceHelper in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7B5279086F6004A2160 /* InputSourceHelper */; };
5556
D427F7C127908EFC004A2160 /* OpenCCBridge in Frameworks */ = {isa = PBXBuildFile; productRef = D427F7C027908EFC004A2160 /* OpenCCBridge */; };
56-
D4314F0D2ED3690F0071DD71 /* NumberInputHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4314F0C2ED369090071DD71 /* NumberInputHelper.swift */; };
5757
D436E23F2CD20BA700C6155D /* AssociatedPhrasesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D436E23E2CD20B9E00C6155D /* AssociatedPhrasesTests.swift */; };
5858
D43737C92DF9C35800D9707C /* InputMethodController+KeyHandlerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43737C82DF9C35100D9707C /* InputMethodController+KeyHandlerDelegate.swift */; };
5959
D43737CB2DF9C48300D9707C /* InputMethodController+CandidateControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D43737CA2DF9C48200D9707C /* InputMethodController+CandidateControllerDelegate.swift */; };
@@ -140,10 +140,12 @@
140140
6A4F5F912879E838008C4307 /* reading_grid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reading_grid.h; sourceTree = "<group>"; };
141141
6A4F5F922879E838008C4307 /* language_model.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = language_model.h; sourceTree = "<group>"; };
142142
6A4F5F932879E838008C4307 /* reading_grid.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = reading_grid.cpp; sourceTree = "<group>"; };
143+
B590C82EAD5C575FFC76F863 /* contextual_user_model.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = contextual_user_model.h; sourceTree = "<group>"; };
144+
4C960E407C381A6E5F4100F2 /* contextual_user_model.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = contextual_user_model.cpp; sourceTree = "<group>"; };
145+
1B900C269506F40A48314006 /* walk_strategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = walk_strategy.h; sourceTree = "<group>"; };
146+
9CBDA16D485EE2E7F11D171B /* walk_strategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = walk_strategy.cpp; sourceTree = "<group>"; };
143147
6A660A6E2EAF371000D53D7B /* ByteBlockBackedDictionary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ByteBlockBackedDictionary.h; sourceTree = "<group>"; };
144148
6A660A6F2EAF371000D53D7B /* ByteBlockBackedDictionary.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ByteBlockBackedDictionary.cpp; sourceTree = "<group>"; };
145-
6A68C1C22EC7F2C0005284A0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = en; path = en.lproj/Localizable.stringsdict; sourceTree = "<group>"; };
146-
6A68C1C42EC7F6B7005284A0 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = "zh-Hant"; path = "zh-Hant.lproj/Localizable.stringsdict"; sourceTree = "<group>"; };
147149
6A6ED1642797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-phrases-replacement.txt"; sourceTree = "<group>"; };
148150
6A6ED1662797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-data.txt"; sourceTree = "<group>"; };
149151
6A6ED1682797650A0012872E /* Base */ = {isa = PBXFileReference; lastKnownFileType = text; name = Base; path = "Base.lproj/template-exclude-phrases-plain-bpmf.txt"; sourceTree = "<group>"; };
@@ -199,7 +201,6 @@
199201
D427F7AC27907B7E004A2160 /* NotifierUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = NotifierUI; path = Packages/NotifierUI; sourceTree = "<group>"; };
200202
D427F7B2279086B5004A2160 /* InputSourceHelper */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = InputSourceHelper; path = Packages/InputSourceHelper; sourceTree = "<group>"; };
201203
D427F7BF27908EAC004A2160 /* OpenCCBridge */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = OpenCCBridge; path = Packages/OpenCCBridge; sourceTree = "<group>"; };
202-
D4314F0C2ED369090071DD71 /* NumberInputHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NumberInputHelper.swift; sourceTree = "<group>"; };
203204
D436E23E2CD20B9E00C6155D /* AssociatedPhrasesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssociatedPhrasesTests.swift; sourceTree = "<group>"; };
204205
D43737C82DF9C35100D9707C /* InputMethodController+KeyHandlerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputMethodController+KeyHandlerDelegate.swift"; sourceTree = "<group>"; };
205206
D43737CA2DF9C48200D9707C /* InputMethodController+CandidateControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "InputMethodController+CandidateControllerDelegate.swift"; sourceTree = "<group>"; };
@@ -330,7 +331,6 @@
330331
D4CB1A5A2B3891FB006EA984 /* DictionaryService.swift */,
331332
D456576D279E4F7B00DF6BC9 /* KeyHandlerInput.swift */,
332333
D461B791279DAC010070E734 /* InputState.swift */,
333-
D4314F0C2ED369090071DD71 /* NumberInputHelper.swift */,
334334
D427F76B278CA1BA004A2160 /* AppDelegate.swift */,
335335
D44FB74427915555003C80A6 /* Preferences.swift */,
336336
D47F7DCF278C0897002F9DD7 /* NonModalAlertWindowController.swift */,
@@ -430,6 +430,10 @@
430430
6A4F5F912879E838008C4307 /* reading_grid.h */,
431431
6A4F5F922879E838008C4307 /* language_model.h */,
432432
6A4F5F932879E838008C4307 /* reading_grid.cpp */,
433+
B590C82EAD5C575FFC76F863 /* contextual_user_model.h */,
434+
4C960E407C381A6E5F4100F2 /* contextual_user_model.cpp */,
435+
1B900C269506F40A48314006 /* walk_strategy.h */,
436+
9CBDA16D485EE2E7F11D171B /* walk_strategy.cpp */,
433437
);
434438
path = gramambular2;
435439
sourceTree = "<group>";
@@ -461,7 +465,6 @@
461465
6A93050C279877FF00D370DA /* McBopomofoInstaller-Bridging-Header.h */,
462466
D4F0BBE2279B08900071253C /* BundleTranslocate.h */,
463467
D4F0BBE3279B08900071253C /* BundleTranslocate.m */,
464-
6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */,
465468
);
466469
path = Installer;
467470
sourceTree = "<group>";
@@ -687,7 +690,6 @@
687690
6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */,
688691
6A225A1F23679F2600F685C6 /* NotarizedArchives in Resources */,
689692
6ACA41FB15FC1D9000935EF6 /* License.rtf in Resources */,
690-
6A68C1C32EC7F2C0005284A0 /* Localizable.stringsdict in Resources */,
691693
6ACA41FC15FC1D9000935EF6 /* Localizable.strings in Resources */,
692694
6ACA41FD15FC1D9000935EF6 /* MainMenu.xib in Resources */,
693695
);
@@ -742,9 +744,10 @@
742744
D4A13D5A27A59F0B003BE359 /* InputMethodController.swift in Sources */,
743745
D44FB74527915565003C80A6 /* Preferences.swift in Sources */,
744746
6A660A702EAF371000D53D7B /* ByteBlockBackedDictionary.cpp in Sources */,
745-
D4314F0D2ED3690F0071DD71 /* NumberInputHelper.swift in Sources */,
746747
D4E569DC27A34D0E00AC2CEF /* KeyHandler.mm in Sources */,
747748
6A4F5F982879E838008C4307 /* reading_grid.cpp in Sources */,
749+
A71A7066B7F904D314C65992 /* contextual_user_model.cpp in Sources */,
750+
9BFBCAEED2ED8369BC7D6ED5 /* walk_strategy.cpp in Sources */,
748751
D47F7DD0278C0897002F9DD7 /* NonModalAlertWindowController.swift in Sources */,
749752
D456576E279E4F7B00DF6BC9 /* KeyHandlerInput.swift in Sources */,
750753
D47F7DCE278BFB57002F9DD7 /* PreferencesWindowController.swift in Sources */,
@@ -830,15 +833,6 @@
830833
name = MainMenu.xib;
831834
sourceTree = "<group>";
832835
};
833-
6A68C1C12EC7F2C0005284A0 /* Localizable.stringsdict */ = {
834-
isa = PBXVariantGroup;
835-
children = (
836-
6A68C1C22EC7F2C0005284A0 /* en */,
837-
6A68C1C42EC7F6B7005284A0 /* zh-Hant */,
838-
);
839-
name = Localizable.stringsdict;
840-
sourceTree = "<group>";
841-
};
842836
6A6ED1632797650A0012872E /* template-phrases-replacement.txt */ = {
843837
isa = PBXVariantGroup;
844838
children = (
@@ -1098,7 +1092,7 @@
10981092
"$(inherited)",
10991093
"@executable_path/../Frameworks",
11001094
);
1101-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1095+
MACOSX_DEPLOYMENT_TARGET = 10.15;
11021096
ONLY_ACTIVE_ARCH = YES;
11031097
PRODUCT_BUNDLE_IDENTIFIER = org.openvanilla.inputmethod.McBopomofo;
11041098
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1153,7 +1147,7 @@
11531147
"$(inherited)",
11541148
"@executable_path/../Frameworks",
11551149
);
1156-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1150+
MACOSX_DEPLOYMENT_TARGET = 10.15;
11571151
PRODUCT_BUNDLE_IDENTIFIER = org.openvanilla.inputmethod.McBopomofo;
11581152
PRODUCT_NAME = "$(TARGET_NAME)";
11591153
SDKROOT = macosx;
@@ -1188,7 +1182,7 @@
11881182
GCC_WARN_ABOUT_RETURN_TYPE = YES;
11891183
GCC_WARN_UNINITIALIZED_AUTOS = YES;
11901184
GCC_WARN_UNUSED_VARIABLE = YES;
1191-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1185+
MACOSX_DEPLOYMENT_TARGET = 10.13;
11921186
ONLY_ACTIVE_ARCH = YES;
11931187
OTHER_CFLAGS = "";
11941188
OTHER_LDFLAGS = "";
@@ -1214,7 +1208,7 @@
12141208
GCC_WARN_ABOUT_RETURN_TYPE = YES;
12151209
GCC_WARN_UNINITIALIZED_AUTOS = YES;
12161210
GCC_WARN_UNUSED_VARIABLE = YES;
1217-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1211+
MACOSX_DEPLOYMENT_TARGET = 10.13;
12181212
OTHER_CFLAGS = "";
12191213
OTHER_LDFLAGS = "";
12201214
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1258,7 +1252,7 @@
12581252
"$(inherited)",
12591253
"@executable_path/../Frameworks",
12601254
);
1261-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1255+
MACOSX_DEPLOYMENT_TARGET = 10.15;
12621256
ONLY_ACTIVE_ARCH = YES;
12631257
PRODUCT_BUNDLE_IDENTIFIER = "org.openvanilla.McBopomofo.${PRODUCT_NAME:rfc1034identifier}";
12641258
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -1300,7 +1294,7 @@
13001294
"$(inherited)",
13011295
"@executable_path/../Frameworks",
13021296
);
1303-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1297+
MACOSX_DEPLOYMENT_TARGET = 10.15;
13041298
PRODUCT_BUNDLE_IDENTIFIER = "org.openvanilla.McBopomofo.${PRODUCT_NAME:rfc1034identifier}";
13051299
PRODUCT_NAME = "$(TARGET_NAME)";
13061300
SDKROOT = macosx;
@@ -1346,7 +1340,7 @@
13461340
"@executable_path/../Frameworks",
13471341
"@loader_path/../Frameworks",
13481342
);
1349-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1343+
MACOSX_DEPLOYMENT_TARGET = 10.15;
13501344
MARKETING_VERSION = 1.0;
13511345
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
13521346
MTL_FAST_MATH = YES;
@@ -1393,7 +1387,7 @@
13931387
"@executable_path/../Frameworks",
13941388
"@loader_path/../Frameworks",
13951389
);
1396-
MACOSX_DEPLOYMENT_TARGET = 11.0;
1390+
MACOSX_DEPLOYMENT_TARGET = 10.15;
13971391
MARKETING_VERSION = 1.0;
13981392
MTL_ENABLE_DEBUG_INFO = NO;
13991393
MTL_FAST_MATH = YES;

Source/Engine/gramambular2/reading_grid_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,38 @@ TEST(FixedSpanTest, ChainedOverrides) {
970970
<< " us\n";
971971
}
972972

973+
TEST(FixedSpanTest, ClearAlsoResetsFixedSpans) {
974+
ReadingGrid grid(std::make_shared<SimpleLM>(kSampleData));
975+
grid.setReadingSeparator("");
976+
std::vector<std::string> readings = {"ㄍㄠ", "ㄎㄜ", "ㄐㄧˋ",
977+
"ㄍㄨㄥ", "", "ㄉㄜ˙",
978+
"ㄋㄧㄢˊ", "ㄓㄨㄥ", "ㄐㄧㄤˇ",
979+
"ㄐㄧㄣ"};
980+
for (const auto& r : readings) {
981+
grid.insertReading(r);
982+
}
983+
984+
auto nzNode = grid.spans()[6].nodeOf(2);
985+
nzNode->selectOverrideUnigram(
986+
"年終", ReadingGrid::Node::OverrideType::kOverrideValueWithHighScore);
987+
grid.fixSpan(6, nzNode);
988+
auto result = grid.walk();
989+
bool hasNianzhong = false;
990+
for (const auto& v : result.valuesAsStrings()) {
991+
if (v == "年終") hasNianzhong = true;
992+
}
993+
ASSERT_TRUE(hasNianzhong);
994+
995+
grid.clear();
996+
997+
for (const auto& r : readings) {
998+
grid.insertReading(r);
999+
}
1000+
result = grid.walk();
1001+
ASSERT_EQ(result.valuesAsStrings(),
1002+
(std::vector<std::string>{"高科技", "公司", "", "年中", "獎金"}));
1003+
}
1004+
9731005
// Phase 0B Tests: Algorithm Comparison
9741006

9751007
TEST(AlgorithmComparisonTest, Basic10Syllables) {

0 commit comments

Comments
 (0)