Skip to content

Commit 29b4a0c

Browse files
committed
Added the "Cat Ipsum generator" to the documentation.
1 parent 5c3a0db commit 29b4a0c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

doc/usage.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,71 @@
7878
; 15
7979
; true
8080
; false)
81+
```
82+
83+
### Cat Ipsum generator
84+
85+
```clojure
86+
;; Model builder
87+
(defn ipsum-model [subjects verbs pronouns objects]
88+
(h/let ['subject (h/enum subjects)
89+
'verb (h/enum verbs)
90+
'pronoun (h/enum pronouns)
91+
'object (h/enum objects)
92+
'group (h/alt (h/cat (h/ref 'pronoun)
93+
(h/ref 'object))
94+
(h/cat (h/ref 'group)
95+
(h/enum #{"and" "with"})
96+
(h/ref 'group)))
97+
'sentence (h/cat (h/ref 'subject)
98+
(h/ref 'verb)
99+
(h/ref 'group))]
100+
(h/repeat 1 10 (h/not-inlined (h/ref 'sentence)))))
101+
102+
;; A model from the model builder
103+
(def cat-ipsum (ipsum-model #{"I"
104+
"My human"
105+
"The baby"
106+
"Bad mouses"}
107+
#{"slept on"
108+
"ate"
109+
"played with"
110+
"jumped over"
111+
"stared at"
112+
"scratched"
113+
"broke"
114+
"stretched nearby"
115+
"was singing for"
116+
"owned"}
117+
#{"the" "a" "my" "*MY*"}
118+
#{"fish" "dry food"
119+
"colorful balls" "table"
120+
"sofa" "bed"
121+
"toy" "trash"
122+
"apartment"
123+
"toilet"}))
81124

125+
;; A generator from the model
126+
(def cat-ipsum-generator
127+
(tcg/fmap (fn [sentences]
128+
(->> sentences
129+
(map (fn [sentence]
130+
(-> (str/join " " sentence)
131+
(str "."))))
132+
(str/join " ")))
133+
(mg/gen cat-ipsum 50)))
82134

135+
;; Generate data from the generator, and have fun
136+
(tcg/sample cat-ipsum-generator)
137+
;("Bad mouses broke the toilet. I scratched *MY* sofa. I slept on *MY* toilet. The baby jumped over the apartment. The baby stared at my toy. Bad mouses ate *MY* bed."
138+
; "My human was singing for a toilet. My human slept on *MY* sofa with *MY* fish. My human owned a toilet."
139+
; "My human was singing for a toilet. The baby ate *MY* trash. I owned the toy. I broke a trash. The baby jumped over my dry food. Bad mouses jumped over my sofa. I scratched the dry food."
140+
; "My human ate the colorful balls. The baby played with the sofa. My human played with the toy. The baby played with a fish. My human was singing for my toilet. The baby stared at my colorful balls. Bad mouses scratched a sofa."
141+
; "The baby stared at the fish. I broke my fish. My human ate my toilet. Bad mouses slept on a trash. The baby stretched nearby the apartment. The baby slept on my fish. I scratched *MY* sofa. My human was singing for a toy. Bad mouses ate *MY* colorful balls."
142+
; "The baby was singing for *MY* toy. Bad mouses stared at my bed. I owned the apartment. My human played with *MY* fish. Bad mouses owned my apartment. Bad mouses stretched nearby my toy. I slept on *MY* apartment. My human was singing for my dry food. Bad mouses ate a dry food."
143+
; "I broke a fish. I slept on a apartment. The baby broke the toilet. My human owned *MY* apartment. Bad mouses ate *MY* trash and my toilet. My human was singing for *MY* bed."
144+
; "I ate my bed. My human was singing for a toy. The baby owned the toilet. The baby slept on *MY* fish."
145+
; "The baby owned my bed. The baby played with a toilet. Bad mouses ate *MY* colorful balls. I scratched the sofa."
146+
; "Bad mouses stared at my fish. My human ate *MY* toilet. My human stretched nearby the toilet. Bad mouses sleeped on my fish. My human scratched a fish. I broke the dry food.")
83147
```
148+

0 commit comments

Comments
 (0)