Ejemplo n.º 1
0
        private void recursiveLearnFromFile(FileSystemObjectInfo info, bool recurse = false)
        {
            if ((info.FileSystemInfo.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                var files = Directory.EnumerateFiles(info.FileSystemInfo.FullName, "*.*", SearchOption.TopDirectoryOnly)
                            .Where(s => s.EndsWith(".txt", StringComparison.OrdinalIgnoreCase));

                foreach (string path in files)
                {
                    FileInfo             fi   = new FileInfo(path);
                    FileSystemObjectInfo fsoi = new FileSystemObjectInfo(fi);
                    recursiveLearnFromFile(fsoi);
                }
            }
            else
            {
                try
                {
                    using (StreamReader sr = new StreamReader(info.FileSystemInfo.FullName))
                    {
                        string line = sr.ReadToEnd();
                        Markov.Train(Context, line);
                        Log("Batched file training complete");
                    }
                }
                catch (IOException ex)
                {
                    Log("Error: The file could not be read:\n" + ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        private void LearnManual()
        {
            Markov.Train(Context, LearnTextBox.Text);

            Log("Manual training complete");

            if (Context.AutoClear)
            {
                LearnTextBox.Text = "";
            }
        }
Ejemplo n.º 3
0
        private void GenerateButton_Click(object sender, RoutedEventArgs e)
        {
            string output = "";

            for (int i = 0; i < NumSentences.Value; i++)
            {
                output += Markov.Generate(Context).FirstCharToUpper() + " ";
            }
            output             += "\r\n\r\n";
            OutputTextBox.Text += output;

            Log("Generated " + NumSentences.Value + " sentences");
        }