Skip to content

Instantly share code, notes, and snippets.

@jaor
Created April 23, 2021 21:32
Show Gist options
  • Save jaor/0bbc13cff59f44215a2e33212c2e7241 to your computer and use it in GitHub Desktop.
Save jaor/0bbc13cff59f44215a2e33212c2e7241 to your computer and use it in GitHub Desktop.
Clean topic model names
{
"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":[]
}
(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