Upload processors.py with huggingface_hub
Browse files12345678108 unmodified lines11711811912012112229 unmodified lines152153154155156157import jsonimport refrom typing import Anyfrom .operators import FieldOperatorclass ToString(FieldOperator):108 unmodified linesreturn text.capitalize()class Substring(FieldOperator):begin: int = 0end: int = None29 unmodified linesreturn textclass StrToFloatFormat(FieldOperator):def process_value(self, text: Any) -> Any:try:123456789108 unmodified lines11811912012112212312412512612712812913013113213313413513613713813914014114214314414529 unmodified lines175176177178179180181182183184185186187import jsonimport refrom difflib import get_close_matchesfrom typing import Any, Dictfrom .operators import FieldOperator, InstanceFieldOperatorclass ToString(FieldOperator):108 unmodified linesreturn text.capitalize()class GetStringAfter(FieldOperator):substring: strdef process_value(self, text: Any) -> Any:return text.split(self.substring, 1)[-1].strip()class MatchClosestOption(InstanceFieldOperator):options_field: str = "options"def process_instance_value(self, value: Any, instance: Dict[str, Any]):options = instance["task_data"][self.options_field]return get_close_matches(value, options, n=1, cutoff=0.0)[0]def process_instance_value(self, value, instance):options = instance[self.options_field]# Get the closest match; n=1 returns the single closest matchclosest_match = get_close_matches(value, options, n=1, cutoff=0)return closest_match[0] if closest_match else Noneclass Substring(FieldOperator):begin: int = 0end: int = None29 unmodified linesreturn textclass YesToOneElseZero(FieldOperator):def process_value(self, text: Any) -> Any:if text == "yes":return "1"return "0"class StrToFloatFormat(FieldOperator):def process_value(self, text: Any) -> Any:try:
processors.py+32-2