>>136243
For you. Right now it's capable of forming semi-coherent phrases.
It can learn from your input, or from a text file. Text files are loaded using the LOAD: command followed by the filename.
The END command quits the program.
This program is licensed to you under the BPL (Bane Posting License)
You have the right to run it, modify it, and study how it works.
You also have the right to redistribute it in binary and source form, but only to people whose head temperature does not exceed the usual limit.
Binary here, source below https://a.pomf.cat/ckvkbz.7z
Binary requires .NET 3.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fgsfds {
class Program {
static readonly string[] limiters = new string[] {
"." , " " , "!" , "?" , "\n","\t" ,"(",")","&","-","=","+","/","\\",","
};
static Dictionary<string,string> links = new Dictionary<string , string>();
static List<string> wordsKnown = new List<string>();
static void Dissect( string input ) {
string last = string.Empty;
string[] splits = input.Split( limiters , StringSplitOptions.RemoveEmptyEntries );
foreach ( string str in splits ) {
if ( !links.ContainsKey( last ) & last != string.Empty ) {
links.Add( last , str );
Console.WriteLine( last + " -> " + str );
}
last = str;
string str2 = str;
// add only if not present, keep track of frequency separately
foreach ( string lim in limiters ) {
str2 = str2.Replace( lim , "" );
}
str2 = str2.ToLowerInvariant();
if ( string.IsNullOrEmpty( str2 ) || wordsKnown.Contains( str2 ) ) { continue; }
wordsKnown.Add( str2 );
Console.WriteLine( str2 );
}
}
static string Babble() {
if ( wordsKnown.Count < 2 ) {
return "...";
}
Random r = new Random();
StringBuilder stb = new StringBuilder();
int count = Math.Min( wordsKnown.Count - 1 , r.Next( 16 ) + 2 );
const char space = ' ';
int z = r.Next( wordsKnown.Count - 1 );
string roll = wordsKnown[z];
//string initWord = roll;
string lastWord = roll;
for ( int i = 0 ; i < count ; i++ ) {
if ( links.ContainsKey( lastWord ) & r.Next( 4 ) != 1 ) {
roll = links[lastWord];
} else {
z = r.Next( wordsKnown.Count - 1 );
roll = wordsKnown[z];
}
if ( lastWord == roll ) {
continue;
}
lastWord = roll;
stb.Append( space + roll );
}
stb.Append( '.' ); // polite shitposting
return stb.ToString();
}
static void Main( string[] args ) {
while ( true ) {
string str;
Console.ForegroundColor = ConsoleColor.Cyan;
str = Console.ReadLine();
if ( str == "END" ) { break; }
if ( str.StartsWith( "LOAD" ) ) {
string filename = str.Split( ':' )[1];
if ( System.IO.File.Exists( filename ) ) {
Dissect( System.IO.File.ReadAllText( filename ) );
continue;
}
}
//Echo
//Console.WriteLine( str );
// Devour the input
Dissect( str );
Console.ForegroundColor = ConsoleColor.Magenta;
// Say something
Console.WriteLine( Babble() );
}
}
}
}