handloose fiddle with model frequencies
This commit is contained in:
@@ -12,15 +12,17 @@
|
|||||||
(File.saveContent path content)
|
(File.saveContent path content)
|
||||||
(print content))
|
(print content))
|
||||||
|
|
||||||
(prop :Map<String,Map<String,Int>> charFrequencies (new Map))
|
(prop :Map<String,Map<String,Float>> charFrequencies (new Map))
|
||||||
(prop :Map<String,Map<String,Int>> wordFrequencies (new Map))
|
(prop :Map<String,Map<String,Float>> wordFrequencies (new Map))
|
||||||
|
|
||||||
(method incFrequency [:Map<String,Map<String,Int>> m :String c :String following]
|
(method incFrequency [:Map<String,Map<String,Float>> m :String c :String following]
|
||||||
(when c
|
(let [&mut weight 1.0]
|
||||||
(when (= c "\r") (set c "\n"))
|
(when c
|
||||||
(unless (m.exists following) (dictSet m following (new Map)))
|
(when (= c "\r") (set c "\n"))
|
||||||
(let [followingMap (dictGet m following)]
|
(when (= c following " ") (set c "\t") (set weight 0.25))
|
||||||
(dictSet followingMap c (+ 1 (or (dictGet followingMap c) 0))))))
|
(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]
|
(method learnFrequencies [:String str]
|
||||||
(let [chars (str.split "")]
|
(let [chars (str.split "")]
|
||||||
@@ -32,6 +34,7 @@
|
|||||||
))
|
))
|
||||||
|
|
||||||
(prop :FlxRandom r (new FlxRandom))
|
(prop :FlxRandom r (new FlxRandom))
|
||||||
|
(var ANY_CHANCE 25) // percent
|
||||||
(method :ArrowStuff generateArrowStuff []
|
(method :ArrowStuff generateArrowStuff []
|
||||||
// TODO also generate word arrows if lastChar is a space
|
// TODO also generate word arrows if lastChar is a space
|
||||||
(let [lastChar (substr content -1)
|
(let [lastChar (substr content -1)
|
||||||
@@ -41,5 +44,5 @@
|
|||||||
(doFor =>c weight charFreq
|
(doFor =>c weight charFreq
|
||||||
(chars.push c)
|
(chars.push c)
|
||||||
(weights.push weight))
|
(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)))))
|
(object text c action ->(type c)))))
|
Reference in New Issue
Block a user