Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ParserResult <Options> parseResult = Parser.Default.ParseArguments <Options>(args);

            if (parseResult.Errors.Any())
            {
                return;
            }

            Options options = parseResult.Value;

            InjectionAnalyzer injectionAnaluzer = new InjectionAnalyzer();

            HashSet <string> exceptions = new HashSet <string>(options.DefTypeExceptions.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));

            InjectionPathComparer injComparer     = new InjectionPathComparer();
            DefTypeComparer       defTypeComparer = new DefTypeComparer();

            List <Entry> keyedEntries    = ReadCommentedKeyedValues(Path.Combine(options.TargetPath, "Keyed")).ToList();
            List <Entry> injectedEntries = ReadCommentedInjections(Path.Combine(options.TargetPath, "DefInjected")).Where(inj => !exceptions.Contains(inj.Category, defTypeComparer)).ToList();

            using (StreamWriter sw = File.CreateText(options.ReportPath))
            {
                WriteEntriesGrouped(injectedEntries.Concat(keyedEntries), sw);
                sw.Close();
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ParserResult <Options> parseResult = Parser.Default.ParseArguments <Options>(args);

            if (parseResult.Errors.Any())
            {
                return;
            }

            Options options = parseResult.Value;

            InjectionAnalyzer analyzer = new InjectionAnalyzer();

            HashSet <string> defTypes = new HashSet <string>(options.DefsTypes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));

            Injection[] injections = analyzer
                                     .ReadInjections(options.DefsPath)
                                     .Where(inj => defTypes.Contains(inj.DefType))
                                     .Where(inj => GetLastPart(inj).ToLowerInvariant().Contains("label"))
                                     //.Where(inj => !ignoredLabels.Contains(inj.Translation))
                                     .ToArray();

            Dictionary <string, int> categoryStats = MergeDictionarites(
                GetCategoriesDict(File.ReadAllLines(options.MaleGenderFile), injections),
                GetCategoriesDict(File.ReadAllLines(options.FemaleGenderFile), injections),
                GetCategoriesDict(File.ReadAllLines(options.NeuterGenderFile), injections),
                GetCategoriesDict(File.ReadAllLines(options.PluralGenderFile), injections));

            //IEnumerable<string> categories =
            //	GetCategories(File.ReadAllLines(options.MaleGenderFile), allLabels)
            //	.Union(GetCategories(File.ReadAllLines(options.FemaleGenderFile), allLabels))
            //	.Union(GetCategories(File.ReadAllLines(options.NeuterGenderFile), allLabels))
            //	.Union(GetCategories(File.ReadAllLines(options.PluralGenderFile), allLabels))
            //	.Distinct();

            File.WriteAllLines(options.OutputFile, categoryStats.Select(kvp => $"{kvp.Key}: {kvp.Value}"));

            File.WriteAllLines(options.IgnoreFile, WriteGroups(GroupByCategory(File.ReadAllLines(options.IgnoreFile), injections)));

            File.WriteAllLines(options.MaleGenderFile, WriteGroups(GroupByCategory(File.ReadAllLines(options.MaleGenderFile), injections)));
            File.WriteAllLines(options.FemaleGenderFile, WriteGroups(GroupByCategory(File.ReadAllLines(options.FemaleGenderFile), injections)));
            File.WriteAllLines(options.NeuterGenderFile, WriteGroups(GroupByCategory(File.ReadAllLines(options.NeuterGenderFile), injections)));
            File.WriteAllLines(options.PluralGenderFile, WriteGroups(GroupByCategory(File.ReadAllLines(options.PluralGenderFile), injections)));
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ParserResult <Arguments> parseResult = Parser.Default.ParseArguments <Arguments>(args);

            if (parseResult.Errors.Any())
            {
                return;
            }

            Arguments arguments = parseResult.Value;

            // Создаем коллекцию всех существительных.
            CyrNounCollection nouns = new CyrNounCollection();

            // Создаем коллекцию всех прилагательных.
            CyrAdjectiveCollection adjectives = new CyrAdjectiveCollection();

            // Создаем фразу с использование созданных коллекций.
            CyrPhrase phrase = new CyrPhrase(nouns, adjectives);

            InjectionAnalyzer analyzer = new InjectionAnalyzer();

            HashSet <string> defTypes = new HashSet <string>(arguments.DefsTypes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));

            HashSet <string> ignoredInjections = File.Exists(arguments.IgnoreFile)
                                ? new HashSet <string>(File.ReadAllLines(arguments.IgnoreFile))
                                : new HashSet <string>();

            HashSet <string> pluralizedLabels = File.Exists(arguments.Output)
                                ? new HashSet <string>(File.ReadAllLines(arguments.Output).Select(line => new string(line.TakeWhile(c => c != ';').ToArray())))
                                : new HashSet <string>();

            Injection[] allLabels = analyzer
                                    .ReadInjections(arguments.DefsPath)
                                    .Where(inj => defTypes.Contains(inj.DefType))
                                    .Where(inj => GetLastPart(inj).ToLowerInvariant().Contains("label"))
                                    .Distinct(new InjectionTypeTranslationComparer())
                                    .Where(inj =>
                                           !ignoredInjections.Contains(FormInjectionLine(inj)) &&
                                           !pluralizedLabels.Contains(inj.Translation))
                                    .ToArray();

            Console.WriteLine($"Check plural forms for {allLabels.Length} labels.");

            List <Option> history = new List <Option>();

            string prevDefType = "";

            PluralPair pluralPair = null;

            for (int labelIndex = 0; labelIndex < allLabels.Length;)
            {
                Injection injection = allLabels[labelIndex];
                string    label     = injection.Translation;

                Console.WriteLine();
                Console.WriteLine($"{labelIndex + 1}/{allLabels.Length} {injection.DefType} <{injection.DefPath}> \"{label}\":");

                if (pluralPair == null)
                {
                    pluralPair = PluralizeIgnoreSuffix(phrase, label, " (", " из ", " для ", " с ", " в ");
                }

                if (pluralPair == null)
                {
                    Console.WriteLine($"	Failed to pluralize");
                }
                else
                {
                    WritePluralization(pluralPair);
                }

                Console.Write("<Enter> - accept; <Space> - edit; <Backspace> - back; <Delete> - ignore");
                ConsoleKey key = Console.ReadKey().Key;
                Console.WriteLine();

                switch (key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.Spacebar:
                    if (pluralPair == null)
                    {
                        pluralPair = new PluralPair(label, label);
                    }

                    pluralPair = EditPluralization(pluralPair);

                    if (injection.DefType != prevDefType)
                    {
                        FileUtil.PushLine(arguments.Output, string.Empty);
                        FileUtil.PushLine(arguments.Output, "// " + injection.DefType);
                    }
                    FileUtil.PushLine(arguments.Output, ToLine(pluralPair));
                    pluralPair = null;
                    history.Add(Option.Accept);
                    labelIndex++;
                    break;

                case ConsoleKey.Enter:
                    if (pluralPair != null)
                    {
                        if (injection.DefType != prevDefType)
                        {
                            FileUtil.PushLine(arguments.Output, string.Empty);
                            FileUtil.PushLine(arguments.Output, "// " + injection.DefType);
                        }
                        FileUtil.PushLine(arguments.Output, ToLine(pluralPair));
                        pluralPair = null;
                        history.Add(Option.Accept);
                        labelIndex++;
                    }
                    break;

                case ConsoleKey.Delete:
                    FileUtil.PushLine(arguments.IgnoreFile, FormInjectionLine(injection));
                    pluralPair = null;
                    history.Add(Option.Ignore);
                    labelIndex++;
                    break;

                case ConsoleKey.Backspace:
                    Option prevOption = history[labelIndex - 1];
                    history.RemoveAt(labelIndex - 1);
                    labelIndex--;

                    if (prevOption == Option.Accept)
                    {
                        string prevDeclinationLine = FileUtil.PopLine(arguments.Output);
                        pluralPair = FromLine(prevDeclinationLine);
                    }
                    else if (prevOption == Option.Ignore)
                    {
                        FileUtil.PopLine(arguments.IgnoreFile);
                        pluralPair = null;
                    }
                    break;

                default:
                    break;
                }

                prevDefType = injection.DefType;
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ParserResult <Options> parseResult = Parser.Default.ParseArguments <Options>(args);

            if (parseResult.Errors.Any())
            {
                return;
            }

            Options options = parseResult.Value;

            InjectionAnalyzer analyzer = new InjectionAnalyzer();

            HashSet <string> defTypes = new HashSet <string>(options.DefsTypes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));

            HashSet <string> maleLabels        = new HashSet <string>(File.ReadAllLines(options.MaleGenderFile));
            HashSet <string> femaleLabels      = new HashSet <string>(File.ReadAllLines(options.FemaleGenderFile));
            HashSet <string> neuterLabels      = new HashSet <string>(File.ReadAllLines(options.NeuterGenderFile));
            HashSet <string> pluralLabels      = new HashSet <string>(File.ReadAllLines(options.PluralGenderFile));
            HashSet <string> ignoredInjections = new HashSet <string>(File.ReadAllLines(options.IgnoreFile));

            Injection[] allLabels = analyzer
                                    .ReadInjections(options.DefsPath)
                                    .Where(inj => defTypes.Contains(inj.DefType))
                                    .Where(inj => GetLastPart(inj).ToLowerInvariant().Contains("label"))
                                    .Distinct(new InjectionTypeTranslationComparer())
                                    .Where(inj =>
                                           !ignoredInjections.Contains(FormInjectionLine(inj)) &&
                                           !maleLabels.Contains(inj.Translation) &&
                                           !femaleLabels.Contains(inj.Translation) &&
                                           !neuterLabels.Contains(inj.Translation) &&
                                           !pluralLabels.Contains(inj.Translation))
                                    .ToArray();

            Console.WriteLine($"Enter genders for {allLabels.Length} labels.");
            Console.WriteLine("1 - Male, 2 - Female, 3 - Neuter, 4 - Plural, 0 - ignore label, <ENTER> - skip");

            List <Option> history = new List <Option>();

            string prevDefType = "";

            for (int labelIndex = 0; labelIndex < allLabels.Length; ++labelIndex)
            {
                Injection injection = allLabels[labelIndex];
                string    label     = injection.Translation;

                Console.WriteLine();
                Console.Write($"{labelIndex + 1}/{allLabels.Length} {injection.DefType} <{injection.DefPath}> \"{label}\": ");

                ConsoleKeyInfo keyInfo = Console.ReadKey();

                switch (keyInfo.Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.Backspace:
                    string prevFileName = GetFileForOption(options, history[labelIndex - 1]);
                    FileUtil.DeleteLine(prevFileName);
                    history.RemoveAt(labelIndex - 1);
                    labelIndex -= 2;
                    break;

                case ConsoleKey.Enter:
                    break;

                default:
                    Option option = ParseInput(keyInfo.KeyChar);

                    if (option == Option.Unknown)
                    {
                        --labelIndex;
                    }
                    else
                    {
                        string fileName = GetFileForOption(options, option);

                        if (option == Option.Ignore)
                        {
                            FileUtil.PushLine(fileName, FormInjectionLine(injection));
                        }
                        else
                        {
                            if (injection.DefType != prevDefType)
                            {
                                FileUtil.PushLine(fileName, string.Empty);
                                FileUtil.PushLine(fileName, "// " + injection.DefType);
                            }
                            FileUtil.PushLine(fileName, label);
                        }

                        history.Add(option);
                    }
                    break;
                }

                prevDefType = injection.DefType;
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            ParserResult <Options> parseResult = Parser.Default.ParseArguments <Options>(args);

            if (parseResult.Errors.Any())
            {
                return;
            }

            Options options = parseResult.Value;

            //InjectionAnalyzer analyzer = new InjectionAnalyzer();
            //List<Injection> injections = analyzer.ReadInjections(options.InjectionsPath).ToList();

            XDocument mergedDefs = DefWorker.MergeDefs(options.DefsPath);

            InjectionAnalyzer injAnalyzer = new InjectionAnalyzer();
            List <Injection>  injections  = injAnalyzer.ReadInjections(options.InjectionsPath).ToList();

            const string blueprintSuffix = " (проект)";
            const string frameSuffix     = " (строится)";

            using (StreamWriter sw = File.CreateText(options.ReportPath))
            {
                foreach (XElement def in mergedDefs.Root.Elements())
                {
                    string defname = DefWorker.GetDefName(def);
                    string defType = def.Name.LocalName;

                    if (DefWorker.IsDefAbstract(def))
                    {
                        continue;
                    }
                    if (!DefWorker.DefHasParent(mergedDefs, def, "BuildingBase"))
                    {
                        continue;
                    }
                    if (!DefWorker.DefHasElement(mergedDefs, def, "designationCategory"))
                    {
                        continue;
                    }

                    XElement defLabelElement = def.Element("label");
                    if (defLabelElement == null)
                    {
                        continue;
                    }

                    string defLabel = defLabelElement.Value;
                    if (string.IsNullOrEmpty(defLabel))
                    {
                        continue;
                    }

                    string defLabelLocalized = injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + ".label").Translation;
                    ;


                    Injection blueprintLabel = injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + "_Blueprint.label");
                    string    blueprintTag   = string.Format("{0}_Blueprint.label", defname);
                    if (blueprintLabel == null)
                    {
                        sw.WriteLine("\t<{0}>{1}{2}</{0}>", blueprintTag, defLabelLocalized, blueprintSuffix);
                    }
                    else if (blueprintLabel.Translation.Replace(blueprintSuffix, string.Empty) != defLabelLocalized)
                    {
                        sw.WriteLine("Replace: <{0}>", blueprintTag);
                        sw.WriteLine("\t\t{0}", blueprintLabel.Translation);
                        sw.WriteLine("\t\t{0}{1}", defLabelLocalized, blueprintSuffix);
                    }


                    Injection frameLabel = injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + "_Frame.label");
                    string    frameTag   = string.Format("{0}_Frame.label", defname);
                    if (frameLabel == null)
                    {
                        sw.WriteLine("\t<{0}>{1}{2}</{0}>", frameTag, defLabelLocalized, frameSuffix);
                    }
                    else if (frameLabel.Translation.Replace(frameSuffix, string.Empty) != defLabelLocalized)
                    {
                        sw.WriteLine("Replace: <{0}>", frameTag);
                        sw.WriteLine("\t\t{0}", frameLabel.Translation);
                        sw.WriteLine("\t\t{0}{1}", defLabelLocalized, frameSuffix);
                    }

                    string    defDescriptionLocalized = injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + ".description").Translation;
                    Injection frameDescription        = injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + "_Frame.description");
                    string    descriptionTag          = string.Format("{0}_Frame.description", defname);
                    if (frameDescription == null)
                    {
                        sw.WriteLine("\t<{0}>{1}</{0}>", descriptionTag, defDescriptionLocalized);
                    }
                    else if (frameDescription.Translation != defDescriptionLocalized)
                    {
                        sw.WriteLine("Replace: <{0}>", descriptionTag);
                        sw.WriteLine("\t\t{0}", frameDescription.Translation);
                        sw.WriteLine("\t\t{0}", defDescriptionLocalized);
                    }

                    //if (injections.FirstOrDefault(inj => inj.DefType == defType && inj.DefPath == defname + "_Blueprint_Install.label") == null)
                    //{
                    //	string tag = string.Format("{0}_Blueprint_Install.label", defname);
                    //	sw.WriteLine("\t<{0}>{1} (проект)</{0}>", tag, defLabelLocalized);
                    //}
                }
                sw.Close();
            }
        }