borderless 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- borderless/__init__.py +3 -0
- borderless/cli.py +320 -0
- borderless/cli_options.py +19 -0
- borderless/criteria.py +33 -0
- borderless/evaluator.py +602 -0
- borderless/intl_visas.py +275 -0
- borderless/llm_review.py +226 -0
- borderless/markdown_report.py +172 -0
- borderless/policy.py +30 -0
- borderless/profile_loader.py +175 -0
- borderless-0.1.0.dist-info/METADATA +190 -0
- borderless-0.1.0.dist-info/RECORD +16 -0
- borderless-0.1.0.dist-info/WHEEL +5 -0
- borderless-0.1.0.dist-info/entry_points.txt +3 -0
- borderless-0.1.0.dist-info/licenses/LICENSE +21 -0
- borderless-0.1.0.dist-info/top_level.txt +1 -0
borderless/evaluator.py
ADDED
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
"""Core evaluation engine.
|
|
2
|
+
|
|
3
|
+
Extracts evidence from profile.yaml and scores it against USCIS criteria.
|
|
4
|
+
Nuanced gap analysis and action items are delegated to the LLM review.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
from calendar import monthrange
|
|
11
|
+
from dataclasses import dataclass, field
|
|
12
|
+
from datetime import date
|
|
13
|
+
from math import isfinite
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
from .criteria import CriterionResult, Strength
|
|
17
|
+
from .intl_visas import IntlPathway, evaluate_international
|
|
18
|
+
from .profile_loader import completed_education, date_bound, validate_profile
|
|
19
|
+
|
|
20
|
+
# ---------------------------------------------------------------------------
|
|
21
|
+
# Helpers
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
def _get(profile: dict, *keys: str, default: Any = None) -> Any:
|
|
25
|
+
"""Nested dict lookup."""
|
|
26
|
+
obj = profile
|
|
27
|
+
for k in keys:
|
|
28
|
+
if isinstance(obj, dict):
|
|
29
|
+
obj = obj.get(k, default)
|
|
30
|
+
else:
|
|
31
|
+
return default
|
|
32
|
+
return obj
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _list(val: Any) -> list:
|
|
36
|
+
if val is None:
|
|
37
|
+
return []
|
|
38
|
+
return val if isinstance(val, list) else [val]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _fmt_item(item: Any, keys: tuple[str, ...] = ("name",), fallback: str = "unnamed") -> str:
|
|
42
|
+
if isinstance(item, dict):
|
|
43
|
+
parts = [str(item.get(k, "")) for k in keys if item.get(k)]
|
|
44
|
+
return " | ".join(parts) if parts else fallback
|
|
45
|
+
return str(item)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# ---------------------------------------------------------------------------
|
|
49
|
+
# Shared criterion evaluators (used by EB-1A, EB-1B, and O-1A)
|
|
50
|
+
# ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
def _eval_awards(p: dict) -> tuple[Strength, list[str]]:
|
|
53
|
+
awards = _list(_get(p, "awards"))
|
|
54
|
+
hackathons = _list(_get(p, "hackathons"))
|
|
55
|
+
all_items = awards + hackathons
|
|
56
|
+
|
|
57
|
+
evidence = [
|
|
58
|
+
f"{label}: {_fmt_item(a, ('name', 'year', 'result'))}"
|
|
59
|
+
for label, items in (("Award", awards), ("Hackathon placement", hackathons))
|
|
60
|
+
for a in items
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
# ponytail: scope-only award signals can inflate placements; use documented recognition/excellence for adjudication.
|
|
64
|
+
broad_scope = [
|
|
65
|
+
a for a in all_items
|
|
66
|
+
if isinstance(a, dict) and a.get("scope") in ("national", "international")
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
if len(broad_scope) >= 2:
|
|
70
|
+
strength = Strength.STRONG
|
|
71
|
+
elif broad_scope or len(all_items) >= 2:
|
|
72
|
+
strength = Strength.MODERATE
|
|
73
|
+
elif all_items:
|
|
74
|
+
strength = Strength.WEAK
|
|
75
|
+
else:
|
|
76
|
+
strength = Strength.NOT_MET
|
|
77
|
+
|
|
78
|
+
return strength, evidence
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _eval_membership(p: dict) -> tuple[Strength, list[str]]:
|
|
82
|
+
memberships = _list(_get(p, "memberships"))
|
|
83
|
+
evidence = [
|
|
84
|
+
m.get("name", str(m)) if isinstance(m, dict) else str(m)
|
|
85
|
+
for m in memberships
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
selective = [
|
|
89
|
+
m for m in memberships
|
|
90
|
+
if isinstance(m, dict) and m.get("requires_outstanding_achievement")
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
if selective:
|
|
94
|
+
strength = Strength.STRONG
|
|
95
|
+
elif memberships:
|
|
96
|
+
strength = Strength.WEAK
|
|
97
|
+
else:
|
|
98
|
+
strength = Strength.NOT_MET
|
|
99
|
+
|
|
100
|
+
return strength, evidence
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _eval_press(p: dict) -> tuple[Strength, list[str]]:
|
|
104
|
+
press = _list(_get(p, "press"))
|
|
105
|
+
evidence = [
|
|
106
|
+
item.get("title", str(item)) if isinstance(item, dict) else str(item)
|
|
107
|
+
for item in press
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
major = [item for item in press if isinstance(item, dict) and item.get("major")]
|
|
111
|
+
|
|
112
|
+
if len(major) >= 2:
|
|
113
|
+
strength = Strength.STRONG
|
|
114
|
+
elif major:
|
|
115
|
+
strength = Strength.MODERATE
|
|
116
|
+
elif press:
|
|
117
|
+
strength = Strength.WEAK
|
|
118
|
+
else:
|
|
119
|
+
strength = Strength.NOT_MET
|
|
120
|
+
|
|
121
|
+
return strength, evidence
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _eval_judging(p: dict) -> tuple[Strength, list[str]]:
|
|
125
|
+
reviewing = _list(_get(p, "reviewing"))
|
|
126
|
+
evidence = [
|
|
127
|
+
f"{r.get('venue', '?')} ({r.get('year', '?')}) – {r.get('role', 'reviewer')}"
|
|
128
|
+
if isinstance(r, dict) else str(r)
|
|
129
|
+
for r in reviewing
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
top_venues = [
|
|
133
|
+
r for r in reviewing
|
|
134
|
+
if isinstance(r, dict) and r.get("tier") in ("A*", "A", "top")
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
if len(top_venues) >= 2:
|
|
138
|
+
strength = Strength.STRONG
|
|
139
|
+
elif reviewing:
|
|
140
|
+
strength = Strength.MODERATE
|
|
141
|
+
else:
|
|
142
|
+
strength = Strength.NOT_MET
|
|
143
|
+
|
|
144
|
+
return strength, evidence
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _eval_original_contributions(p: dict) -> tuple[Strength, list[str]]:
|
|
148
|
+
publications = _list(_get(p, "publications"))
|
|
149
|
+
oss = _list(_get(p, "open_source_contributions"))
|
|
150
|
+
citations_total = _get(p, "metrics", "total_citations", default=0) or 0
|
|
151
|
+
h_index = _get(p, "metrics", "h_index", default=0) or 0
|
|
152
|
+
|
|
153
|
+
evidence = []
|
|
154
|
+
for pub in publications:
|
|
155
|
+
if isinstance(pub, dict):
|
|
156
|
+
cite_str = f", {pub['citations']} cites" if "citations" in pub else ""
|
|
157
|
+
evidence.append(f"{pub.get('title', '?')} @ {pub.get('venue', '?')}{cite_str}")
|
|
158
|
+
for o in oss:
|
|
159
|
+
if isinstance(o, dict):
|
|
160
|
+
evidence.append(f"OSS: {o.get('project', '?')} – {o.get('impact', '')}")
|
|
161
|
+
else:
|
|
162
|
+
evidence.append(f"OSS: {o}")
|
|
163
|
+
|
|
164
|
+
if h_index >= 10 or citations_total >= 200:
|
|
165
|
+
strength = Strength.STRONG
|
|
166
|
+
elif h_index >= 5 or citations_total >= 50 or (publications and oss):
|
|
167
|
+
strength = Strength.MODERATE
|
|
168
|
+
elif publications or oss:
|
|
169
|
+
strength = Strength.WEAK
|
|
170
|
+
else:
|
|
171
|
+
strength = Strength.NOT_MET
|
|
172
|
+
|
|
173
|
+
return strength, evidence
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _eval_scholarly_articles(p: dict) -> tuple[Strength, list[str]]:
|
|
177
|
+
publications = _list(_get(p, "publications"))
|
|
178
|
+
evidence = []
|
|
179
|
+
peer_reviewed = []
|
|
180
|
+
for pub in publications:
|
|
181
|
+
if isinstance(pub, dict):
|
|
182
|
+
evidence.append(f"{pub.get('title', '?')} @ {pub.get('venue', '?')} ({pub.get('year', '?')})")
|
|
183
|
+
if pub.get("peer_reviewed"):
|
|
184
|
+
peer_reviewed.append(pub)
|
|
185
|
+
else:
|
|
186
|
+
evidence.append(str(pub))
|
|
187
|
+
|
|
188
|
+
if len(peer_reviewed) >= 5:
|
|
189
|
+
strength = Strength.STRONG
|
|
190
|
+
elif len(peer_reviewed) >= 2:
|
|
191
|
+
strength = Strength.MODERATE
|
|
192
|
+
elif peer_reviewed or publications:
|
|
193
|
+
strength = Strength.WEAK
|
|
194
|
+
else:
|
|
195
|
+
strength = Strength.NOT_MET
|
|
196
|
+
|
|
197
|
+
return strength, evidence
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def _eval_leading_role(p: dict) -> tuple[Strength, list[str]]:
|
|
201
|
+
roles = [
|
|
202
|
+
r for r in _list(p.get("leading_roles"))
|
|
203
|
+
if isinstance(r, dict) and r.get("critical_role") is not False
|
|
204
|
+
]
|
|
205
|
+
work = [
|
|
206
|
+
r for r in _list(p.get("work_experience"))
|
|
207
|
+
if isinstance(r, dict) and r.get("critical_role") is True
|
|
208
|
+
]
|
|
209
|
+
candidates = roles + work
|
|
210
|
+
evidence = [_fmt_item(r, ("role", "title", "organization")) for r in candidates]
|
|
211
|
+
qualifying = [
|
|
212
|
+
r for items, label in ((roles, "role"), (work, "title")) for r in items
|
|
213
|
+
if r.get("distinguished") is True and r.get(label) and r.get("organization")
|
|
214
|
+
]
|
|
215
|
+
if len(qualifying) >= 2:
|
|
216
|
+
strength = Strength.STRONG
|
|
217
|
+
elif qualifying:
|
|
218
|
+
strength = Strength.MODERATE
|
|
219
|
+
elif candidates:
|
|
220
|
+
strength = Strength.WEAK
|
|
221
|
+
else:
|
|
222
|
+
strength = Strength.NOT_MET
|
|
223
|
+
return strength, evidence
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _eval_high_salary(p: dict) -> tuple[Strength, list[str]]:
|
|
227
|
+
salary = _get(p, "salary")
|
|
228
|
+
if not salary:
|
|
229
|
+
return Strength.NOT_MET, []
|
|
230
|
+
amount = salary.get("amount")
|
|
231
|
+
if amount is None:
|
|
232
|
+
return Strength.NOT_MET, ["Salary amount not provided"]
|
|
233
|
+
if isinstance(amount, bool) or not isinstance(amount, (int, float)) or not isfinite(amount) or amount < 0:
|
|
234
|
+
raise ValueError("salary.amount must be a finite non-negative number")
|
|
235
|
+
evidence = [f"{amount:,} {salary.get('currency', 'USD')}/yr as {salary.get('role', '?')}"]
|
|
236
|
+
percentile = salary.get("percentile")
|
|
237
|
+
comparison = [salary.get(k) for k in ("comparison_source", "comparison_field", "comparison_location")]
|
|
238
|
+
if percentile is None or not all(comparison):
|
|
239
|
+
return Strength.WEAK, evidence
|
|
240
|
+
if isinstance(percentile, bool) or not isinstance(percentile, (int, float)) or not 0 <= percentile <= 100:
|
|
241
|
+
raise ValueError("salary.percentile must be a number from 0 to 100")
|
|
242
|
+
evidence.append(f"Percentile {percentile}: {comparison[1]} in {comparison[2]} (source: {comparison[0]})")
|
|
243
|
+
strength = Strength.STRONG if percentile >= 95 else Strength.MODERATE if percentile >= 90 else Strength.WEAK
|
|
244
|
+
return strength, evidence
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
# ---------------------------------------------------------------------------
|
|
248
|
+
# EB-1A (10 criteria, need >= 3)
|
|
249
|
+
# ---------------------------------------------------------------------------
|
|
250
|
+
|
|
251
|
+
_EB1A_EVALUATORS: list[tuple[str, str, Any]] = [
|
|
252
|
+
("eb1a_1", "Prizes / Awards", _eval_awards),
|
|
253
|
+
("eb1a_2", "Membership in Associations", _eval_membership),
|
|
254
|
+
("eb1a_3", "Published Material About the Person", _eval_press),
|
|
255
|
+
("eb1a_4", "Judging the Work of Others", _eval_judging),
|
|
256
|
+
("eb1a_5", "Original Contributions of Major Significance", _eval_original_contributions),
|
|
257
|
+
("eb1a_6", "Authorship of Scholarly Articles", _eval_scholarly_articles),
|
|
258
|
+
("eb1a_7", "Artistic Exhibitions", None),
|
|
259
|
+
("eb1a_8", "Leading or Critical Role", _eval_leading_role),
|
|
260
|
+
("eb1a_9", "High Salary / Remuneration", _eval_high_salary),
|
|
261
|
+
("eb1a_10", "Commercial Success in Performing Arts", None),
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def evaluate_eb1a(profile: dict) -> list[CriterionResult]:
|
|
266
|
+
results = []
|
|
267
|
+
for cid, name, fn in _EB1A_EVALUATORS:
|
|
268
|
+
if fn is None:
|
|
269
|
+
results.append(CriterionResult(cid, name, Strength.NOT_MET))
|
|
270
|
+
continue
|
|
271
|
+
strength, evidence = fn(profile)
|
|
272
|
+
results.append(CriterionResult(cid, name, strength, evidence))
|
|
273
|
+
return results
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
# ---------------------------------------------------------------------------
|
|
277
|
+
# EB-1B (6 criteria, need >= 2, plus prereqs)
|
|
278
|
+
# ---------------------------------------------------------------------------
|
|
279
|
+
|
|
280
|
+
def _completed_advanced_degrees(profile: dict, as_of: date | None = None) -> list[dict]:
|
|
281
|
+
advanced = []
|
|
282
|
+
for edu in completed_education(profile, as_of):
|
|
283
|
+
degree = (edu.get("degree") or "").lower()
|
|
284
|
+
if any(kw in degree for kw in ("master", "doctor", "phd", "m.s.", "m.sc")):
|
|
285
|
+
advanced.append(edu)
|
|
286
|
+
return advanced
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _eval_eb1b_experience(p: dict, as_of: date | None = None) -> tuple[bool, list[str]]:
|
|
290
|
+
"""Count non-overlapping, completed qualifying months conservatively."""
|
|
291
|
+
today = as_of or date.today()
|
|
292
|
+
degrees = {e.get("id") for e in _completed_advanced_degrees(p, today) if e.get("id")}
|
|
293
|
+
intervals = []
|
|
294
|
+
details = []
|
|
295
|
+
for work in _list(p.get("work_experience")):
|
|
296
|
+
if not isinstance(work, dict):
|
|
297
|
+
continue
|
|
298
|
+
title = (work.get("title") or "").lower()
|
|
299
|
+
if not (work.get("graduate_experience") is True or any(
|
|
300
|
+
k in title for k in ("research", "professor", "teaching", "instructor", "postdoc")
|
|
301
|
+
)):
|
|
302
|
+
continue
|
|
303
|
+
graduate = work.get("graduate_experience", bool(re.search(r"\b(graduate|postgraduate|doctoral|ph\.?d)\b", title)))
|
|
304
|
+
if graduate and not (
|
|
305
|
+
work.get("education_id") in degrees and work.get("graduate_experience_evidence")
|
|
306
|
+
):
|
|
307
|
+
details.append(f"{work.get('title')}: graduate experience conditions unestablished")
|
|
308
|
+
continue
|
|
309
|
+
try:
|
|
310
|
+
start = date_bound(work.get("start"), latest=True)
|
|
311
|
+
raw_end = work.get("end", "present")
|
|
312
|
+
end = today if raw_end == "present" else min(today, date_bound(raw_end))
|
|
313
|
+
except (ValueError, TypeError):
|
|
314
|
+
details.append(f"{work.get('title')}: dates unassessed")
|
|
315
|
+
continue
|
|
316
|
+
if start < end:
|
|
317
|
+
intervals.append((start, end))
|
|
318
|
+
details.append(f"{work.get('title')} at {work.get('organization', '?')} ({start}–{end})")
|
|
319
|
+
merged = []
|
|
320
|
+
for start, end in sorted(intervals):
|
|
321
|
+
if merged and start <= merged[-1][1]:
|
|
322
|
+
merged[-1] = (merged[-1][0], max(end, merged[-1][1]))
|
|
323
|
+
else:
|
|
324
|
+
merged.append((start, end))
|
|
325
|
+
# ponytail: whole months undercount fragmented partial months; document exact dates for attorney assessment.
|
|
326
|
+
months = sum(
|
|
327
|
+
(end.year - start.year) * 12 + end.month - start.month
|
|
328
|
+
- (end.day < min(start.day, monthrange(end.year, end.month)[1]))
|
|
329
|
+
for start, end in merged
|
|
330
|
+
)
|
|
331
|
+
details.append(f"{months} completed non-overlapping qualifying months as of {today}")
|
|
332
|
+
return months >= 36, details
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _eval_eb1b_original_research(p: dict) -> tuple[Strength, list[str]]:
|
|
336
|
+
"""EB-1B criterion 5: lower bar than EB-1A (no 'major significance')."""
|
|
337
|
+
publications = _list(_get(p, "publications"))
|
|
338
|
+
oss = _list(_get(p, "open_source_contributions"))
|
|
339
|
+
evidence = []
|
|
340
|
+
for pub in publications:
|
|
341
|
+
if isinstance(pub, dict):
|
|
342
|
+
evidence.append(f"{pub.get('title', '?')} @ {pub.get('venue', '?')}")
|
|
343
|
+
for o in oss:
|
|
344
|
+
if isinstance(o, dict):
|
|
345
|
+
evidence.append(f"OSS: {o.get('project', '?')}")
|
|
346
|
+
|
|
347
|
+
if publications and (oss or len(publications) >= 2):
|
|
348
|
+
strength = Strength.STRONG
|
|
349
|
+
elif publications:
|
|
350
|
+
strength = Strength.MODERATE
|
|
351
|
+
else:
|
|
352
|
+
strength = Strength.NOT_MET
|
|
353
|
+
|
|
354
|
+
return strength, evidence
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
_EB1B_EVALUATORS: list[tuple[str, str, Any]] = [
|
|
358
|
+
("eb1b_1", "Major Prizes or Awards", _eval_awards),
|
|
359
|
+
("eb1b_2", "Membership in Associations", _eval_membership),
|
|
360
|
+
("eb1b_3", "Published Material About the Person", _eval_press),
|
|
361
|
+
("eb1b_4", "Judging the Work of Others", _eval_judging),
|
|
362
|
+
("eb1b_5", "Original Research Contributions", _eval_eb1b_original_research),
|
|
363
|
+
("eb1b_6", "Authorship of Scholarly Articles", _eval_scholarly_articles),
|
|
364
|
+
]
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _eval_eb1b_job(profile: dict) -> CriterionResult:
|
|
368
|
+
offer = profile.get("eb1b_job_offer") or {}
|
|
369
|
+
evidence = [f"{offer.get('position_type', '?')} at {offer.get('employer', '?')}"] if offer else []
|
|
370
|
+
documented = all(offer.get(k) for k in ("employer", "offer_letter"))
|
|
371
|
+
position = offer.get("position_type") in ("tenured", "tenure_track", "permanent_research")
|
|
372
|
+
employer = offer.get("employer_type") in ("university", "higher_education")
|
|
373
|
+
if offer.get("employer_type") == "private_research":
|
|
374
|
+
researchers = offer.get("full_time_researchers", 0)
|
|
375
|
+
employer = (
|
|
376
|
+
isinstance(researchers, int) and not isinstance(researchers, bool)
|
|
377
|
+
and researchers >= 3 and bool(offer.get("research_accomplishments"))
|
|
378
|
+
)
|
|
379
|
+
qualified = documented and position and employer and offer.get("country") == "US"
|
|
380
|
+
if qualified:
|
|
381
|
+
evidence.append(f"Qualifying U.S. offer documented by {offer['offer_letter']}")
|
|
382
|
+
return CriterionResult(
|
|
383
|
+
"eb1b_job", "Qualifying U.S. Job Offer (required)",
|
|
384
|
+
Strength.STRONG if qualified else Strength.WEAK if offer else Strength.NOT_MET,
|
|
385
|
+
evidence,
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def evaluate_eb1b(profile: dict) -> list[CriterionResult]:
|
|
390
|
+
exp_met, exp_details = _eval_eb1b_experience(profile)
|
|
391
|
+
|
|
392
|
+
results = [
|
|
393
|
+
CriterionResult(
|
|
394
|
+
"eb1b_prereq", "3+ Years Research/Teaching Experience",
|
|
395
|
+
Strength.STRONG if exp_met else Strength.NOT_MET,
|
|
396
|
+
evidence=exp_details,
|
|
397
|
+
),
|
|
398
|
+
]
|
|
399
|
+
|
|
400
|
+
for cid, name, fn in _EB1B_EVALUATORS:
|
|
401
|
+
strength, evidence = fn(profile)
|
|
402
|
+
results.append(CriterionResult(cid, name, strength, evidence))
|
|
403
|
+
|
|
404
|
+
results.append(_eval_eb1b_job(profile))
|
|
405
|
+
|
|
406
|
+
return results
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
# ---------------------------------------------------------------------------
|
|
410
|
+
# EB2-NIW (Dhanasar 3-prong test)
|
|
411
|
+
# ---------------------------------------------------------------------------
|
|
412
|
+
|
|
413
|
+
def _eval_niw_prong1(p: dict) -> CriterionResult:
|
|
414
|
+
endeavor = _get(p, "proposed_endeavor")
|
|
415
|
+
field_val = _get(p, "field", default="")
|
|
416
|
+
|
|
417
|
+
evidence = []
|
|
418
|
+
if endeavor:
|
|
419
|
+
evidence.append(f"Proposed endeavor: {endeavor}")
|
|
420
|
+
if field_val:
|
|
421
|
+
evidence.append(f"Field: {field_val}")
|
|
422
|
+
|
|
423
|
+
ai_keywords = {"ai", "artificial intelligence", "machine learning", "nlp",
|
|
424
|
+
"natural language processing", "deep learning", "computer science"}
|
|
425
|
+
is_ai = any(kw in (field_val or "").lower() for kw in ai_keywords)
|
|
426
|
+
|
|
427
|
+
if endeavor and is_ai:
|
|
428
|
+
strength = Strength.STRONG
|
|
429
|
+
elif endeavor:
|
|
430
|
+
strength = Strength.MODERATE
|
|
431
|
+
else:
|
|
432
|
+
strength = Strength.WEAK
|
|
433
|
+
evidence.append("(inferred from profile)")
|
|
434
|
+
|
|
435
|
+
return CriterionResult("niw_1", "Substantial Merit & National Importance", strength, evidence)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def _eval_niw_prong2(p: dict) -> CriterionResult:
|
|
439
|
+
publications = _list(_get(p, "publications"))
|
|
440
|
+
education = _list(_get(p, "education"))
|
|
441
|
+
completed = completed_education(p)
|
|
442
|
+
reviewing = _list(_get(p, "reviewing"))
|
|
443
|
+
oss = _list(_get(p, "open_source_contributions"))
|
|
444
|
+
|
|
445
|
+
evidence = []
|
|
446
|
+
for e in education:
|
|
447
|
+
if isinstance(e, dict):
|
|
448
|
+
state = "completed" if e in completed else "completion unestablished"
|
|
449
|
+
evidence.append(f"{e.get('degree', '?')} – {e.get('institution', '?')} ({state}; year {e.get('year', 'unreported')})")
|
|
450
|
+
evidence.append(f"{len(publications)} publications")
|
|
451
|
+
if reviewing:
|
|
452
|
+
evidence.append(f"Reviewer for {len(reviewing)} venues")
|
|
453
|
+
if oss:
|
|
454
|
+
evidence.append(f"{len(oss)} open-source contributions")
|
|
455
|
+
|
|
456
|
+
score = 0
|
|
457
|
+
if any(any(k in e.get("degree", "").lower() for k in ("doctor", "phd")) for e in completed):
|
|
458
|
+
score += 2
|
|
459
|
+
score += min(len(publications), 3)
|
|
460
|
+
score += min(len(reviewing), 2)
|
|
461
|
+
score += min(len(oss), 2)
|
|
462
|
+
|
|
463
|
+
if score >= 6:
|
|
464
|
+
strength = Strength.STRONG
|
|
465
|
+
elif score >= 3:
|
|
466
|
+
strength = Strength.MODERATE
|
|
467
|
+
else:
|
|
468
|
+
strength = Strength.WEAK
|
|
469
|
+
|
|
470
|
+
return CriterionResult("niw_2", "Well-Positioned to Advance Endeavor", strength, evidence)
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
def _eval_niw_prong3(p: dict) -> CriterionResult:
|
|
474
|
+
waiver = p.get("niw_waiver") or {}
|
|
475
|
+
argument = waiver.get("argument")
|
|
476
|
+
documents = waiver.get("evidence") or []
|
|
477
|
+
evidence = ([f"Waiver-benefit argument: {argument}"] if argument else []) + list(documents)
|
|
478
|
+
strength = Strength.MODERATE if argument and documents else Strength.WEAK
|
|
479
|
+
return CriterionResult("niw_3", "Benefit to Waive Job Offer", strength, evidence)
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def evaluate_niw(profile: dict) -> list[CriterionResult]:
|
|
483
|
+
return [
|
|
484
|
+
_eval_niw_prong1(profile),
|
|
485
|
+
_eval_niw_prong2(profile),
|
|
486
|
+
_eval_niw_prong3(profile),
|
|
487
|
+
]
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
def evaluate_eb2_base(profile: dict) -> CriterionResult:
|
|
491
|
+
advanced = _completed_advanced_degrees(profile)
|
|
492
|
+
evidence = [f"{e.get('degree', '?')} – {e.get('institution', '?')}" for e in advanced]
|
|
493
|
+
if advanced:
|
|
494
|
+
return CriterionResult("eb2_base", "EB-2 Base Qualification", Strength.STRONG, evidence)
|
|
495
|
+
return CriterionResult(
|
|
496
|
+
"eb2_base", "EB-2 Base Qualification", Strength.WEAK,
|
|
497
|
+
["Advanced degree not established; bachelor's plus five years of progressive "
|
|
498
|
+
"post-degree experience or exceptional ability requires separate assessment."],
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
# ---------------------------------------------------------------------------
|
|
503
|
+
# O-1A (reuses the eight applicable evidence categories)
|
|
504
|
+
# ---------------------------------------------------------------------------
|
|
505
|
+
|
|
506
|
+
def evaluate_o1a(eb1a_results: list[CriterionResult]) -> CriterionResult:
|
|
507
|
+
"""Assess only initial evidence signals, not sustained acclaim or totality."""
|
|
508
|
+
applicable = {"eb1a_1", "eb1a_2", "eb1a_3", "eb1a_4", "eb1a_5", "eb1a_6", "eb1a_8", "eb1a_9"}
|
|
509
|
+
met = len({
|
|
510
|
+
r.criterion_id for r in eb1a_results
|
|
511
|
+
if r.criterion_id in applicable and r.strength in (Strength.MODERATE, Strength.STRONG)
|
|
512
|
+
})
|
|
513
|
+
evidence = [
|
|
514
|
+
f"Applicable O-1A criteria with moderate+ signals: {met}/8 (threshold: 3)",
|
|
515
|
+
"Sustained acclaim and very-top-of-field totality assessment remain unassessed; a qualifying petition is required.",
|
|
516
|
+
]
|
|
517
|
+
return CriterionResult(
|
|
518
|
+
"o1a", "O-1A Initial Evidence Threshold",
|
|
519
|
+
Strength.MODERATE if met >= 3 else Strength.WEAK, evidence,
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
# ---------------------------------------------------------------------------
|
|
524
|
+
# Aggregate report
|
|
525
|
+
# ---------------------------------------------------------------------------
|
|
526
|
+
|
|
527
|
+
@dataclass
|
|
528
|
+
class EvaluationReport:
|
|
529
|
+
name: str
|
|
530
|
+
nationality: str
|
|
531
|
+
country_of_birth: str | None = None
|
|
532
|
+
eb1a_results: list[CriterionResult] = field(default_factory=list)
|
|
533
|
+
eb1b_results: list[CriterionResult] = field(default_factory=list)
|
|
534
|
+
niw_results: list[CriterionResult] = field(default_factory=list)
|
|
535
|
+
eb2_base: CriterionResult | None = None
|
|
536
|
+
o1a_result: CriterionResult | None = None
|
|
537
|
+
intl_results: list[IntlPathway] = field(default_factory=list)
|
|
538
|
+
|
|
539
|
+
@property
|
|
540
|
+
def eb1a_met_count(self) -> int:
|
|
541
|
+
return sum(1 for r in self.eb1a_results if r.strength in (Strength.MODERATE, Strength.STRONG))
|
|
542
|
+
|
|
543
|
+
@property
|
|
544
|
+
def eb1a_strong_count(self) -> int:
|
|
545
|
+
return sum(1 for r in self.eb1a_results if r.strength == Strength.STRONG)
|
|
546
|
+
|
|
547
|
+
@property
|
|
548
|
+
def eb1a_threshold_met(self) -> bool:
|
|
549
|
+
return self.eb1a_met_count >= 3
|
|
550
|
+
|
|
551
|
+
@property
|
|
552
|
+
def eb1b_met_count(self) -> int:
|
|
553
|
+
criteria = [r for r in self.eb1b_results if r.criterion_id not in ("eb1b_prereq", "eb1b_job")]
|
|
554
|
+
return sum(1 for r in criteria if r.strength in (Strength.MODERATE, Strength.STRONG))
|
|
555
|
+
|
|
556
|
+
@property
|
|
557
|
+
def eb1b_prerequisites_met(self) -> bool:
|
|
558
|
+
prereq = next((r for r in self.eb1b_results if r.criterion_id == "eb1b_prereq"), None)
|
|
559
|
+
job = next((r for r in self.eb1b_results if r.criterion_id == "eb1b_job"), None)
|
|
560
|
+
return (
|
|
561
|
+
bool(prereq and prereq.strength in (Strength.MODERATE, Strength.STRONG))
|
|
562
|
+
and self.eb1b_met_count >= 2
|
|
563
|
+
and bool(job and job.strength in (Strength.MODERATE, Strength.STRONG))
|
|
564
|
+
)
|
|
565
|
+
|
|
566
|
+
@property
|
|
567
|
+
def niw_prongs_met(self) -> bool:
|
|
568
|
+
return (
|
|
569
|
+
{r.criterion_id for r in self.niw_results} == {"niw_1", "niw_2", "niw_3"}
|
|
570
|
+
and all(r.strength in (Strength.MODERATE, Strength.STRONG) for r in self.niw_results)
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
@property
|
|
574
|
+
def niw_signals_supported(self) -> bool:
|
|
575
|
+
return bool(
|
|
576
|
+
self.eb2_base and self.eb2_base.strength == Strength.STRONG
|
|
577
|
+
and self.niw_prongs_met
|
|
578
|
+
)
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
def evaluate(profile: dict, country: str | None = None) -> EvaluationReport:
|
|
582
|
+
validate_profile(profile)
|
|
583
|
+
eb1a = evaluate_eb1a(profile)
|
|
584
|
+
met = sum(1 for r in eb1a if r.strength in (Strength.MODERATE, Strength.STRONG))
|
|
585
|
+
strong = sum(1 for r in eb1a if r.strength == Strength.STRONG)
|
|
586
|
+
if country == "us":
|
|
587
|
+
intl_results: list[IntlPathway] = []
|
|
588
|
+
elif country is None:
|
|
589
|
+
intl_results = evaluate_international(profile, us_met=met, us_strong=strong)
|
|
590
|
+
else:
|
|
591
|
+
intl_results = evaluate_international(profile, us_met=met, us_strong=strong, country=country)
|
|
592
|
+
return EvaluationReport(
|
|
593
|
+
name=profile.get("name", "Unknown"),
|
|
594
|
+
nationality=profile.get("nationality", "Unknown"),
|
|
595
|
+
country_of_birth=profile.get("country_of_birth"),
|
|
596
|
+
eb1a_results=eb1a,
|
|
597
|
+
eb1b_results=evaluate_eb1b(profile),
|
|
598
|
+
niw_results=evaluate_niw(profile),
|
|
599
|
+
eb2_base=evaluate_eb2_base(profile),
|
|
600
|
+
o1a_result=evaluate_o1a(eb1a),
|
|
601
|
+
intl_results=intl_results,
|
|
602
|
+
)
|