コード例 #1
0
        public void AddAllDwavesOnLine(string line)
        {
            foreach (Match match in DwaveRegex.Matches(line))
            {
                //Note: this variable does not have quotes! eg ["test\path"] is converted to [test\path]
                string dwavePathOrAlias = match.Groups[1].Value;

                DwaveArgument dwaveArgumentObject = new DwaveArgument(dwavePathOrAlias);

                string normalizedDwaveArgument = dwaveArgumentObject.GetNormalizedValue();

                if (allDwaveArgs.ContainsKey(normalizedDwaveArgument))
                {
                    logger.Warning($"Duplicate dwave command: {normalizedDwaveArgument}");
                }
                else
                {
                    allDwaveArgs.Add(dwaveArgumentObject.GetNormalizedValue(), dwaveArgumentObject);
                }
            }
        }
コード例 #2
0
        //expects a list of dwave strings like:
        //{ ":dwave 0, beae14:", ":dwave 0, bea21:",  }
        //outputs a new list with missing voices added in
        public AutoFixResult FixMissingDwaves(List <string> dwaveStrings, int numberOfDwaveToGenerate, out List <string> fixedDwaves)
        {
            List <DwaveArgument> argumentsOnly = new List <DwaveArgument>();

            //get only the arguments of each dwave
            foreach (string s in dwaveStrings)
            {
                Match         match         = DwaveRegex.Match(s);
                DwaveArgument dwaveArgument = new DwaveArgument(match.Groups[1].Value);
                argumentsOnly.Add(dwaveArgument);
            }

            //check the 'head' of all the dwaves are the same - stop if not the same
            string firstHead = argumentsOnly[0].GetHead();

            foreach (DwaveArgument dwaveArgument in argumentsOnly)
            {
                if (dwaveArgument.GetHead() != firstHead)
                {
                    throw new PrefixOfDwaveArgNotTheSame($"ERROR: head {dwaveArgument.GetHead()} is not the same as {firstHead}!");
                }
            }

            //find the min and max values in the list. Also, create a hashset
            //containing all the dwave arguments in the orginal japanese dwave list
            HashSet <int> digitsInOriginalList = new HashSet <int>();
            int           minValue             = int.MaxValue;
            int           maxValue             = int.MinValue;

            foreach (DwaveArgument dwaveArgument in argumentsOnly)
            {
                int trailingDigits = dwaveArgument.GetTrailingDigits();
                digitsInOriginalList.Add(trailingDigits);
                minValue = Math.Min(trailingDigits, minValue);
                maxValue = Math.Max(trailingDigits, maxValue);
            }

            //DEBUG: check the dwaves one before, one after, and inbetween the min and max dwaves.
            //this debugging for printing.
            if (debugEnabled)
            {
                Console.WriteLine("----------------------------");
                for (int i = minValue - 1; i <= maxValue + 1; i++)
                {
                    string generatedDwaveArgument = $"{firstHead}{i}";
                    Console.Write(generatedDwaveArgument);

                    if (i == minValue - 1 || i == maxValue + 1)
                    {
                        Console.Write(" <PREPOST> ");
                    }

                    if (digitsInOriginalList.Contains(i))
                    {
                        Console.WriteLine(": Already in current line.");
                    }
                    else if (CheckDwaveUsed(generatedDwaveArgument))
                    {
                        Console.WriteLine(": Appears in script.");
                    }
                    else
                    {
                        Console.WriteLine(": NOT USED");
                    }
                }
            }

            //Make a new list of dwaves of length "numberOfDwaveToGenerate"
            List <DwaveArgument> generatedDwaveArguments = new List <DwaveArgument>();

            for (int i = minValue - 1; i <= maxValue + 1; i++)
            {
                string generatedDwaveArgumentString = $"{firstHead}{i}";

                //accept the dwave argument if it was already in the current line, OR if it doesn't exist anywhere in the script
                if (!CheckDwaveUsed(generatedDwaveArgumentString) || digitsInOriginalList.Contains(i))
                {
                    generatedDwaveArguments.Add(new DwaveArgument(generatedDwaveArgumentString));
                }

                if (generatedDwaveArguments.Count == numberOfDwaveToGenerate)
                {
                    break;
                }
            }

            if (debugEnabled)
            {
                Console.WriteLine("Generated Dwaves:");
                foreach (DwaveArgument i in generatedDwaveArguments)
                {
                    Console.WriteLine(i.GetNormalizedValue());
                }
            }

            //regenerate the full dwave strings
            fixedDwaves = new List <string>();
            foreach (DwaveArgument dwaveArgument in generatedDwaveArguments)
            {
                fixedDwaves.Add($":dwave 0, {dwaveArgument.GetUnNormalizedValue()}:");
            }

            //DEBUG: print the two dwave lists
            if (debugEnabled)
            {
                foreach (string dwaveCommand in fixedDwaves)
                {
                    Console.Write($"{dwaveCommand},");
                }
                Console.WriteLine();
                foreach (string dwaveCommand in dwaveStrings)
                {
                    Console.Write($"{dwaveCommand},");
                }
                Console.WriteLine();
            }

            //Return whether fixing was sucessfull or unsuccesful
            if (generatedDwaveArguments.Count < numberOfDwaveToGenerate)
            {
                //Couldn't generate enough DWaves
                return(AutoFixResult.Failure);
            }
            else if (numberOfDwaveToGenerate < dwaveStrings.Count)
            {
                //was asked to 'remove' dwaves from english line - needs manual check
                return(AutoFixResult.NeedsManualCheck);
            }
            else if (generatedDwaveArguments.Count == numberOfDwaveToGenerate)
            {
                //was asked to add more dwaves to japanese line, and succesfully generated the number of dwaves asked.
                return(AutoFixResult.OK);
            }

            throw new Exception("FixMissingDwaves: shouldn't be able to reach here");
        }
コード例 #3
0
        //might change this later to accept a full dwave command line dwave 0, sadf;alskdfj
        public bool CheckDwaveUsed(string dwaveArgString)
        {
            DwaveArgument dwaveArgumentObject = new DwaveArgument(dwaveArgString);

            return(allDwaveArgs.ContainsKey(dwaveArgumentObject.GetNormalizedValue()));
        }