Generate a rule for the given token.
(token, distribution, base_biases, temperature, rng, dynamic)
| 254 | |
| 255 | |
| 256 | def generate_rule(token, distribution, base_biases, temperature, rng, dynamic): |
| 257 | """Generate a rule for the given token.""" |
| 258 | biases = base_biases.copy() |
| 259 | length = rng.integers(3, 20) |
| 260 | production = "" |
| 261 | for _ in range(length): |
| 262 | alpha = 1.5 |
| 263 | biases[token] *= alpha |
| 264 | new_token = generate_rhs_token(distribution, biases, rng, temperature, dynamic, alpha) |
| 265 | if new_token == token: |
| 266 | biases[token] = 1 |
| 267 | production += new_token |
| 268 | # TODO: Close any unmatched pops, pushes or drawing toggles. |
| 269 | # Prepend ['s and d's. Append ]'s and D's. Only add up to one 'd' or 'D'. |
| 270 | return production |
| 271 | |
| 272 | |
| 273 | def pairwise(iterable): |
no test coverage detected