Spaces:
Sleeping
Sleeping
File size: 755 Bytes
abcd0c2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from __future__ import annotations
from typing import Any, Dict, List, Optional, Tuple
from .spacy_extractor import VALID_SPACY_LABELS
def validate_mappings(fields: Dict[str, Dict[str, Any]]) -> Tuple[bool, Optional[Dict]]:
invalid: List[str] = []
for field_name, rule in fields.items():
if rule.get("source_type") == "entity":
label = rule.get("label", "")
if label not in VALID_SPACY_LABELS:
invalid.append(label)
if not invalid:
return True, None
return False, {
"invalid_labels": invalid,
"valid_labels": VALID_SPACY_LABELS,
"suggestion": (
"Use source_type 'regex' for custom patterns not covered by spaCy NER labels."
),
}
|