-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocab.jl
47 lines (43 loc) · 1.02 KB
/
vocab.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const COPY_SYMBOLS = (-1:9...)
const REVERSE_SYMBOLS = (-2:9...)
const WALK_SYMBOLS = (-4:9...)
const SYMBOLS = (0:9...)
const NO_SYMBOL = -1
const WRITE = "write"
const NOT_WRITE = "not-write"
const TAPE_ACTIONS = ("mr","ml")
const GRID_ACTIONS = ("mr","ml")
const WRITE_ACTIONS = (WRITE, NOT_WRITE)
const STOP_ACTION = ("<s>", NOT_WRITE)
function get_symbols(task)
if in(task,("copy","reverse","walk"))
return eval(parse(uppercase(string(task,"_symbols"))))
end
return SYMBOLS
end
function get_actions(task)
actions = nothing
if in(task,("copy","reverse"))
actions = TAPE_ACTIONS
else
actions = GRID_ACTIONS
end
retval = []
for ma in actions
for wa in WRITE_ACTIONS
push!(retval, (ma,wa))
end
end
return [retval..., STOP_ACTION]
end
function initvocab(symbols)
symbols = collect(symbols)
s2i, i2s = Dict(), Dict()
c = 1
for sym in symbols
s2i[sym] = c
i2s[c] = sym
c += 1
end
return s2i, i2s
end