Exemple #1
0
    public string GenerateStory()
    {
        string result = "";

        int        wordCount     = 0;
        PrefixWord currentPrefix = new PrefixWord(2);
        SuffixWord currentSuffix;

        do
        {
            currentSuffix = table.GetSuffixOf(currentPrefix);

            if (currentSuffix.value != "*")
            {
                result += currentSuffix.value + " ";
            }
            else
            {
                result += '\n';
            }

            currentPrefix.Add(currentSuffix.value);
            wordCount++;
        } while (/*currentSuffix.value != "*" && */ wordCount < maxWords);

        return(result);
    }
Exemple #2
0
    public void BuildDatabase()
    {
        PrefixWord currentPrefix = new PrefixWord(2);

        char[]   delimiterChars = { ' ', '\t', '\n', '\r' };
        string[] words          = sample.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);

        //string pattern = @"\s?";
        //string[] words = Regex.Split (sample, pattern);

        for (int i = 0; i <= words.Length; i++)
        {
            string     next          = i < words.Length ? words[i] : "*";
            SuffixWord currentSuffix = new SuffixWord(next);
            AddToDatabase(currentPrefix, currentSuffix);
            currentPrefix.Add(next);
        }

        SaveDatabase();
        LoggerTool.Post("Finished building story database!");
    }