Exemplo n.º 1
0
        static double FindCosignTotal(Person person)
        {
            CosineSimilarity sim       = new CosineSimilarity();
            double           fNameval  = sim.GetSimilarity(fName, person.FirstName.ToLower());
            double           LNameval  = sim.GetSimilarity(LName, person.LastName.ToLower());
            double           fNameval1 = sim.GetSimilarity(fName, person.LastName.ToLower());
            double           LNameval1 = sim.GetSimilarity(LName, person.FirstName.ToLower());

            return(fNameval + LNameval + fNameval1 + LNameval1);
        }
Exemplo n.º 2
0
        public double CheckSimilarity()
        {
            var list = u.Repository <Question>().GetAll().ToList();

            //double[] results = new double[list.Count];

            //for (int i = 0; i < list.Count; i++)
            //{
            //    //results[i] = 100 - StringSimilarity.LevenshteinCaculate(list[0].QuestionContent, list[i].QuestionContent) * 100 / list[0].QuestionContent.Length;
            //    //results[i] = StringSimilarity.RateSimilarity(list[0].QuestionContent, list[i].QuestionContent);
            //    //var sim = new CosineSimilarity();
            //    //var sim = new JaccardSimilarity();
            //    var sim = new DiceSimilarity();
            //    results[i] = sim.GetSimilarity(list[0].QuestionContent, list[i].QuestionContent);
            //}
            //var sim = new DiceSimilarity();
            var sim = new CosineSimilarity();
            //var sim = new OverlapCoefficient();
            //var sim = new BlockDistance();
            //var sim = new ChapmanLengthDeviation(); // neu cau ngan qua thi xac xuat cao cung chua chac la giong nhau
            //var sim = new MongeElkan();// tham chieu tu Jaro Winkler https://cs.stackexchange.com/questions/32530/a-reference-for-pseudocode-for-monge-elkan-algorithm
            //var sim = new SmithWatermanGotohWindowedAffine();
            //double result = sim.GetSimilarity("What is software engineering", "software engineering is __");
            //double result = sim.GetSimilarity("i bit a dog", "a dog bit me");
            double result = sim.GetSimilarity("By switching on and off, the __ can be used to represent the 1s and 0s that are foundation of all that goes on in the computer",
                                              "what can be used to represent the on and off that are foundation of all that goes on in the computer?");

            return(result);
        }
        public void GetSimilarity_TwoDifferentVectors_ExpectedResult()
        {
            CosineSimilarity cs = new CosineSimilarity();
            Article          x  = new Article();
            Article          y  = new Article();

            x.Vector[1] = 1;
            x.Vector[2] = 3;
            x.Vector[3] = 5;

            y.Vector[1] = 2;
            y.Vector[2] = 4;
            y.Vector[5] = 3;

            double expected = 0.43943537440204113472653679374377;
            double actual   = cs.GetSimilarity(x, y);

            Assert.IsTrue(Math.Abs(expected - actual) < 0.001);
        }
Exemplo n.º 4
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));
            }
        }