extractor: improve rules for extracting aadhar by verifying checksum
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-31 10:16:20 +05:30
parent 12d1327525
commit 9299d22c5b
2 changed files with 16 additions and 2 deletions

View File

@@ -240,6 +240,7 @@ class DocumentExtractionService(
normalizePinCode(results)
normalizeIdNumber(results)
markAadhaarIfValid(results)
results["docType"] = computeDocType(results, handled)
applyGuestUpdates(document, propertyId, results)
return ExtractionResult(results, handled)
@@ -265,7 +266,7 @@ class DocumentExtractionService(
val fromAddress = extractPinFromAddress(address)
val chosen = fromPin ?: fromAddress
results[pinKey] = chosen ?: "NONE"
results[pinKey] = if (isValidPin(chosen)) chosen!! else "NONE"
}
private fun normalizeIdNumber(results: MutableMap<String, String>) {
@@ -277,6 +278,14 @@ class DocumentExtractionService(
}
}
private fun markAadhaarIfValid(results: MutableMap<String, String>) {
val idKey = DocumentPrompts.ID_NUMBER.first
val digits = normalizeDigits(cleanedValue(results[idKey]))
if (digits != null && isValidAadhaar(digits)) {
results["hasAadhar"] = "YES"
}
}
private fun computeDocType(results: Map<String, String>, handled: Boolean): String {
if (!handled) return "GENERAL"
return when {
@@ -454,3 +463,8 @@ private fun normalizeDigits(value: String?): String? {
val digits = value.filter { it.isDigit() }
return digits.ifBlank { null }
}
private fun isValidPin(value: String?): Boolean {
if (value.isNullOrBlank()) return false
return pinCodeRegex.matches(value)
}

View File

@@ -5,7 +5,7 @@ object DocumentPrompts {
val DOB = "dob" to "DOB? Reply only date or NONE."
val ID_NUMBER = "idNumber" to "ID NUMBER? Read extremely carefully. Reply only number or NONE."
val ADDRESS = "address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE."
val PIN_CODE = "pinCode" to "POSTAL PIN CODE (6 digits). Do NOT return Aadhaar or 12-digit numbers. Reply only pin or NONE."
val PIN_CODE = "pinCode" to "CITY POSTAL PIN CODE. Reply only pin or NONE."
val CITY = "city" to "CITY? Reply only city or NONE."
val GENDER = "gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE."
val NATIONALITY = "nationality" to "NATIONALITY? Reply only nationality or NONE."