Created
May 14, 2015 12:35
-
-
Save ivoras/2d7737c214c3dc937c28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.algorithm, std.container, std.conv, std.regex, std.stdio, std.string; | |
Array!string [string] markov; | |
int main(string[] args) | |
{ | |
static rx = regex("[ \r\n\t,.!?@#\"'*_()\\[\\]{}+=:;/-]+"); | |
auto prev_token = ""; | |
foreach (c_line; stdin.byLine()) { | |
auto line = to!string(c_line); | |
string[] tokens = split(line.replace("„", "").replace("“", ""), rx); | |
foreach (tok; tokens) { | |
if (tok.length == 0) | |
continue; | |
auto token = toLower(tok); | |
if (prev_token in markov) { | |
markov[prev_token].insert(token); | |
} else { | |
markov[prev_token] = Array!string([token]); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment