//Returns an array of LevenshteinResults, sorted lowest DISTANCE [i=0] to highest DISTANCE [i=end] (eg from highest simliarity to lowest similarity)
        private static List <LevenshteinResult> GetAllLevenshteinSorted(List <MangaGamerDialogue> unmatchedmgs, List <PS3DialogueInstruction> unmatchedPS3)
        {
            List <LevenshteinResult> allLevenshteinResults = new List <LevenshteinResult>();

            //For each mg dialogue, Calculate similarity against ps3 dialogue
            for (int mgIndex = 0; mgIndex < unmatchedmgs.Count; mgIndex++)
            {
                for (int ps3Index = 0; ps3Index < unmatchedPS3.Count; ps3Index++)
                {
                    string mgString       = Differ.PrepareStringForDiff(unmatchedmgs[mgIndex].data);
                    string ps3String      = Differ.PrepareStringForDiff(unmatchedPS3[ps3Index].data);
                    int    rawLevenshtein = Fastenshtein.Levenshtein.Distance(mgString, ps3String);

                    //divide the raw levenschtein by length of the longer string, to get a percentage match
                    //double scaledLevenshtein = rawLevenshtein / Math.Max(mgString.Length, ps3String.Length) * 100.0;

                    allLevenshteinResults.Add(new LevenshteinResult()
                    {
                        mgIndex  = mgIndex,
                        ps3Index = ps3Index,
                        score    = rawLevenshtein, //(int) Math.Round(scaledLevenshtein),
                    });
                }
            }

            //sort the list
            allLevenshteinResults.Sort();

            return(allLevenshteinResults);
        }
        //Searches for japanese dialogue in the 'OutputLine' functions in the MangaGamer scripts
        public static List <MangaGamerDialogue> GetDialogueLinesFromMangaGamerScript(string filePath, out List <string> mgLeftovers)
        {
            IEnumerable <string>      allLines  = File.ReadLines(filePath);
            List <MangaGamerDialogue> dialogues = new List <MangaGamerDialogue>();

            int           lineNumber    = 0;
            List <string> previousLines = new List <string>();

            foreach (string line in allLines)
            {
                if (line.Contains("OutputLine"))
                {
                    if (Differ.PrepareStringForDiff(line).Length > 0)
                    {
                        dialogues.Add(new MangaGamerDialogue(lineNumber, line, previousLines));
                        previousLines.Clear();
                    }
                    else
                    {
                        Console.WriteLine($"WARNING: MG dialogue has no japanese characters - it won't be used for matching: [{line}]");
                        previousLines.Add(line);
                    }
                }
                else
                {
                    previousLines.Add(line);
                }

                lineNumber += 1;
            }

            mgLeftovers = previousLines;

            return(dialogues);
        }
Ejemplo n.º 3
0
        static PS3DialogueFragment SearchForBestPS3Dialogues(List <PS3DialogueFragment> ps3DialogueFragments, MangaGamerDialogue mgDialogueToSearch)
        {
            string mangaGamerChoiceForDiff = Differ.PrepareStringForDiff(mgDialogueToSearch.data);

            float lowestDistance         = float.MaxValue;
            PS3DialogueFragment bestFrag = null;

            foreach (var frag in ps3DialogueFragments)
            {
                string fragmentForDiff = Differ.PrepareStringForDiff(frag.data);

                //if ps3 fragment is of length 0, skip it
                if (fragmentForDiff.Length == 0)
                {
                    continue;
                }

                float rawLevenshtein    = (float)Fastenshtein.Levenshtein.Distance(mangaGamerChoiceForDiff, fragmentForDiff);
                float scaledLevenshtein = rawLevenshtein / Math.Max(mangaGamerChoiceForDiff.Length, fragmentForDiff.Length);

                if (scaledLevenshtein < lowestDistance)
                {
                    lowestDistance = scaledLevenshtein;
                    bestFrag       = frag;
                }
            }

            return(bestFrag);
        }