feat(cv-import): add source-grounded review and explicit corrections
This commit is contained in:
@@ -37,6 +37,21 @@ otherSections.N.title or otherSections.N.items.N. Relationships across ambiguous
|
||||
FIELD = re.compile(r"^(?:contact\.(?:fullName|headline|email|phone|location|website|linkedIn|gitHub)|contact\.links\.\d{1,3}\.(?:label|url)|(?:summary|skills|interests|awards|publications|organisations|references)\.\d{1,3}|(?:jobs|education|certifications|projects|languages)\.\d{1,3}\.(?:title|company|name|institution|qualification|qualificationLevel|issuer|role|location|start|end|date|level|notes|(?:bullets|skills|details)\.\d{1,3})|otherSections\.\d{1,3}\.(?:title|items\.\d{1,3}))$")
|
||||
|
||||
|
||||
def _supported_field(field):
|
||||
parts = field.split(".")
|
||||
fields = {
|
||||
"jobs": ({"title", "company", "location", "start", "end"}, {"bullets", "skills"}),
|
||||
"education": ({"institution", "qualification", "qualificationLevel", "location", "start", "end"}, {"details"}),
|
||||
"certifications": ({"name", "issuer", "location", "date"}, {"details"}),
|
||||
"projects": ({"name", "role", "location", "start", "end"}, {"bullets", "skills"}),
|
||||
"languages": ({"name", "level", "notes"}, set()),
|
||||
}
|
||||
if parts[0] not in fields:
|
||||
return bool(FIELD.fullmatch(field))
|
||||
scalar, lists = fields[parts[0]]
|
||||
return bool(FIELD.fullmatch(field)) and ((len(parts) == 3 and parts[2] in scalar) or (len(parts) == 4 and parts[2] in lists))
|
||||
|
||||
|
||||
def _validate_config(config):
|
||||
url = urlsplit(config.base_url)
|
||||
if url.scheme != "http" or url.username or url.password or url.query or url.fragment or url.path not in ("", "/") or not config.model or len(config.model) > 200:
|
||||
@@ -88,7 +103,8 @@ def analyse(blocks, config=None, generate=None):
|
||||
for item in parsed["suggestions"]:
|
||||
if not isinstance(item, dict) or set(item) != {"field", "value", "block_id", "quote"} or any(not isinstance(value, str) or not value.strip() or len(value) > 8000 for value in item.values()):
|
||||
raise ValueError("Invalid model suggestion.")
|
||||
if not FIELD.fullmatch(item["field"]) or item["field"] in seen or item["block_id"] not in by_id or clean(item["quote"]) not in clean(by_id[item["block_id"]]) or clean(item["value"]) not in clean(item["quote"]):
|
||||
grounded_value = re.search(r"(?<![\w+#.])" + re.escape(clean(item["value"])) + r"(?![\w+#.])", clean(item["quote"]))
|
||||
if not _supported_field(item["field"]) or item["field"] in seen or item["block_id"] not in by_id or clean(item["quote"]) not in clean(by_id[item["block_id"]]) or not grounded_value:
|
||||
raise ValueError("Unsupported model suggestion.")
|
||||
seen.add(item["field"])
|
||||
suggestions.append({**item, "method": "model-assisted", "review_state": "needs_review"})
|
||||
|
||||
Reference in New Issue
Block a user