コード例 #1
0
        private void Init(IEnumerable <KanaCharacter> kana)
        {
            int x = 0;
            int y = 0;

            foreach (var k in kana)
            {
                if (k != null)
                {
                    Kana.Add(new KanaVM(this, CodePoint.FromString(k.Kana), k.Romaji, x, y));
                }
                else
                {
                    Kana.Add(new KanaVM(this, null, null, x, y));
                }

                x++;
                if (x == 5)
                {
                    x = 0;
                    y++;
                }
            }

            Width  = x == 0 ? y : y + 1;
            Height = 5;

            var contents = Kana.OrderBy(k => k.X * Width + -k.Y).ToList();

            Kana.Clear();
            Kana.AddRange(contents);
        }
コード例 #2
0
 public void Test()
 {
     CollectionAssert.AreEquivalent(
         "籥鑰龠瀹爚禴籲鸙龡龢龣龥".AsCodePoints().Select(CodePoint.FromInt),
         lookup.SelectRadical(new[] { CodePoint.FromString("龠") })
         .Kanji);
     Console.WriteLine($"Expected: {string.Join(",", "龥籲".AsCodePoints())}");
     Console.WriteLine($"Actual: {string.Join(",", lookup.SelectRadical(new[] { CodePoint.FromString("龠"), CodePoint.FromString("ハ") }).Kanji.Select(k => k.Utf32))}");
     CollectionAssert.AreEquivalent(
         "龥籲".AsCodePoints().Select(CodePoint.FromInt),
         lookup.SelectRadical(new[] { CodePoint.FromString("龠"), CodePoint.FromString("ハ") })
         .Kanji);
     CollectionAssert.AreEquivalent(
         "一|亅个ハ冂口目冊竹貝頁龠廾".AsCodePoints().Select(CodePoint.FromInt),
         lookup.SelectRadical(new[] { CodePoint.FromString("龠"), CodePoint.FromString("ハ") })
         .PossibleRadicals
         .Where(r => r.Value)
         .Select(r => r.Key));
     // 龠瀹爚禴龡龢籥鑰龣龥鸙籲
     // 籥鑰龠瀹爚禴籲鸙龡龢龣龥
 }
コード例 #3
0
        public Task <Option <RichFormatting> > Answer(Request request)
        {
            var ch   = request.Character;
            var cp   = CodePoint.FromString(ch);
            var rich = new RichFormatting();
            var p    = new TextParagraph();

            var radicals = cp is Kanji k
                ? lang.LookupRadicals(k).ValueOr(Enumerable.Empty <CodePoint>())
                : Enumerable.Empty <CodePoint>();

            var romaji = cp is Kana kana?lang.LookupRomaji(kana) : null;

            var text = cp.ToDescriptionString() + "\n" +
                       (romaji != null ? romaji + "\n" : "") +
                       string.Join(" ; ", radicals);

            p.Content.Add(new Text(text));
            rich.Paragraphs.Add(p);
            return(Task.FromResult(Option.Some(rich)));
        }