示例#1
0
        public static bool Match(string companyName, string word2)
        {
            var words = new string[2];

            if (companyName.Contains(' '))
            {
                var splits = companyName.Split(' ');
                var s      = splits.First(x => x.Length > 2);
                words[0] = s;
            }
            else
            {
                words[0] = companyName;
            }
            if (word2.Contains(' '))
            {
                var splits = word2.Split(' ');
                var s      = splits.First(x => x.Length > 2);
                words[1] = s;
            }
            else
            {
                words[1] = word2;
            }

            var similarity = LevensteinDistance.Similarity(words[0], words[1]);

            return(similarity >= .7f);
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (gjitheFjalet.Contains(txtFjala.Text.ToLower()))
            {
                MessageBox.Show("Fjala eshte shkruar mire");
            }
            else
            {
                Dictionary <string, int> rekomandimet = new Dictionary <string, int>();

                LevensteinDistance l = new LevensteinDistance();
                foreach (string fjala in gjitheFjalet)
                {
                    if (rekomandimet.ContainsKey(fjala) == false)
                    {
                        rekomandimet.Add(fjala, l.Kalkulo(txtFjala.Text.ToLower(), fjala));
                    }
                }

                foreach (KeyValuePair <string, int> fjala in rekomandimet.OrderBy(x => x.Value).Take(5))
                {
                    lstRekomandime.Items.Add(fjala.Key + " - " + fjala.Value.ToString());
                }
            }
        }
示例#3
0
        public SpellCheckerWrapper(string field, StringDistance sd)
        {
            this.field = field;

            if (sd == null)
            {
                sd = new LevensteinDistance();
            }

            spellChecker = new SpellChecker(new RAMDirectory(), sd);
            spellChecker.setAccuracy(accuracy);
        }
示例#4
0
 public void LevenshteinDistance_ShouldReturnDistanceZero_WhenOneParameterStringIsNull()
 {
     Assert.That(LevensteinDistance.Distance(null, Text2), Is.EqualTo(0));
 }
示例#5
0
 public void LevenshteinDistance_ShouldReturnDistanceSecondLenght_WhenFirstStringIsEmpty()
 {
     Assert.That(LevensteinDistance.Distance(string.Empty, Text2), Is.EqualTo(Text2.Length));
 }
示例#6
0
 public void LevenshteinDistance_ShouldReturnDistanceFirstLength_WhenSecondStringIsEmpty()
 {
     Assert.That(LevensteinDistance.Distance(Text1, string.Empty), Is.EqualTo(Text1.Length));
 }
示例#7
0
 public void LevenshteinPercentage_ShouldReturnDistanceOne_WhenTwoStringHave80Percent()
 {
     Assert.That(LevensteinDistance.Percentage(Text1, Text2), Is.EqualTo(Percentage));
 }
示例#8
0
 public void LevenshteinDistance_ShouldReturnDistanceOne_WhenTwoStringHaveOneDifference()
 {
     Assert.That(LevensteinDistance.Distance(Text1, Text2), Is.EqualTo(Distance));
 }