Exemplo n.º 1
0
        /// <summary>
        /// Determines the similarity of this message to the specified subsection of another one.
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        private float GetSimilarity(Message other, float begin, float length)
        {
            double totalSimilarity = 1.0d;

            int SampleCount = 20;

            for (int i = 0; i < SampleCount; i++)
            {
                float fullPos  = (float)i / (float)(SampleCount - 1);
                float thisPos  = fullPos;
                float otherPos = begin + length * fullPos;

                LargeVector localSample = this.SampleVector(thisPos);
                LargeVector otherSample = other.SampleVector(otherPos);

                float similarity = 0.1f;
                if (!localSample.IsEmpty && !otherSample.IsEmpty)
                {
                    float lengthA = localSample.GetLength();
                    float lengthB = otherSample.GetLength();
                    similarity = LargeVector.Dot(localSample, otherSample) / (lengthA * lengthB);
                }

                totalSimilarity *= (double)similarity;
            }

            return((float)Math.Pow(totalSimilarity, 5.0d / (double)SampleCount));
        }
Exemplo n.º 2
0
        public float GetSimilarity(string wordA, string wordB)
        {
            LargeVector vecA = this.Get(wordA);

            if (vecA.IsEmpty)
            {
                return(0.0f);
            }

            LargeVector vecB = this.Get(wordB);

            if (vecB.IsEmpty)
            {
                return(0.0f);
            }

            float lengthA = vecA.GetLength();
            float lengthB = vecB.GetLength();

            return(LargeVector.Dot(vecA, vecB) / (lengthA * lengthB));
        }