Talk:Execute a Markov algorithm: Difference between revisions

m
(Inconsistent/invalid examples?)
 
(6 intermediate revisions by 5 users not shown)
Line 4:
:I put it in Extended BNF notation which is more precise than the format in the WP article, and it is a standard for representing grammars. There's only two main differences: the WP version has quotes, which aren't really necessary; and this one allows for comments using #. --[[User:Rob.s.brit|Rob.s.brit]] 16:21, 15 December 2009 (UTC)
: (I originally wrote this early this morning, but I didn't notice an edit conflict with the J talk addition before I went to work.) While EBNF is pretty common (and interesting on its own), I can't help but wonder if the parsing of the Markov rules should be distinct pieces of funtionality. I.e. some [[Parse EBNF]], and a [[Execute Markov Algorithm]]. The particulars of parsing EBNF seem irrelevant to Markov chains themselves. While there are broad tasks on RC (such as [[RCRPG]] and a few interpreters), they're usually not created until after the individual concepts have places elsewhere. --[[User:Short Circuit|Michael Mol]] 08:17, 16 December 2009 (UTC)
 
:: I also changed the '''rulesets'''   (from the existing faux language entries)   into (bold) section headers into the (true) task preamble.   This fixed the "dual" numbering that was in effect, and also placed the TOC (table of contents) into the correct location.   -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 04:41, 20 July 2016 (UTC)
 
==J==
Line 209 ⟶ 211:
==Inconsistent/invalid examples?==
The rule for <rule> seems to indicate NO <whitespace> in a pattern but that isn't consistent with the examples. If a pattern can contain <whitespace>, then "->.* -> money" conflicts with "the shop -> my brother" because "<pattern> <whitespace> -> <whitespace>" is going to break on one or the other when trying to find <pattern> ("->.*"/"the" or ""/"the shop"???).
: <pattern> doesn't seem to be defined. It can definitely contain whitespace. The regex engine will notice that the whitespace after "the" isn't followed by an arrow and will include it in the capture, and continue to look for a whitespace followed by an arrow further down the line. [[User:Fwend|Fwend]] ([[User talk:Fwend|talk]]) 22:34, 1 June 2014 (UTC)
::You are correct, <pattern> isn't defined, and it took me several tries to figure out a definition due to the ambiguities. Which was annoying. Your RE engine may work that way, mine doesn't.
:::<pattern> ::= <any char>+
:::<replacement> ::= <pattern>
:::<rtoken> ::= first <1whitespace> -> <1whitespace>
:::<rule> ::= <pattern> <rtoken> [.] <replacement>
::This also clarifies that "foo ->" is an invalid <rule> but introduces other ambiguities.
 
==Dictionary==
===Python===
Wouldn't it be simpler to use a Python dictionary object to implement the rules? For example the first set of rules would be implemented like this:
 
<pre>grammar = {'A': 'apple', 'B': 'bag', 'S': 'shop', 'T': 'the', 'the shop': 'my brother' }</pre>
 
I tried this with CoffeeScript and it yields a rather short code, which may be even shortened with the use of Python's ''iter'' method for the dictionary (the main difficulty being that only the first working rule has to be applied).
 
[[User:AlainBusser|AlainBusser]] ([[User talk:AlainBusser|talk]]) 04:17, 20 July 2016 (UTC)
 
:Hi Alain, There is a difference in the approaches in that the Python way leverages the rigorousness in the spec and makes at least that part of the spec directly executable. In what can be meticulous industries of Science and Engineering when given an executable spec it is good to automate its use in the most direct way, because as the implementation of the spec firms one can worry more on the spec itself rather than a continuing human step of spec translation which is more likely to waver, (due to job changes, holidays, alcohol abuse, ... for example :-)
 
:I guess people decide for themselves which is "simpler". Does my solution reflect badly on the Python language in comparison with others? I don't think so. For example: One criticism of Python is in how it supports regular expressions - Ruby and Perl have direct syntactical support for regular expressions; Python has the re library and r-strings. The Python example shows that despite being different, Python still has excellent support for regular expressions including the ability to use multi-line regexps with named groups.
 
:--[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 06:58, 31 July 2016 (UTC)
 
::Hi, I wouldn't say your solution reflects badly at all, if only because you used comprehensions which are usually a very elegant way of programming.
 
::Besides, I found that the use of a dictionary would not simplify much the code, as once created, the dictionary has keys which are ordered alphabetically and not in the order they were introduced. So the iteration on these keys does not usually give the intended behavior: After all the use of a dictionary would not be "simpler" as I thought it would.
 
: And this is true for CoffeeScript too: I still have to find how to program it yet...
 
[[User:AlainBusser|AlainBusser]] ([[User talk:AlainBusser|talk]]) 12:38, 1 August 2016 (UTC)