Esempio n. 1
0
        private void TestDecrementChainCount()
        {
            _markovChainString = new MarkovChainNodeString(typeof(MCStorageString), true, _onDiskDirectoryBasePath, null);
            MarkovChainString mostMarkovChainUsingStrings = null;

            AddMarkovChainString(Preprocess("I love Hawaii.", int.MaxValue), true, null);
            AddMarkovChainString(Preprocess("I love Hawaii.", int.MaxValue), true, null);
            AddMarkovChainString(Preprocess("I love Hawaii.", int.MaxValue), true, null);
            AddMarkovChainString(Preprocess("I love Hawaii.", int.MaxValue), true, null);
            AddMarkovChainString(Preprocess("I love Hawaii.", int.MaxValue), true, null);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 15);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 12);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 9);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 6);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 3);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love Hawaii.", true, false);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 0);
        }
Esempio n. 2
0
        private void TestPerInputNodeAttributes()
        {
            _markovChainString.Children.Clear();

            string inputString = "This string contains per node attributes.";

            MarkovChainInputString markovChainInputString = Preprocess(inputString, int.MaxValue);

            foreach (MarkovChainInputNodeString markovChainInputNodeString in markovChainInputString.Nodes)
            {
                if (markovChainInputNodeString.String.Contains("i"))
                {
                    markovChainInputNodeString.Attributes.Add("perNodeAttribute", 1);
                }
            }

            Dictionary <string, double> globalAttributes = new Dictionary <string, double>();

            globalAttributes.Add("globalAttribute1", 1);
            globalAttributes.Add("globalAttribute2", 1);

            AddMarkovChainString(markovChainInputString, false, globalAttributes);

            MarkovChainString markovChainString = GetMarkovChainString(inputString, false, false);
        }
Esempio n. 3
0
        private void TestChainRecallWithReset()
        {
            _markovChainString = new MarkovChainNodeString(typeof(MCStorageString), true, _onDiskDirectoryBasePath, null);
            MarkovChainString mostMarkovChainUsingStrings = null;

            Dictionary <string, double> hikingAttributes = new Dictionary <string, double>();

            hikingAttributes.Add("hiking", 1);
            hikingAttributes.Add("bacon", 0);

            AddMarkovChainString(Preprocess("I love hiking.", int.MaxValue), false, hikingAttributes);
            AddMarkovChainString(Preprocess("I love hiking.", int.MaxValue), false, hikingAttributes);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love hiking.", false, false);
#if DEBUG
            Debug.Assert(mostMarkovChainUsingStrings.ToString().StartsWith("String: i love hiking"));

            Debug.Assert(mostMarkovChainUsingStrings.Nodes.Sum(_ => _.Attributes["hiking"]) == 6);
            Debug.Assert(mostMarkovChainUsingStrings.Nodes.Sum(_ => _.Attributes["bacon"]) == 0);
#endif
            /**/

            ResetString();

            /**/

            Dictionary <string, double> baconAttributes = new Dictionary <string, double>();
            baconAttributes.Add("hiking", 0);
            baconAttributes.Add("bacon", 1);

            AddMarkovChainString(Preprocess("I love bacon.", int.MaxValue), false, baconAttributes);
            AddMarkovChainString(Preprocess("I love bacon.", int.MaxValue), false, baconAttributes);

            mostMarkovChainUsingStrings = GetMarkovChainString("I love bacon.", false, false);
#if DEBUG
            Debug.Assert(mostMarkovChainUsingStrings.ToString().StartsWith("String: i love bacon"));

            Debug.Assert(mostMarkovChainUsingStrings.Nodes.Sum(_ => _.Attributes["hiking"]) == 0);
            Debug.Assert(mostMarkovChainUsingStrings.Nodes.Sum(_ => _.Attributes["bacon"]) == 6);
#endif
        }
Esempio n. 4
0
        private void TestDirectoryStress()
        {
            _markovChainString.Children.Clear();
            MarkovChainString mostMarkovChainUsingStrings = null;

            char[] directoryName = new char[3];
            for (int i = 0; i < directoryName.Length; i++)
            {
                directoryName[i] = 'a';
            }

            int           pointer        = directoryName.Length - 1;
            bool          loop           = true;
            string        directoryName2 = null;
            int           numberOfWords  = 0;
            int           numberOfWordsPerInputString = 20;
            StringBuilder stringBuilder = new StringBuilder();

            int numberOfDirectories = 0;

            Stopwatch stopwatch = new Stopwatch();

            while (loop)
            {
                directoryName2 = new string(directoryName);
                numberOfDirectories++;

                stringBuilder.Append(directoryName2 + " ");
                numberOfWords++;

                if (numberOfWords == numberOfWordsPerInputString)
                {
                    stopwatch.Start();
                    AddMarkovChainString(Preprocess(stringBuilder.ToString(), int.MaxValue), false, null);

                    string   input      = stringBuilder.ToString();
                    string[] inputSplit = input.Split(" ".ToCharArray());

                    mostMarkovChainUsingStrings = GetMarkovChainString(inputSplit[0], false, true);
                    stopwatch.Stop();
#if DEBUG
                    if (numberOfDirectories % 100 == 0)
                    {
                        Console.WriteLine(numberOfDirectories / stopwatch.Elapsed.TotalSeconds + "/sec. :: " + numberOfDirectories);
                    }
#endif
                    if (!_isCaseSensitive)
                    {
                        Debug.Assert(mostMarkovChainUsingStrings.String == input.ToLowerInvariant().TrimEnd());
                    }
                    else
                    {
                        Debug.Assert(mostMarkovChainUsingStrings.String == input.TrimEnd());
                    }

                    stringBuilder.Remove(0, stringBuilder.Length);
                    numberOfWords = 0;
                }

                /**/

                directoryName[pointer]++;

                while (directoryName[pointer] > 'z')
                {
                    if (pointer == 0)
                    {
                        loop = false;
                        break;
                    }

                    directoryName[pointer] = 'a';
                    if (pointer - 1 >= 0)
                    {
                        directoryName[pointer - 1]++;
                        pointer--;
                    }
                }
                pointer = directoryName.Length - 1;
            }
        }

        private void TestLongPaths()
        {
            _markovChainString.Children.Clear();
            MarkovChainString mostMarkovChainUsingStrings = null;

            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < 1000; i++)
            {
                stringBuilder.Append("Long ");
            }

            AddMarkovChainString(Preprocess(stringBuilder.ToString(), int.MaxValue), false, null);

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("Long", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == stringBuilder.ToString().ToLowerInvariant().TrimEnd());
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == stringBuilder.ToString().TrimEnd());
            }
        }
Esempio n. 5
0
        private void TestLongFormInput()
        {
            _markovChainString.Children.Clear();
            MarkovChainString mostMarkovChainUsingStrings = null;

            int numberOfExemplars = 0;

            Stopwatch stopwatch = new Stopwatch();

            int numberOfLinesToTake = 1000;

            foreach (string line in File.ReadAllLines("TextDatabases\\Dracula.txt").Take(numberOfLinesToTake))
            {
                string line2 = string.Join(" ", UserDefinedFunctions.ExtractWords(line, true, false).Cast <string>().ToArray());

                if (string.IsNullOrEmpty(line2))
                {
                    continue;
                }

                numberOfExemplars++;

                stopwatch.Start();
                AddMarkovChainString(Preprocess(line2, int.MaxValue), false, null);

                mostMarkovChainUsingStrings = GetMarkovChainString(line2, false, false);
                stopwatch.Stop();
#if DEBUG
                if (numberOfExemplars % 100 == 0)
                {
                    Console.WriteLine("TestLongFormInput: R/W :: " + (numberOfExemplars / stopwatch.Elapsed.TotalSeconds) + "/sec. :: " + numberOfExemplars);
                }
#endif
                if (!_isCaseSensitive)
                {
                    Debug.Assert(mostMarkovChainUsingStrings.String == line2.ToLowerInvariant().TrimEnd());
                }
                else
                {
                    Debug.Assert(mostMarkovChainUsingStrings.String == line2.TrimEnd());
                }
            }

            _markovChainString.Children.Clear();

            numberOfExemplars = 0;
            stopwatch.Reset();

            foreach (string line in File.ReadAllLines("TextDatabases\\Dracula.txt").Take(numberOfLinesToTake))
            {
                string line2 = string.Join(" ", UserDefinedFunctions.ExtractWords(line, true, false).Cast <string>().ToArray());

                if (string.IsNullOrEmpty(line2))
                {
                    continue;
                }

                numberOfExemplars++;

                stopwatch.Start();
                AddMarkovChainString(Preprocess(line2, int.MaxValue), false, null);
                stopwatch.Stop();
#if DEBUG
                if (numberOfExemplars % 100 == 0)
                {
                    Console.WriteLine("TestLongFormInput: W :: " + (numberOfExemplars / stopwatch.Elapsed.TotalSeconds) + "/sec. :: " + numberOfExemplars);
                }
#endif
            }

            numberOfExemplars = 0;
            stopwatch.Reset();

            foreach (string line in File.ReadAllLines("TextDatabases\\Dracula.txt").Take(numberOfLinesToTake))
            {
                string line2 = string.Join(" ", UserDefinedFunctions.ExtractWords(line, true, false).Cast <string>().ToArray());

                if (string.IsNullOrEmpty(line2))
                {
                    continue;
                }

                numberOfExemplars++;

                stopwatch.Start();
                mostMarkovChainUsingStrings = GetMarkovChainString(line2, false, false);
                stopwatch.Stop();
#if DEBUG
                if (numberOfExemplars % 100 == 0)
                {
                    Console.WriteLine("TestLongFormInput: R :: " + (numberOfExemplars / stopwatch.Elapsed.TotalSeconds) + "/sec. :: " + numberOfExemplars);
                }
#endif
                if (!_isCaseSensitive)
                {
                    Debug.Assert(mostMarkovChainUsingStrings.String == line2.ToLowerInvariant().TrimEnd());
                }
                else
                {
                    Debug.Assert(mostMarkovChainUsingStrings.String == line2.TrimEnd());
                }
            }
        }
Esempio n. 6
0
        private void TestBaseline()
        {
            _markovChainString.Children.Clear();
            MarkovChainString mostMarkovChainUsingStrings = null;

            //test simple and w/o Attributes...
            AddMarkovChainString(Preprocess("I love.", int.MaxValue), false, null);
            AddMarkovChainString(Preprocess("I love.", int.MaxValue), false, null);
            AddMarkovChainString(Preprocess("I like.", int.MaxValue), false, null);

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("I", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 5);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCountTotal == 6);
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "i love");
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "I love");
            }

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("I love", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 5);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCountTotal == 6);
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "i love");
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "I love");
            }

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("I like", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 4);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCountTotal == 6);
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "i like");
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "I like");
            }

            /**/

            _markovChainString = new MarkovChainNodeString(typeof(MCStorageString), true, _onDiskDirectoryBasePath, null);

            //test with Attributes...
            Dictionary <string, double> attributes = new Dictionary <string, double>();
            attributes.Add("Attribute3", 3);
            attributes.Add("Attribute1", 1);

            AddMarkovChainString(Preprocess("I love cats more than I love dogs.", int.MaxValue), false, attributes); //3,3,2,2,2,2
            AddMarkovChainString(Preprocess("I love cats more than I love dogs.", int.MaxValue), false, attributes);
            AddMarkovChainString(Preprocess("I love dogs more than I love cats.", int.MaxValue), false, attributes);

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("I love", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 18);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCountTotal == 19);
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "i love cats more than i love dogs");
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "I love cats more than I love dogs");
            }

            /**/

            mostMarkovChainUsingStrings = GetMarkovChainString("I love cats", false, true);

#if DEBUG
            Console.WriteLine(mostMarkovChainUsingStrings.String + " :: " + mostMarkovChainUsingStrings.ChainCount);
#endif
            Debug.Assert(mostMarkovChainUsingStrings.ChainCount == 18);
            Debug.Assert(mostMarkovChainUsingStrings.ChainCountTotal == 19);
            if (!_isCaseSensitive)
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "i love cats more than i love dogs");
            }
            else
            {
                Debug.Assert(mostMarkovChainUsingStrings.String == "I love cats more than I love dogs");
            }
        }