tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,30 @@
|
|||
require'strings regex'
|
||||
|
||||
markovLexer =: verb define
|
||||
rules =. LF cut TAB&=`(,:&' ')}y
|
||||
rules =. a: -.~ (dltb@:{.~ i:&'#')&.> rules
|
||||
rules =. 0 _1 {"1 '\s+->\s+' (rxmatch rxcut ])S:0 rules
|
||||
(,. ] (}.&.>~ ,. ]) ('.'={.)&.>)/ |: rules
|
||||
)
|
||||
|
||||
|
||||
replace =: dyad define
|
||||
'index patternLength replacement'=. x
|
||||
'head tail' =. index split y
|
||||
head, replacement, patternLength }. tail
|
||||
)
|
||||
|
||||
matches =: E. i. 1:
|
||||
|
||||
markov =: dyad define
|
||||
ruleIdx =. 0 [ rules =. markovLexer x
|
||||
while. ruleIdx < #rules do.
|
||||
'pattern replacement terminating' =. ruleIdx { rules
|
||||
ruleIdx =. 1 + ruleIdx
|
||||
if. (#y) > index =. pattern matches y do.
|
||||
y =. (index ; (#pattern) ; replacement) replace y
|
||||
ruleIdx =. _ * terminating
|
||||
end.
|
||||
end.
|
||||
y
|
||||
)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
m1 =. noun define
|
||||
# This rules file is extracted from Wikipedia:
|
||||
# http://en.wikipedia.org/wiki/Markov_Algorithm
|
||||
A -> apple
|
||||
B -> bag
|
||||
S -> shop
|
||||
T -> the
|
||||
the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
)
|
||||
|
||||
m1 markov 'I bought a B of As from T S.'
|
||||
I bought a bag of apples from my brother.
|
||||
Loading…
Add table
Add a link
Reference in a new issue