| 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 |
| ) |