Talk:Execute a Markov algorithm: Difference between revisions

→‎J: strikeout notes on original version, which has been replaced with fully functional (if ugly) version from talk page
(→‎J: strikeout notes on original version, which has been replaced with fully functional (if ugly) version from talk page)
Line 6:
 
==J==
 
I just slapped together the [[Markov Algorithm#J|J solution]] in 20 seconds, so it doesn't fully implement a Markov evaluator. In particular, it doesn't handle terminating rules; there may be other small wrinkles, but that depends on how one interprets the (underspecified) BNF grammar. All would be trivial to fix, but I don't have time now. Anyway, here are the gaps I think of:
 
# Terminating rules are not handled. The fix is easy but would involve modification or duplication of a standard function, [http://www.jsoftware.com/trac/base/browser/branches/cdb/main/main/strings.ijs?rev=418#L239 stringreplace].
# Similarly, according to [[wp:Markov algorithm|WP]], <blockquote> if [a rule is matched], replace the '''leftmost''' matching text in the input string with its replacement in the first applicable rule.</blockquote> But stringreplace will replace '''all''' instances of matches at once. Again, a trivial fix as long as we're willing to reprise stringreplace.
# <s>The standard function [http://www.jsoftware.com/trac/base/browser/tags/j601c/api/regex/regex.ijs?rev=322&order=date#L130 rxcut] will cut on all <code>\s+->\s+</code> though the grammar calls for ignoring any of these after the first (so the replacement string may carry a <code>-></code>). Fix is trivial, where we'd probably use <code>rxE</code>instead.</s> Silly, we can just use <code>rxmatch</code> rather than <code>rxmatch'''es'''</code>. --[[User:DanBron|DanBron]] 17:47, 15 December 2009 (UTC)
# Note also that leading blanks in the rule and trailing blanks in the replacement are removed -- the grammar doesn't call for this. Very trivial fix.
 
I just realized it took me longer to write up the description of these gaps than it would've taken me to fix them. :P --[[User:DanBron|DanBron]] 16:27, 15 December 2009 (UTC)
 
=== explicit vs tacit ===
 
Line 102 ⟶ 92:
===Markov a specific form of Rewriting scheme?===
I got lost in [http://planetmath.org/encyclopedia/MarkovAlgorithm.html this], and [http://planetmath.org/encyclopedia/MarkovAlgorithm.html this], and [[wp:rewriting|this]]. After a surfaced it seemed to me that the Markov is a specific case of more general [[wp:Rewriting|rewriting schemes]], so maybe you have been expecting the more general case? --[[User:Paddy3118|Paddy3118]] 13:07, 16 December 2009 (UTC)
 
=== original version ===
 
<s>I just slapped together the [[Markov Algorithm#J|J solution]] in 20 seconds, so it doesn't fully implement a Markov evaluator. In particular, it doesn't handle terminating rules; there may be other small wrinkles, but that depends on how one interprets the (underspecified) BNF grammar. All would be trivial to fix, but I don't have time now. Anyway, here are the gaps I think of:
 
# Terminating rules are not handled. The fix is easy but would involve modification or duplication of a standard function, [http://www.jsoftware.com/trac/base/browser/branches/cdb/main/main/strings.ijs?rev=418#L239 stringreplace].
# Similarly, according to [[wp:Markov algorithm|WP]], <blockquote> if [a rule is matched], replace the '''leftmost''' matching text in the input string with its replacement in the first applicable rule.</blockquote> But stringreplace will replace '''all''' instances of matches at once. Again, a trivial fix as long as we're willing to reprise stringreplace.
# <s>The standard function [http://www.jsoftware.com/trac/base/browser/tags/j601c/api/regex/regex.ijs?rev=322&order=date#L130 rxcut] will cut on all <code>\s+->\s+</code> though the grammar calls for ignoring any of these after the first (so the replacement string may carry a <code>-></code>). Fix is trivial, where we'd probably use <code>rxE</code>instead.</s> Silly, we can just use <code>rxmatch</code> rather than <code>rxmatch'''es'''</code>. --[[User:DanBron|DanBron]] 17:47, 15 December 2009 (UTC)
# Note also that leading blanks in the rule and trailing blanks in the replacement are removed -- the grammar doesn't call for this. Very trivial fix.
 
I just realized it took me longer to write up the description of these gaps than it would've taken me to fix them. :P --[[User:DanBron|DanBron]] 16:27, 15 December 2009 (UTC)</s>
 
The above comments applied to the original version <lang j>require'strings regex'
NB. Lex a Markov program
markovLexer =: verb define
rules =. LF cut TAB&=`(,:&' ')}y
rules =. a: -.~ (dltb@:{.~ i:&'#')&.> rules
0 _1 {"1 '\s+->\s+' (rxmatch rxcut ])S:0 rules
)
NB. Given ruleset and target string, output
NB. result.
markov =: markovLexer@[ stringreplace^:_ ]
NB. Same as above, but output all intermediate
NB. evaluations
markovDebug =: markovLexer@[ stringreplace^:a: ]</lang> ... which has since been replaced.
Anonymous user