|
78 | 78 | ; 15 |
79 | 79 | ; true |
80 | 80 | ; 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"})) |
81 | 124 |
|
| 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))) |
82 | 134 |
|
| 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.") |
83 | 147 | ``` |
| 148 | + |
0 commit comments