From 960314a87faca50b1d45a3d3b83cd787c96ec421 Mon Sep 17 00:00:00 2001 From: Rocka Date: Thu, 4 Jul 2024 03:28:56 +0800 Subject: [PATCH 1/2] fix npe --- src/ImeWlConverterCore/ConsoleRun.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ImeWlConverterCore/ConsoleRun.cs b/src/ImeWlConverterCore/ConsoleRun.cs index 89b05d1c..4d360c92 100644 --- a/src/ImeWlConverterCore/ConsoleRun.cs +++ b/src/ImeWlConverterCore/ConsoleRun.cs @@ -394,7 +394,7 @@ private void LoadImeList() cbxImportItems.Add(cbxa); imports.Add( cbxa.ShortCode, - Type.GetType(type.FullName) as IWordLibraryImport + assembly.CreateInstance(type.FullName) as IWordLibraryImport ); } if (type.GetInterface("IWordLibraryExport") != null) @@ -403,7 +403,7 @@ private void LoadImeList() cbxExportItems.Add(cbxa); exports.Add( cbxa.ShortCode, - Type.GetType(type.FullName) as IWordLibraryExport + assembly.CreateInstance(type.FullName) as IWordLibraryExport ); } } From 2d9abdb19fa49bd8f07cbaed0a5080043b050fb6 Mon Sep 17 00:00:00 2001 From: Rocka Date: Thu, 4 Jul 2024 03:03:47 +0800 Subject: [PATCH 2/2] LibIME pinyin txt format. --- src/ImeWlConverterCore/ConstantString.cs | 2 + src/ImeWlConverterCore/IME/LibIMEText.cs | 69 ++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/ImeWlConverterCore/IME/LibIMEText.cs diff --git a/src/ImeWlConverterCore/ConstantString.cs b/src/ImeWlConverterCore/ConstantString.cs index abdbcffb..33f2fb6a 100644 --- a/src/ImeWlConverterCore/ConstantString.cs +++ b/src/ImeWlConverterCore/ConstantString.cs @@ -77,6 +77,7 @@ public class ConstantString public const string CHINESE_PYIM = "Chinese-pyim"; public const string EMOJI = "Emoji"; public const string MAC_PLIST = "Mac简体拼音"; + public const string LIBIME_TEXT = "LibIME 拼音词库(文本格式)"; //简码,控制台用 public const string BAIDU_SHOUJI_C = "bdsj"; @@ -131,5 +132,6 @@ public class ConstantString public const string CHINESE_PYIM_C = "pyim"; public const string EMOJI_C = "emoji"; public const string MAC_PLIST_C = "plist"; + public const string LIBIME_TEXT_C = "libimetxt"; } } diff --git a/src/ImeWlConverterCore/IME/LibIMEText.cs b/src/ImeWlConverterCore/IME/LibIMEText.cs new file mode 100644 index 00000000..398898ef --- /dev/null +++ b/src/ImeWlConverterCore/IME/LibIMEText.cs @@ -0,0 +1,69 @@ +/* + * Copyright © 2009-2020 studyzy(深蓝,曾毅) + + * This program "IME WL Converter(深蓝词库转换)" is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +using System; +using System.Collections.Generic; +using System.Text; +using Studyzy.IMEWLConverter.Entities; + +namespace Studyzy.IMEWLConverter.IME +{ + /// + /// LibIME (https://github.com/fcitx/libime) 文本格式 + /// + [ComboBoxShow(ConstantString.LIBIME_TEXT, ConstantString.LIBIME_TEXT_C, 500)] + public class LibIMEText : BaseTextImport, IWordLibraryExport, IWordLibraryTextImport + { + public override Encoding Encoding => Encoding.UTF8; + + public string ExportLine(WordLibrary wl) + { + var sb = new StringBuilder(); + + sb.Append(wl.Word); + sb.Append(" "); + sb.Append(wl.GetPinYinString("'", BuildType.None)); + sb.Append(" "); + sb.Append(wl.Rank); + + return sb.ToString(); + } + + public IList Export(WordLibraryList wlList) + { + var sb = new StringBuilder(); + for (int i = 0; i < wlList.Count; i++) + { + sb.Append(ExportLine(wlList[i])); + sb.Append("\n"); + } + return new List() { sb.ToString() }; + } + + public override WordLibraryList ImportLine(string line) + { + string[] c = line.Split(' '); + var wl = new WordLibrary(); + wl.PinYin = c[0].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries); + wl.Word = c[1]; + wl.Rank = Convert.ToInt32(c[2]); + var wll = new WordLibraryList(); + wll.Add(wl); + return wll; + } + } +}