Beispiel #1
0
        public IEnumerable <FengDocument> Run()
        {
            var jsonOutput = new List <string>();
            var documents  = new List <FengDocument>();

            var docs = LoadFengRows(mergedPath).Select(f =>
            {
                var tmp = new FengDocument
                {
                    Id               = $"p{f.PageNumber}_{f.LineNumber}",
                    HanziCanonical   = f.KanjiClean,
                    YngpingCanonical = f.Pron,
                    Explanation      = f.Explanation,
                    ExplanationHans  = Simplify(f.Explanation),
                    Source           = new FengDocument.Types.SourceInfo
                    {
                        PageNumber = f.PageNumber,
                        LineNumber = f.LineNumber
                    },
                };
                tmp.HanziMatchable.Add(f.KanjiClean);
                tmp.HanziMatchable.Add(Simplify(f.KanjiClean));
                tmp.YngpingPermutations.Add(f.Pron);
                tmp.YngpingPermutations.AddRange(YngpingVariantsUtil.GenerateYngpingVariants(f.Pron));
                return(tmp);
            });

            documents.AddRange(docs);
            jsonOutput.AddRange(docs.Select(proto => proto.ToString()));
            File.WriteAllLines(Path.Combine(outputFolder, "feng_index_debug.txt"), jsonOutput);
            return(documents);
        }
Beispiel #2
0
        private static string[] CollectYngpingPermutations(
            IReadOnlyCollection <YngdiengDocument.Types.Source> sources)
        {
            return(sources
                   .SelectMany(s =>
            {
                switch (s.SourceCase)
                {
                case SourceOneofCase.CiklinDfd:
                    return new string[] { s.CiklinDfd.YngpingModern };

                case SourceOneofCase.Feng:
                    return s.Feng.YngpingPermutations.ToArray();

                case SourceOneofCase.Contrib:
                    return YngpingVariantsUtil.GenerateYngpingVariants(s.Contrib.YngpingSandhi)
                    .Concat(new string[] { s.Contrib.YngpingUnderlying });
                }
                return new string[] { };
            })
                   .Distinct()
                   .ToArray());
        }