Upload processors.py with huggingface_hub
Browse files80 unmodified lines8182838485848586878788899021 unmodified lines11211311411511611711811912012112212312412512612712812913013113219 unmodified lines15215315415515615715815916016116216316416580 unmodified lines
class TakeFirstNonEmptyLine(FieldOperator): def process_value(self, text: Any) -> Any: splitted = str(text).strip().split("\n") if len(splitted) == 0: parts = str(text).strip().split("\n") if len(parts) == 0: return "" return splitted[0].strip() return parts[0].strip()
class ConvertToBoolean(FieldOperator):21 unmodified lines return text.lower()
class Capitalize(FieldOperator): def process_value(self, text: Any) -> Any: return text.capitalize()
class Substring(FieldOperator): begin: int = 0 end: int = None
def process_value(self, text: Any) -> Any: if self.end is None: return text[self.begin :] return text[self.begin : self.end]
class FirstCharacter(FieldOperator): def process_value(self, text: Any) -> Any: match = re.search(r"\s*(\w)", text)19 unmodified lines return text
class StrToFloatFormat(FieldOperator): def process_value(self, text: Any) -> Any: try: return str(float(text)) except Exception: return str(text)
class ToYesOrNone(FieldOperator): def process_value(self, text: Any) -> Any: if text == "yes":processors.py+26-3