From 8ded66c2d7805f428df88ebad9defd76d0fa0429 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 28 Jan 2022 14:01:57 -0700 Subject: [PATCH] handloose fiddle with model frequencies --- projects/handloose/source/DocumentModel.kiss | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/projects/handloose/source/DocumentModel.kiss b/projects/handloose/source/DocumentModel.kiss index 6b3347ce..7df8161b 100644 --- a/projects/handloose/source/DocumentModel.kiss +++ b/projects/handloose/source/DocumentModel.kiss @@ -12,15 +12,17 @@ (File.saveContent path content) (print content)) -(prop :Map> charFrequencies (new Map)) -(prop :Map> wordFrequencies (new Map)) +(prop :Map> charFrequencies (new Map)) +(prop :Map> wordFrequencies (new Map)) -(method incFrequency [:Map> m :String c :String following] - (when c - (when (= c "\r") (set c "\n")) - (unless (m.exists following) (dictSet m following (new Map))) - (let [followingMap (dictGet m following)] - (dictSet followingMap c (+ 1 (or (dictGet followingMap c) 0)))))) +(method incFrequency [:Map> m :String c :String following] + (let [&mut weight 1.0] + (when c + (when (= c "\r") (set c "\n")) + (when (= c following " ") (set c "\t") (set weight 0.25)) + (unless (m.exists following) (dictSet m following (new Map))) + (let [followingMap (dictGet m following)] + (dictSet followingMap c (+ weight (or (dictGet followingMap c) 0))))))) (method learnFrequencies [:String str] (let [chars (str.split "")] @@ -32,6 +34,7 @@ )) (prop :FlxRandom r (new FlxRandom)) +(var ANY_CHANCE 25) // percent (method :ArrowStuff generateArrowStuff [] // TODO also generate word arrows if lastChar is a space (let [lastChar (substr content -1) @@ -41,5 +44,5 @@ (doFor =>c weight charFreq (chars.push c) (weights.push weight)) - (let [c (r.getObject chars weights)] + (let [c (r.getObject chars (if (r.bool ANY_CHANCE) null weights))] (object text c action ->(type c))))) \ No newline at end of file