tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,25 @@
|
|||
def markovInterpreterFor = { rules ->
|
||||
def ruleMap = [:]
|
||||
rules.eachLine { line ->
|
||||
(line =~ /\s*(.+)\s->\s([.]?)(.+)\s*/).each { text, key, terminating, value ->
|
||||
if (key.startsWith('#')) { return }
|
||||
ruleMap[key] = [text: value, terminating: terminating]
|
||||
}
|
||||
}
|
||||
[interpret: { text ->
|
||||
def originalText = ''
|
||||
while (originalText != text) {
|
||||
originalText = text
|
||||
for (Map.Entry e : ruleMap.entrySet()) {
|
||||
if (text.indexOf(e.key) >= 0) {
|
||||
text = text.replace(e.key, e.value.text)
|
||||
if (e.value.terminating) {
|
||||
return text
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
text
|
||||
}]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue