{"record":{"id":"af35e04687ae847e","repo":"studyzy/imewlconverter","slug":"c","errorCode":null,"errorMessage":"给定关键字不在字典中，【{c}】","messagePattern":"给定关键字不在字典中，【(.+?)】","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/ImeWlConverter.Core/Helpers/DictionaryHelper.cs","lineNumber":48,"sourceCode":"                            Wubi86: hzpy[2],\n                            Wubi98: hzpy[3],\n                            WubiNewAge: hzpy[4],\n                            Pinyins: hzpy[5],\n                            Freq: Convert.ToDouble(hzpy[6])\n                        )\n                    );\n                }\n            }\n\n            return dictionary;\n        }\n    }\n\n    public static ChineseCode GetCode(char c)\n    {\n        if (Dict.TryGetValue(c, out var code))\n            return code;\n        throw new Exception(\"给定关键字不在字典中，【\" + c + \"】\");\n    }\n\n    public static List<ChineseCode> GetAll()\n    {\n        return new List<ChineseCode>(Dict.Values);\n    }\n\n    public static string GetResourceContent(string fileName)\n    {\n        var assembly = typeof(DictionaryHelper).Assembly;\n\n        using var stream = assembly.GetManifestResourceStream(\n            \"ImeWlConverter.Core.Resources.\" + fileName\n        );\n        if (stream == null)\n            throw new InvalidOperationException($\"Embedded resource not found: {fileName}\");\n\n        using var reader = new StreamReader(stream, detectEncodingFromByteOrderMarks: true);","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/studyzy/imewlconverter/blob/16744a12ed5064896cf39095163e44b367aaada1/src/ImeWlConverter.Core/Helpers/DictionaryHelper.cs#L30-L66","documentation":"DictionaryHelper.GetCode(char) returns the full ChineseCode record (wubi 86/98/new-age + pinyin + frequency) for one character, loaded from the embedded ChineseCode.txt resource. It throws when the character has no entry in that table. This is the backing lookup for wubi/zhengma-style code generation and the pinyin dictionaries.","triggerScenarios":"Calling DictionaryHelper.GetCode(c) for a character absent from ChineseCode.txt: punctuation, symbols, whitespace, ASCII outside handled ranges, CJK extension characters, or emoji.","commonSituations":"Wubi/zhengma code generation over a dictionary that contains punctuation, symbols, or rare/extension CJK characters not covered by the bundled code table; feeding a mixed-content wordlist (CJK + symbols) into a stroke-based generator.","solutions":["Pre-check existence: iterate DictionaryHelper.GetAll() or keep a HashSet<char> of known chars and skip unknown ones before calling GetCode.","Wrap the call in try/catch(KeyNotFoundException) (it re-throws as Exception) and skip the character.","Pre-filter word entries to common CJK characters present in the table before code generation."],"exampleFix":"// before\nvar code = DictionaryHelper.GetCode(c);\n// after\nif (!knownChars.Contains(c)) continue;\nvar code = DictionaryHelper.GetCode(c);","handlingStrategy":"validation","validationCode":"var known = new HashSet<char>(DictionaryHelper.GetAll().Select(c => c.Word));\nif (!known.Contains(c)) continue;\nvar code = DictionaryHelper.GetCode(c);","typeGuard":null,"tryCatchPattern":"try { var code = DictionaryHelper.GetCode(c); }\ncatch (Exception) { /* character not in table, skip */ }","preventionTips":["Pre-filter wordlists to common CJK characters before stroke/pinyin code generation.","Avoid passing punctuation, symbols, or extension CJK to DictionaryHelper.GetCode.","Cache a HashSet<char> of known characters once and reuse it across the batch."],"tags":["dictionary","wubi","lookup","cjk"],"backgroundTag":null,"analyzedSha":"16744a12ed5064896cf39095163e44b367aaada1","analyzedAt":"2026-08-13T19:53:09.031Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}