Esempio n. 1
0
        private static void Generate(String start = null, Int32 depth = 2, Int32 maxLen = 40)
        {
            if (String.IsNullOrWhiteSpace(start))
            {
                start = null;
            }

            using (new StackingArea("Generating sentence"))
                Console.WriteLine(start != null ? chain.Generate(start, depth, maxLen) : chain.Generate( ));
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string fileloc = "../../../clean_out/infowars.mkv";

            using (StreamReader reader = new StreamReader(new FileStream(fileloc, FileMode.Open)))
            {
                MarkovChain chain = MarkovChain.ReadFromStream(reader);
                using (StreamWriter output = new StreamWriter(new FileStream("outfile.txt", FileMode.Create)))
                    output.Write(chain.Generate(1000));
            }
        }
		/// <summary>
		/// Generates a new text variation based on the given sample.
		/// </summary>
		/// <param name="sample">The sample on which the variation will be based..</param>
		/// <param name="size">The size of the text to generate.</param>
		/// <param name="windowSize">Size of the window.</param>
		/// <returns></returns>
		public static string Generate(string sample, int size = 1000, int windowSize=5)
		{
			// tokenise the input string
			var seedList = new List<string>(Split(Cleanup(sample)));
			
			var chain = new MarkovChain<string>(seedList, windowSize);

			// generate a new sequence using a starting word, and maximum return size
			var generated = new List<string>(chain.Generate(size));
			// output the results to the console
			var sb = new StringBuilder();
			generated.ForEach(item => sb.Append(item));
			
			var  goodcase = ToSentenceCase(sb.ToString().Trim());
			if(!goodcase.EndsWith(".")) goodcase += ".";
			return goodcase;
		}
Esempio n. 4
0
    static void Main()
    {
        // Initialise a Markov chain of type 'char'.
        MarkovChain <char> chain = new MarkovChain <char>(3);

        // Add all the words from 'wordlist.txt' to the chain.
        foreach (string line in File.ReadLines("wordlist.txt"))
        {
            chain.AddItems(line);
        }

        // Generate and print a new word every time the return key is pressed.
        while (true)
        {
            Console.Write(string.Join("", chain.Generate()));
            Console.ReadLine();
        }
    }