Classify SSD ZIP import roots in typed Kotlin
ober
c0de60c2c6eeaf8f2e0c0f60093624c35b91a6da
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -5313,6 +5313,7 @@ validatedSourceKey treeFileMime safeTreePathParts treePathLeaf treePathDirectoryParts safeImportLeafEntryName zipEntryRootName zipEntryLeafName + zipEntryRootKind jsonLinesFileName) (type Int32) (type Char) @@ -5376,6 +5377,18 @@ (def (zipEntryLeafName (name : String) (separator : Char)) : String (list-ref (zipEntryParts name separator) (int32 1))) + (def (zipEntryRootKind (name : String) + (separator : Char)) : Int32 + (let ((root (zipEntryRootName name separator))) + (if (equal? root "ground_truth") + (int32 1) + (if (equal? root "learned") + (int32 2) + (if (equal? root "events") + (int32 3) + (if (equal? root "reviews") + (int32 4) + (int32 0))))))) (def (validSourceKey (key : String)) : Bool (let ((n (string-length key))) (and (and (>= n 1) (<= n 96)) @@ -8668,12 +8681,11 @@ "" " private fun containedImportPath(name: String): File {" " require(safeImportLeafEntryName(name)) { \"Unsafe import path\" }" - " val root = zipEntryRootName(name, '/')" - " val directory = when (root) {" - " \"ground_truth\" -> groundTruthDir" - " \"learned\" -> learnedDir" - " \"events\" -> eventsDir" - " \"reviews\" -> reviewsDir" + " val directory = when (zipEntryRootKind(name, '/')) {" + " 1 -> groundTruthDir" + " 2 -> learnedDir" + " 3 -> eventsDir" + " 4 -> reviewsDir" " else -> throw IllegalArgumentException(\"Unknown import directory\")" " }" " return containedLeaf(directory, zipEntryLeafName(name, '/'))"