Skip to content

Commit

Permalink
ATOK追加
Browse files Browse the repository at this point in the history
  • Loading branch information
AioiLight committed Mar 8, 2020
1 parent ba926a7 commit 249b517
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions DictionaryMate/IME/ATOK.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AioiLight.DictionaryMate.IME;

namespace AioiLight.DictionaryMate.IME
{
internal class ATOK : IConvertible
{
public Encoding Encoding
{
get
{
return Encoding.Unicode;
}
}

public string Convert(List<Dictionary> jsonDic)
{
var sb = new StringBuilder();

// ヘッダー
sb.Append("!!ATOK_TANGO_TEXT_HEADER_1\r\n");

foreach (var item in jsonDic)
{
// 置換候補が6つ以上あれば、複数同じ単語で登録する必要がある
for (var i = item.Replace.Length; 0 < i ; i -= 5)
{
var replace = string.Join('\t', item.Replace.Skip(item.Replace.Length - i).Take(5));
sb.Append(
$"{item.Pronounce}\t{item.Word}\t{SpeechToString(item.Speech)}\t{item.Comment}\t{replace}\r\n"
);
}
}


return sb.ToString();
}

public string SpeechToString(Speech? speech)
{
return !speech.HasValue
? "名詞"
: (speech.Value switch
{
Speech.Noun => "名詞",
Speech.Family => "固有人姓",
Speech.Name => "固有人名",
Speech.Person => "固有人他",
Speech.Place => "固有地名",
Speech.Org => "固有組織",
Speech.Short => "短縮読み",
Speech.Emoji => "顔文字",
_ => "名詞",
});
}
}
}
1 change: 1 addition & 0 deletions DictionaryMate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 52,7 @@ static void Error(IEnumerable<Error> err)
private static IME.IConvertible GetConverterFromString(string ime)
{
return ime switch {
"atok" => new IME.ATOK(),
"googleime" => new IME.GoogleIME(),
_ => null
};
Expand Down

0 comments on commit 249b517

Please sign in to comment.