markov - run Markov Algorithms
Steffen Mueller, mail at steffen-mueller dot net
Copyright (c) 2002 Steffen Mueller. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Please see the Perl Artistic License.
The currently documented version is 1.02.
markov -rules FILENAME -string 'STRING' [-help -manual]
-help displays this synopsis.
-manual displays the full manual.
-rules FILENAME specifies a text file containing rule definitions.
-string 'STRING' specifies a string to apply the rules to. Note
that the quotation marks should be double quotes (") in Windows
environments.
-verbose turns on verbose output (default). -noverbose turns it off.
Please also see the full manual for very important details. I suppose you won't be able to use this program without having skimmed the manual beforehand.
Whitespace in both rule file and string is ignored! The formal epsilon
(empty string) is, symbolized by \e. .correct and .fail symbolize
their formal counterparts. ".", "-" and "\" are illegal characters in both
rules and strings unless they are used in their respective special meaning.
(You can't assume I'm doing any extra fancy parsing work!) \e may only
appear on the left side of a rule and must be the only token on the left
side. .correct and .fail may only appear on the right side.
If you introduce characters that were not used in the original string, it is your task to remove them from the resulting string. I chose not to have them removed from the resulting string because they can be of great help when debugging your algorithm. Removing them, however, is trivial. I suggest you just use capital letters in the input and lower case letters as tokens introduced in the rules.
Given a file rules.txt that looks like this:
BAa -> AaB aBB -> BaB aAA -> AaA aAB -> AaB aBA -> AaB a -> .correct \e -> a
You may run markov like this:
markov -rules rules.txt -string BAAABBA -verbose
You will get this output:
Compiling rules. Interpreting rules. Source string: 'BAAABBA' Step 1: 'BAAABBA' -> 'aBAAABBA' (Rule 7). Step 2: 'aBAAABBA' -> 'AaBAABBA' (Rule 5). Step 3: 'AaBAABBA' -> 'AAaBABBA' (Rule 5). Step 4: 'AAaBABBA' -> 'AAAaBBBA' (Rule 5). Step 5: 'AAAaBBBA' -> 'AAABaBBA' (Rule 2). Step 6: 'AAABaBBA' -> 'AAABBaBA' (Rule 2). Step 7: 'AAABBaBA' -> 'AAABBAaB' (Rule 5). Step 8: 'AAABBAaB' -> 'AAABAaBB' (Rule 1). Step 9: 'AAABAaBB' -> 'AAAAaBBB' (Rule 1). Step 10: 'AAAAaBBB' -> 'AAAABaBB' (Rule 2). Step 11: 'AAAABaBB' -> 'AAAABBaB' (Rule 2). Step 12: Succeeded in rule 6. Result is 'AAAABBB'
'Nuff said.