Created
April 23, 2021 21:32
-
-
Save jaor/0bbc13cff59f44215a2e33212c2e7241 to your computer and use it in GitHub Desktop.
Clean topic model names
This file contains 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
{ | |
"name": "Clean topic names", | |
"kind": "script", | |
"description": "Remove non-letter characters from topic names", | |
"source_code": "script.whizzml", | |
"imports":[ | |
], | |
"inputs":[ | |
{ | |
"name": "topic-model", | |
"type": "topicmodel-id", | |
"description": "The topic model to cleanse" | |
}], | |
"outputs":[] | |
} |
This file contains 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
(define bad-chars "[^0-9A-Za-z]") | |
(define replacement "_") | |
(define (clean-name n) (replace n bad-chars replacement)) | |
(define (rename-topics tm-id) | |
(let (topics (reduce (lambda (r t) | |
(assoc r (t "id") {"name" (clean-name (t "name"))})) | |
{} | |
((fetch tm-id) ["topic_model" "topics"]))) | |
(update tm-id {"topics" topics}))) | |
(define result (rename-topics topic-model)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment