-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLanguage.elm
124 lines (105 loc) · 2.07 KB
/
Language.elm
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module Language exposing (Language, Word, generate, decode, wordFor)
import Util
import Idea exposing (Idea)
import Random exposing (Generator)
import String
type Word = Root Idea String
type alias Language = List Word
syllables =
[ "ae"
, "al"
, "au"
, "ch"
, "de"
, "ea"
, "el"
, "en"
, "ep"
, "es"
, "eu"
, "jo"
, "li"
, "ll"
, "lm"
, "lo"
, "ma"
, "mne"
, "mu"
, "no"
, "nu"
, "oe"
, "oh"
, "oi"
, "or"
, "ru"
, "ry"
, "sa"
, "sho"
, "thi"
, "us"
]
-- init
init : Idea -> String -> Word
init idea description =
Root idea description
secret =
Root Idea.holy "???"
-- translation
decode : Idea -> Language -> Language -> String
decode idea known model =
let
knownIdea =
known
|> List.any (\(Root idea' _) -> idea == idea')
in if knownIdea then
Idea.describe idea
else
model
|> foreignWordFor idea
foreignWordFor : Idea -> Language -> String
foreignWordFor idea model =
model
|> List.filter (\(Root idea' _) -> idea == idea')
|> List.map (\(Root _ word) -> word)
|> List.head
|> Maybe.withDefault "???"
wordFor : Idea -> Language -> Word
wordFor idea model =
model
|> List.filter (\(Root idea' _) -> idea == idea')
|> List.head
|> Maybe.withDefault secret
-- generation
generateSyllable : Generator String
generateSyllable =
let
pickSyllable = \idx ->
Util.getAt syllables idx
|> Maybe.withDefault "zz"
randomIdx =
Random.int 0 (List.length syllables-1)
in
Random.map pickSyllable randomIdx
generateWord : Generator String
generateWord =
let
randomCount =
Random.int 2 3
syllableList =
Random.list 10 generateSyllable
constructWord = \ls ct ->
ls
|> List.take ct
|> String.join ""
in
Random.map2 constructWord syllableList randomCount
generateWords : Generator (List String)
generateWords =
Random.list (List.length Idea.ideas) generateWord
generate : Generator Language
generate =
let
expression = \words ->
List.map2 init Idea.ideas words
in
Random.map expression generateWords