Created
November 24, 2024 22:06
-
-
Save phunanon/d11c1ec2c09f9580d89c9d39d27501d1 to your computer and use it in GitHub Desktop.
For educational purposes, obviously.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (-> 'ls topics/*.json' | |
| exec | |
| (split '\n') | |
| (map read) | |
| (filter val) | |
| (map from-json) | |
| (map #(% 'questions')) | |
| flatten | |
| (flat-map extract-questions) | |
| to-json | |
| (write "test.json")) | |
| (function extract-choices preamble assets config | |
| (let messages (config 'messages') | |
| messages (if messages | |
| (-> messages (map (fn [k v] [(to-key k) (v 'text')])) dict) | |
| {}) | |
| choices (-> 'choices' config (map #[(% 'label') (% 'correct')]) dict) | |
| text (config 'text') | |
| image (config 'image') | |
| image-url (assets image) | |
| extracted {:question text :choices choices} | |
| extracted (if preamble (extracted :preamble preamble) extracted) | |
| extracted (if image-url (extracted :image-url image-url) extracted)) | |
| extracted) | |
| (function extract-questions section | |
| (let config (section 'config') | |
| assets (-> 'assets' section (map (fn [k v] [k (v 'url')])) dict) | |
| text (config 'text') | |
| questions (config 'questions')) | |
| (return-when questions (flat-map @(extract-choices text assets) questions)) | |
| (extract-choices null assets config)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment