Upload processors.py with huggingface_hub
Browse files12334556789108 unmodified lines11811912012112212312412512612712812913013113213313413513613713813914014114214314414529 unmodified lines175176177178179180181182183184185186187import jsonimport refrom difflib import get_close_matchesfrom typing import Anyfrom typing import Any, Dict
from .operators import FieldOperatorfrom .operators import FieldOperator, InstanceFieldOperator
class ToString(FieldOperator):108 unmodified lines return text.capitalize()
class GetStringAfter(FieldOperator): substring: str
def 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 match closest_match = get_close_matches(value, options, n=1, cutoff=0) return closest_match[0] if closest_match else None
class Substring(FieldOperator): begin: int = 0 end: int = None29 unmodified lines return text
class 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