public void TestDistance() { var instance = new QGram(k: 2); // AB BC CD CE // 1 1 1 0 // 1 1 0 1 // Total: 2 var result = instance.Distance("ABCD", "ABCE"); Assert.Equal(expected: 2.0, actual: result); Assert.Equal( expected: 0.0, actual: instance.Distance("S", "S"), precision: 1); // 0.0 Assert.Equal( expected: 0.0, actual: instance.Distance("012345", "012345"), precision: 1); // 0.0 // NOTE: not using null/empty tests in NullEmptyTests because QGram is different Assert.Equal(0.0, instance.Distance("", ""), 1); Assert.Equal(2.0, instance.Distance("", "foo"), 1); Assert.Equal(2.0, instance.Distance("foo", ""), 1); NullEmptyTests.AssertArgumentNullExceptions(instance); }
public void TestDistance() { var instance = new QGram(k: 2); // AB BC CD CE // 1 1 1 0 // 1 1 0 1 // Total: 2 var result = instance.Distance("ABCD", "ABCE"); Assert.Equal(expected: 2.0, actual: result); }
public void q_gram() { sayac = 0; kelimeleri_ayir(); dgrTab8.Rows.Clear(); var qGram = new QGram(2); tSql = "select kelime from kelimeler"; tCon.Open(); cmd.CommandText = tSql; tDataReader = cmd.ExecuteReader(); while (tDataReader.Read()) { sayac++; prgGenel.Value = Convert.ToInt32((100 * sayac) / prgHesap); foreach (string eleman in aList) { hesap = Convert.ToInt32((100 / eleman.Length) * ((eleman.Length + tDataReader["kelime"].ToString().Length - qGram.Distance(eleman, tDataReader["kelime"].ToString())) / 2)); if (hesap > 20) { dgrTab8.Rows.Add(eleman, hesap, tDataReader["kelime"].ToString()); tToplamQgram += hesap; adetQgram += 1; } } } tDataReader.Close(); bag_close(); dgrTab8.Sort(dgrTab8.Columns[1], ListSortDirection.Descending); //lblQgram.Text = tToplamQgram / adetQgram + "%"; //prgQgram.Value = Convert.ToInt32(tToplamQgram / Convert.ToDouble(adetQgram)); bpgrQgram.Value = Convert.ToInt32(tToplamQgram / Convert.ToDouble(adetQgram)); qgram_sonuc(); }