Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var       json       = File.ReadAllText(@"lojbantan-zei-jbovlaste.json");
            var       dictionary = OneToManyJsonSerializer.Deserialize(json);
            Thesaurus thesaurus  = JsonSerializer.Deserialize <Thesaurus>(File.ReadAllText(@"relations.json"));

            foreach (var word in dictionary.Words.Where(word => !word.Tags.Contains("ラフシ") && !word.Tags.Contains("語根《ラフシ》")))
            {
                word.Relations = new List <Relation>();
            }

            foreach (var tagFamily in thesaurus.TagFamilies)
            {
                var words = dictionary.Words.Where(word => word.Tags.Contains(tagFamily.Tag));
                foreach (var category in tagFamily.Categories)
                {
                    var relations = new List <Relation>();
                    foreach (var group in category.Groups)
                    {
                        foreach (var relationWord in group.Relations)
                        {
                            relations.Add(new Relation
                            {
                                Title = group.Title,
                                Entry = dictionary.Words.First(word => word.Entry.Form == relationWord && word.Tags.Contains(tagFamily.Tag)).Entry
                            });
                        }
                    }
                    foreach (var group in category.Groups)
                    {
                        foreach (var relationWord in group.Relations)
                        {
                            var word = dictionary.Words.First(w => w.Entry.Form == relationWord && w.Tags.Contains(tagFamily.Tag));
                            word.Relations = word.Relations.Union(relations).ToList();
                        }
                    }
                }
            }

            var options = new JsonSerializerOptions
            {
                Encoder       = JavaScriptEncoder.Create(UnicodeRanges.All),
                WriteIndented = true,
            };

            json = OneToManyJsonSerializer.Serialize(dictionary, options);
            File.WriteAllText(@"output.json", json);
        }
        static void Main()
        {
            var path       = @"lineparine.csv";
            var dicwords   = Load(path);
            var dictionary = new OneToManyJson
            {
                Zpdic = new Zpdic
                {
                    AlphabetOrder = "",
                    WordOrderType = "UNICODE",
                    Punctuations  = new List <string> {
                        ",", "、"
                    },
                    IgnoredTranslationRegex = @"\(.*\)|(.*)|\[.*\]",
                    PlainInformationTitles  = null,
                    InformationTitleOrder   = null,
                    FormFontFamily          = null,
                    DefaultWord             = new Word
                    {
                    },
                }
            };
            int totalTicks         = dicwords.Count;
            var progressBarOptions = new ProgressBarOptions
            {
                ForegroundColor     = ConsoleColor.Yellow,
                BackgroundColor     = ConsoleColor.DarkGray,
                BackgroundCharacter = '.',
                ProgressCharacter   = '#',
            };
            var childProgressBarOptions = new ProgressBarOptions
            {
                ForegroundColor      = ConsoleColor.Green,
                BackgroundColor      = ConsoleColor.DarkGray,
                BackgroundCharacter  = '.',
                ProgressCharacter    = '#',
                CollapseWhenFinished = false,
            };

            using (var pbar = new ProgressBar(5, "Total Progress", progressBarOptions))
                using (var pbar5 = pbar.Spawn(1, "Output to ./output.json", childProgressBarOptions))
                    using (var pbar4 = pbar.Spawn(1, "Relation ID completion", childProgressBarOptions))
                        using (var pbar3 = pbar.Spawn(totalTicks, "Register cases", childProgressBarOptions))
                            using (var pbar2 = pbar.Spawn(totalTicks, "Register subheadings", childProgressBarOptions))
                                using (var pbar1 = pbar.Spawn(totalTicks, "Register words", childProgressBarOptions))
                                {
                                    foreach (var dicword in dicwords)
                                    {
                                        var wc = new WordConverter {
                                            DicWord = dicword, DicWords = dicwords
                                        };
                                        var word = wc.Convert();
                                        dictionary.AddWord(word);
                                        var subheadings = wc.AddSubheading(dictionary);
                                        pbar1.Tick($"Register \"{word.Entry.Form}\" in the dictionary");
                                        foreach (var subheading in subheadings)
                                        {
                                            if (dictionary.Words.All(w => w.Entry.Id != subheading.Entry.Id))
                                            {
                                                dictionary.AddWord(subheading);
                                            }
                                        }
                                        pbar2.Tick($"Register \"{word.Entry.Form}\"'s subheadings in the dictionary");
                                    }
                                    pbar.Tick("Register words");
                                    pbar.Tick("Register subheadings");
                                    pbar3.MaxTicks = dictionary.Words.Count;
                                    var casegen = new CaseGenerator();
                                    foreach (var word in dictionary.Words)
                                    {
                                        casegen.Word = word;
                                        casegen.AddCase();
                                        pbar3.Tick($"Register \"{word.Entry.Form}\"'s cases in the dictionary");
                                    }
                                    pbar.Tick("Register cases");
                                    dictionary.RelationIdCompletion();
                                    pbar4.Tick("Relation ID completion");
                                    pbar.Tick("Relation ID completion");
                                    var options = new System.Text.Json.JsonSerializerOptions
                                    {
                                        Encoder       = JavaScriptEncoder.Create(UnicodeRanges.All),
                                        WriteIndented = true,
                                    };
                                    var json = OneToManyJsonSerializer.Serialize(dictionary, options);
                                    File.WriteAllText(@"output.json", json);
                                    pbar5.Tick("Output to ./output.json");
                                    pbar.Tick("Output to ./output.json");
                                }
        }