extractor: improve rules for extracting aadhar by verifying checksum
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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."
|
||||
|
||||
Reference in New Issue
Block a user