From 8c6ff83f5c408753559d4b01f52635c348520881 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 28 Jan 2022 14:30:33 -0700 Subject: [PATCH] outline how precompiled char frequency will work --- projects/handloose/Project.xml | 4 ++++ projects/handloose/source/DocumentModel.kiss | 24 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/projects/handloose/Project.xml b/projects/handloose/Project.xml index 68902cd6..53450bea 100644 --- a/projects/handloose/Project.xml +++ b/projects/handloose/Project.xml @@ -46,6 +46,10 @@ + + + + diff --git a/projects/handloose/source/DocumentModel.kiss b/projects/handloose/source/DocumentModel.kiss index 7df8161b..688c90ec 100644 --- a/projects/handloose/source/DocumentModel.kiss +++ b/projects/handloose/source/DocumentModel.kiss @@ -1,10 +1,7 @@ (defNew [&prop :String path] (when (FileSystem.exists path) (set content (File.getContent path))) (type "") // If the file can't be written to, throw the error right away - // Use files with the same extension in the current working directory to determine letter frequencies - (walkDirectory "" (FileSystem.absolutePath "") - ->file (when (= (Path.extension file) (Path.extension path)) - (learnFrequencies (File.getContent file))))) + (learnAllFrequencies)) (prop &mut :String content "") (method :Void type [:String str] @@ -24,6 +21,25 @@ (let [followingMap (dictGet m following)] (dictSet followingMap c (+ weight (or (dictGet followingMap c) 0))))))) +(defMacro prelearnAllFrequencies [] + /* TODO - add Context.definedValues to macro variables + - walk LEARN_FROM, adding to a frequency map in prelearnFrequencies() below + - stringify the frequency map with "" specially added around the keys + - inject a Context.parse of the stringified frequency map + */ + (throw "not implemented")) + +(defMacroFunction prelearnFrequencies [str &builder b] + (throw "not implemented")) + +(method learnAllFrequencies [] + (#if LEARN_FROM + (prelearnAllFrequencies) + // Use files with the same extension in the current working directory to determine letter frequencies + (walkDirectory "" (FileSystem.absolutePath "") + ->file (when (= (Path.extension file) (Path.extension path)) + (learnFrequencies (File.getContent file)))))) + (method learnFrequencies [:String str] (let [chars (str.split "")] (when chars