private static string[,] JaProcess(string text) { int SegBufferSize = Program.EXT_BYTES_MAX_SIZE * 20; IntPtr pSegBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(byte)) * SegBufferSize); MeCabSegment(text, pSegBuffer, SegBufferSize); string SegStr = MyConverter.pBufferToString(pSegBuffer, SegBufferSize, "utf-8"); Marshal.FreeHGlobal(pSegBuffer); SegStr = SegStr.Trim(Program.WhiteSpaceChars); string[,] table; if (SegStr == string.Empty) { table = new string[1, 3]; table[0, 0] = text; table[0, 1] = table[0, 2] = ""; } else { string[] Words = SegStr.Split('\n'); table = new string[Words.Length, 3]; for (int i = 0; i < Words.Length; i++) { string[] WordAttrs = Words[i].Split('\t', ','); table[i, 0] = WordAttrs.Length >= 1 ? WordAttrs[0] : ""; table[i, 1] = WordAttrs.Length >= 2 ? WordAttrs[1] : ""; table[i, 2] = WordAttrs.Length >= 9 ? katakanaToHiragana(WordAttrs[8]) : ""; } } return(table); }
public static void onExtText() { form1.ClearLastResult(); string OriginText = MyConverter.pBufferToString(pExtBuffer, EXT_BYTES_MAX_SIZE, vn.ProcEncoding); //pre-process OriginText = OriginText.Trim(WhiteSpaceChars); int pos = OriginText.LastIndexOf('\0'); if (pos != -1) { OriginText = OriginText.Substring(pos + 1); } if (OriginText == string.Empty) { return; } //user filter foreach (string w in vn.WordsFilter) { OriginText = OriginText.Replace(w, ""); } TextTable = WordProcess.Process(OriginText, vn.Language); form1.RefreshText(); List <Task <string> > TranslateTasks = GenerateTranslateTasks(OriginText); foreach (Task <string> task in TranslateTasks) { task.ContinueWith(t => { form1.RefreshTranslation(TranslateTasks.IndexOf(t), t.Result.ToString()); }); task.Start(); } }