Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibIME pinyin text format #319

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ImeWlConverterCore/ConsoleRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/ImeWlConverterCore/ConstantString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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";
}
}
69 changes: 69 additions & 0 deletions src/ImeWlConverterCore/IME/LibIMEText.cs
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Text;
using Studyzy.IMEWLConverter.Entities;

namespace Studyzy.IMEWLConverter.IME
{
/// <summary>
/// LibIME (https://github.com/fcitx/libime) 文本格式
/// </summary>
[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<string> 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<string>() { 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;
}
}
}