public async Task <Dictionary <RaidbossPokemon, double> > GetSimilarRaidbossByNameAsync(string name, int limit = int.MaxValue)
        {
            var algorithm  = new Levenstein();
            var rankedList =
                Pokemon.Select(e => new { Pokemon = e, Rank = algorithm.GetSimilarity(e.Name, name) })
                .OrderByDescending(e => e.Rank)
                .Where(e => e.Rank > 0.1f);
            var raidbosses      = RaidbossService.Raidbosses;
            var pokemonWithBoss = new Dictionary <RaidbossPokemon, double>();

            foreach (var pokemon in rankedList)
            {
                foreach (var raidboss in raidbosses)
                {
                    if (pokemon.Pokemon.Id == raidboss.Id)
                    {
                        pokemonWithBoss.Add(new RaidbossPokemon(pokemon.Pokemon, raidboss), pokemon.Rank);
                    }
                }
                if (pokemonWithBoss.Count >= limit)
                {
                    break;
                }
            }

            return(await Task.FromResult(pokemonWithBoss));

            //var rankedListFiltered = rankedList.Where(e => raidbosses.Contains(e.Pokemon.Id)).Take(limit);
            //return await Task.FromResult(rankedListFiltered.ToDictionary(k => k.Pokemon, v => v.Rank));
        }
        public async Task <Dictionary <IPokemon, double> > GetSimilarPokemonByNameAsync(string name, int limit = int.MaxValue)
        {
            var algorithm  = new Levenstein();
            var rankedList =
                Pokemon.Select(e => new { Pokemon = e, Rank = algorithm.GetSimilarity(e.Name, name) })
                .OrderByDescending(e => e.Rank)
                .Where(e => e.Rank > 0.1f)
                .Take(limit);

            return(await Task.FromResult(rankedList.ToDictionary(k => k.Pokemon, v => v.Rank)));
        }
Example #3
0
        protected override bool CheckResult(string consoleOut)
        {
            var lines    = consoleOut.Split(new string[] { "\r", "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            var lastLine = lines[lines.Length - 1];

            if (RequiredAccuracy == 1)
            {
                // No differences allowed
                return(lastLine == ExpectedResult);
            }

            var comparer = new Levenstein();
            var accuracy = comparer.GetSimilarity(lastLine, ExpectedResult);

            return(accuracy >= RequiredAccuracy);
        }
Example #4
0
        private void DoLevenstein()
        {
            Levenstein lev = new Levenstein();

            switch (_newObjectName.NameType)
            {
            case FisheryObjectNameType.CatchLocalName:
                var localNameList = Names.LocalNameList;
                foreach (var item in localNameList)
                {
                    var similarity = lev.GetSimilarity(_newObjectName.NewName, item);
                }
                break;

            case FisheryObjectNameType.GearLocalName:
                break;
            }
        }
        protected override bool CheckResult(string consoleOut)
        {
            // Normalise new line characters
            var fixedConsoleOut     = consoleOut.Replace("\r\n", "\n").Trim();
            var fixedExpectedResult = ExpectedResult.Replace("\r\n", "\n").Trim();

            const int magicNUmber = 1;

            if (RequiredAccuracy == magicNUmber)
            {
                // No differences allowed
                return(fixedConsoleOut == fixedExpectedResult);
            }

            var comparer = new Levenstein();
            var accuracy = comparer.GetSimilarity(fixedConsoleOut, fixedExpectedResult);

            return(accuracy >= RequiredAccuracy);
        }
Example #6
0
        public static double ApproximatelyEquals(this string firstWord, string secondWord, SimMetricType simMetricType = SimMetricType.Levenstein)
        {
            switch (simMetricType)
            {
            case SimMetricType.BlockDistance:
                var sim2 = new BlockDistance();
                return(sim2.GetSimilarity(firstWord, secondWord));

            case SimMetricType.ChapmanLengthDeviation:
                var sim3 = new ChapmanLengthDeviation();
                return(sim3.GetSimilarity(firstWord, secondWord));

            case SimMetricType.CosineSimilarity:
                var sim4 = new CosineSimilarity();
                return(sim4.GetSimilarity(firstWord, secondWord));

            case SimMetricType.DiceSimilarity:
                var sim5 = new DiceSimilarity();
                return(sim5.GetSimilarity(firstWord, secondWord));

            case SimMetricType.EuclideanDistance:
                var sim6 = new EuclideanDistance();
                return(sim6.GetSimilarity(firstWord, secondWord));

            case SimMetricType.JaccardSimilarity:
                var sim7 = new JaccardSimilarity();
                return(sim7.GetSimilarity(firstWord, secondWord));

            case SimMetricType.Jaro:
                var sim8 = new Jaro();
                return(sim8.GetSimilarity(firstWord, secondWord));

            case SimMetricType.JaroWinkler:
                var sim9 = new JaroWinkler();
                return(sim9.GetSimilarity(firstWord, secondWord));

            case SimMetricType.MatchingCoefficient:
                var sim10 = new MatchingCoefficient();
                return(sim10.GetSimilarity(firstWord, secondWord));

            case SimMetricType.MongeElkan:
                var sim11 = new MongeElkan();
                return(sim11.GetSimilarity(firstWord, secondWord));

            case SimMetricType.NeedlemanWunch:
                var sim12 = new NeedlemanWunch();
                return(sim12.GetSimilarity(firstWord, secondWord));

            case SimMetricType.OverlapCoefficient:
                var sim13 = new OverlapCoefficient();
                return(sim13.GetSimilarity(firstWord, secondWord));

            case SimMetricType.QGramsDistance:
                var sim14 = new QGramsDistance();
                return(sim14.GetSimilarity(firstWord, secondWord));

            case SimMetricType.SmithWaterman:
                var sim15 = new SmithWaterman();
                return(sim15.GetSimilarity(firstWord, secondWord));

            case SimMetricType.SmithWatermanGotoh:
                var sim16 = new SmithWatermanGotoh();
                return(sim16.GetSimilarity(firstWord, secondWord));

            case SimMetricType.SmithWatermanGotohWindowedAffine:
                var sim17 = new SmithWatermanGotohWindowedAffine();
                return(sim17.GetSimilarity(firstWord, secondWord));

            case SimMetricType.ChapmanMeanLength:
                var sim18 = new ChapmanMeanLength();
                return(sim18.GetSimilarity(firstWord, secondWord));

            default:
                var sim1 = new Levenstein();
                return(sim1.GetSimilarity(firstWord, secondWord));
            }
        }
        public Tuple <bool, List <string> > FilterWords(string origin, int rate)
        {
            if (Regex.Replace(origin, " ", string.Empty) == "")
            {
                throw new Exception("Input is empty");
            }
            if (욕설감지리스트.Count == 0)
            {
                throw new Exception("plz call LoadWordDB() before calling");
            }
            if (rate > 100)
            {
                throw new Exception("rate should be under 100");
            }


            List <string> badWordsUsed = new List <string>();

            origin = Regex.Replace(origin, @"[\d-]|[^\w\d]", string.Empty);

            string origin2 = Divider.SliceLetter(origin);
            bool   success = false;

            if (origin2.Length < 5)
            {
                Parallel.ForEach(욕설감지리스트, (kv) =>
                {
                    if (!badWordsUsed.Contains(kv.Value.Item1))
                    {
                        string s    = kv.Key;
                        double d    = needleman.GetSimilarity(origin, s) * 100;
                        int percent = Convert.ToInt32(d);
                        Console.WriteLine($"{kv.Key}와 {percent}% 일치합니다.   ({origin})<==>({s})");
                        if (percent >= rate)
                        {
                            lock (locks)
                            {
                                badWordsUsed.Add(kv.Value.Item1); success = true;
                            }
                        }
                    }
                });
            }
            else
            {
                Parallel.ForEach(욕설감지리스트, (kv) =>
                {
                    if (!badWordsUsed.Contains(kv.Value.Item1))
                    {
                        string s    = Divider.SliceLetter(kv.Key);
                        double d    = smithWaterMan.GetSimilarity(origin2, s) * 100;
                        int percent = Convert.ToInt32(d);
                        Console.WriteLine($"{kv.Key}와 {percent}% 일치합니다.   ({origin2})<==>({s})");
                        if (percent >= rate)
                        {
                            badWordsUsed.Add(kv.Value.Item1); success = true;
                        }
                    }
                });
            }
            return(Tuple.Create <bool, List <string> >(success, badWordsUsed));
        }