Exemplo n.º 1
0
        public void CatchWordSwaps() {
            var source = SimpleTokeniser.Tokenise("how now brown cow");
            var target = SimpleTokeniser.Tokenise("how brown now cow");

            var ld2 = new LevenshteinDistance();
            Assert.AreEqual(1, ld2.DamerauLevenshteinDistance(source.ToArray(), target.ToArray()));

            LevenshteinDistance ld = new LevenshteinDistance();
            Assert.AreEqual(2, ld.Computer(source.ToArray(), target.ToArray()));
        }
Exemplo n.º 2
0
        static void Main(string[] args) {
            //Console.ReadLine();
            var source = SimpleTokeniser.Tokenise("how now brown cow").ToArray();
            var target = SimpleTokeniser.Tokenise("how brown now cow").ToArray();
            const int reps = 1000000;

            var ld = new LevenshteinDistance();
            for (int i = 0; i < reps; i++) {
                ld.DamerauLevenshteinDistance(source, target);
            }
            Console.Out.WriteLine(".");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void TestDamerauLevenshteinDistance()
        {
            var extionsionname = "pDf";
            var regex          = new Regex(@".*\.pdf?$");

            var inputFileName = new string[] { "abc", "abc.PdF.pdf.pdf", "abc.pddf", ".pdf", "pdf", "abc.pd", "abcpdf", "abc.pdf", "abc.PDF", "abc.PdF", "abc.pd", "abc.pf", "abc.df" };

            foreach (var item in inputFileName)
            {
                var result = LevenshteinDistance.DamerauLevenshteinDistance(item, extionsionname);
                //StringAssert.Matches(result, regex);
                //Assert.IsTrue(myCollection.Any(a => a > min));
                Assert.IsTrue(result < 200);
            }
        }
Exemplo n.º 4
0
        public void RaceTime() {
            var source = SimpleTokeniser.Tokenise("how now brown cow").ToArray();
            var target = SimpleTokeniser.Tokenise("how brown now cow").ToArray();
            const int reps = 1000000;

            DateTime a = DateTime.Now;
            LevenshteinDistance ldd = new LevenshteinDistance();
            for (int i = 0; i < reps; i++) {
                ldd.DamerauLevenshteinDistance(source, target);
            }
            var b = DateTime.Now - a;

            DateTime c = DateTime.Now;
            LevenshteinDistance ld = new LevenshteinDistance();
            for (int i = 0; i < reps; i++) {
                ld.Computer(source, target);
            }
            var d = DateTime.Now - c;

            Assert.IsTrue(b > d);
        }
Exemplo n.º 5
0
        public void CharacterTest() {
            var s = CharacterTokeniser.Tokenise("abcdef").ToArray();
            var t = CharacterTokeniser.Tokenise("abdcef").ToArray();

            LevenshteinDistance ld = new LevenshteinDistance();
            Assert.AreEqual(1, ld.DamerauLevenshteinDistance(s, t));
        }
Exemplo n.º 6
0
        public void LengthTests() {
            var shorter = SimpleTokeniser.Tokenise("foo bar baz bone dog cow cat frog").ToArray();
            var longer = SimpleTokeniser.Tokenise("foo bar baz bone dog sheep cow cat frog").ToArray();

            LevenshteinDistance ld = new LevenshteinDistance();
            Assert.AreEqual(1, ld.DamerauLevenshteinDistance(shorter, longer));
            Assert.AreEqual(1, ld.DamerauLevenshteinDistance(longer, shorter));

            var x = longer.ToList();
            x.Add(new Token("mouse", 0, 0));
            x.RemoveAt(1);
            longer = x.ToArray();

            Assert.AreEqual(3, ld.DamerauLevenshteinDistance(shorter, longer));
            Assert.AreEqual(3, ld.DamerauLevenshteinDistance(longer, shorter));
        }