import re def extract_income_limit(text): """ Extract income limit from eligibility text. Returns integer value in INR. """ patterns = [ r"family income.*?₹?\s*([\d,]+)", r"annual income.*?₹?\s*([\d,]+)", r"income should not exceed.*?₹?\s*([\d,]+)", r"income below.*?₹?\s*([\d,]+)", r"income less than.*?₹?\s*([\d,]+)", r"income.*?₹?\s*([\d,]+)" ] for pattern in patterns: match = re.search( pattern, text, re.IGNORECASE ) if match: value = ( match.group(1) .replace(",", "") ) try: return int(value) except: pass return None def extract_age_limit(text): """ Extract age range if available. """ patterns = [ r'(\d+)\s*[-–]\s*(\d+)\s*years', r'age.*?between\s*(\d+)\s*and\s*(\d+)', r'(\d+)\s*to\s*(\d+)\s*years' ] for pattern in patterns: match = re.search( pattern, text, re.IGNORECASE ) if match: return { "min": int(match.group(1)), "max": int(match.group(2)) } return None def extract_categories(text): """ Detect reservation categories. """ categories = [ "SC", "ST", "OBC", "EWS", "Minority", "General", "PWD", "Disabled" ] found = [] for category in categories: if category.lower() in text.lower(): found.append(category) return found def check_eligibility( master_json, income ): """ Main eligibility checker. """ eligibility_text = master_json.get( "eligibility", "" ) income_limit = extract_income_limit( eligibility_text ) age_rule = extract_age_limit( eligibility_text ) categories = extract_categories( eligibility_text ) result_lines = [] result_lines.append( "📋 Eligibility Analysis" ) result_lines.append("") if income_limit: result_lines.append( f"💰 Income Limit: ₹{income_limit:,}" ) else: result_lines.append( "💰 Income Limit: Not Found" ) if age_rule: result_lines.append( f"🎂 Age Requirement: {age_rule['min']} - {age_rule['max']} years" ) else: result_lines.append( "🎂 Age Requirement: Not Found" ) if categories: result_lines.append( f"🏷 Category: {', '.join(categories)}" ) else: result_lines.append( "🏷 Category: Open" ) result_lines.append("") result_lines.append("Result:") if income_limit: if income <= income_limit: result_lines.append( "✅ Eligible (Income Criteria Satisfied)" ) else: result_lines.append( "❌ Not Eligible (Income Exceeds Limit)" ) else: result_lines.append( "⚠ Unable to verify eligibility automatically." ) return "\n".join( result_lines )