Generate SSD learned guess application from typed Jerboa
ober
62bfa80d26948e75536ec0262a2151e0d3a35e22
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -15538,6 +15538,7 @@ (java nio file Path) (java security MessageDigest) (javax net ssl HttpsURLConnection) + (org json JSONArray) (org json JSONObject)) (typed-library (com sfb ssdreview) (export truthStoreSha256Hex truthStoreContainedLeaf @@ -15550,7 +15551,8 @@ truthStoreLoadRemoteConfigLocal truthStoreRemoteUrlLocal truthStoreReadResponseTextLocal - truthStoreWriteRemoteTruthLocal) + truthStoreWriteRemoteTruthLocal + truthStoreApplyLearnedGuessesLocal) (type Context) (type Exception) (type File) @@ -15566,6 +15568,7 @@ (type StorageStats) (type TruthStore) (type URL) + (type JSONArray) (type JSONObject) (extern (truthStoreRoot (store : TruthStore)) : File @@ -15576,10 +15579,20 @@ (extern (truthStoreEventsDir (store : TruthStore)) : File (kotlin-member-get eventsDir)) + (extern (truthStoreLearnedDir + (store : TruthStore)) : File + (kotlin-member-get learnedDir)) + (extern (truthStoreChildFile + (parent : File) + (name : String)) : File + (kotlin-call File)) (extern (truthStoreLoadTruthForSession (store : TruthStore) (session : SsdSession)) : (Nullable JSONObject) (kotlin-member-call loadTruth)) + (extern (truthStoreRebuildLearnedExamplesRaw + (store : TruthStore)) : Unit + (kotlin-member-call rebuildLearnedExamples)) (extern (truthStoreSaveTruthSnapshotRaw (store : TruthStore) (truth : JSONObject)) : File @@ -16097,7 +16110,25 @@ text) (truthStoreInvalidateTruthIndexRaw store) #t))))))) - #f))))) + #f))) + (def (truthStoreApplyLearnedGuessesLocal + (store : TruthStore) + (session : SsdSession)) : Int32 + (let ((file + (truthStoreChildFile + (truthStoreLearnedDir store) + (learnedExamplesFileName)))) + (begin + (if (localFileMissing file) + (truthStoreRebuildLearnedExamplesRaw store) + (begin)) + (if (localFileMissing file) + (int32 0) + (applyLearnedGuessesFromExamples + session + (learnedExamplesFromDocument + (jsonObjectFromText + (truthStoreReadLocalText file)))))))))) (kotlin-file-lines "com/sfb/ssdreview/TruthStore.kt" ( @@ -16146,7 +16177,7 @@ "class TruthStore(private val context: Context) {" " internal val root = File(context.filesDir, \"ssd_review\")" " internal val groundTruthDir = File(root, \"ground_truth\")" - " private val learnedDir = File(root, \"learned\")" + " internal val learnedDir = File(root, \"learned\")" " internal val eventsDir = File(root, \"events\")" " private val reviewsDir = File(root, \"reviews\")" " private val remoteConfig: RemoteConfig? by lazy { loadRemoteConfig() }" @@ -16391,13 +16422,8 @@ " ): Boolean =" " truthStoreWriteRemoteTruthLocal(this, truth, modified, replaceIfMoreComplete)" "" - " fun applyLearnedGuesses(session: SsdSession): Int {" - " val file = File(learnedDir, learnedExamplesFileName())" - " if (localFileMissing(file)) rebuildLearnedExamples()" - " if (localFileMissing(file)) return 0" - " val examples = learnedExamplesFromDocument(jsonObjectFromText(readLocalText(file)))" - " return applyLearnedGuessesFromExamples(session, examples)" - " }" + " fun applyLearnedGuesses(session: SsdSession): Int =" + " truthStoreApplyLearnedGuessesLocal(this, session)" "" " fun exportZip(out: OutputStream) {" " storageStats()" @@ -16580,7 +16606,7 @@ " truthStoreSeedBundledTruthAsync(this, done)" " }" "" - " private fun rebuildLearnedExamples() {" + " internal fun rebuildLearnedExamples() {" " val examples = learnedExamplesEmpty()" " val files = if (fileListFilesPresent(groundTruthDir)) {" " checkNotNull(groundTruthDir.listFiles { f -> truthJsonFileName(f.name) })"