Upload processors.py with huggingface_hub
Browse files- processors.py +26 -3
processors.py
CHANGED
|
@@ -81,10 +81,10 @@ class DictOfListsToPairs(FieldOperator):
|
|
| 81 |
|
| 82 |
class TakeFirstNonEmptyLine(FieldOperator):
|
| 83 |
def process_value(self, text: Any) -> Any:
|
| 84 |
-
|
| 85 |
-
if len(
|
| 86 |
return ""
|
| 87 |
-
return
|
| 88 |
|
| 89 |
|
| 90 |
class ConvertToBoolean(FieldOperator):
|
|
@@ -112,6 +112,21 @@ class LowerCase(FieldOperator):
|
|
| 112 |
return text.lower()
|
| 113 |
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
class FirstCharacter(FieldOperator):
|
| 116 |
def process_value(self, text: Any) -> Any:
|
| 117 |
match = re.search(r"\s*(\w)", text)
|
|
@@ -137,6 +152,14 @@ class YesNoToInt(FieldOperator):
|
|
| 137 |
return text
|
| 138 |
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
class ToYesOrNone(FieldOperator):
|
| 141 |
def process_value(self, text: Any) -> Any:
|
| 142 |
if text == "yes":
|
|
|
|
| 81 |
|
| 82 |
class TakeFirstNonEmptyLine(FieldOperator):
|
| 83 |
def process_value(self, text: Any) -> Any:
|
| 84 |
+
parts = str(text).strip().split("\n")
|
| 85 |
+
if len(parts) == 0:
|
| 86 |
return ""
|
| 87 |
+
return parts[0].strip()
|
| 88 |
|
| 89 |
|
| 90 |
class ConvertToBoolean(FieldOperator):
|
|
|
|
| 112 |
return text.lower()
|
| 113 |
|
| 114 |
|
| 115 |
+
class Capitalize(FieldOperator):
|
| 116 |
+
def process_value(self, text: Any) -> Any:
|
| 117 |
+
return text.capitalize()
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class Substring(FieldOperator):
|
| 121 |
+
begin: int = 0
|
| 122 |
+
end: int = None
|
| 123 |
+
|
| 124 |
+
def process_value(self, text: Any) -> Any:
|
| 125 |
+
if self.end is None:
|
| 126 |
+
return text[self.begin :]
|
| 127 |
+
return text[self.begin : self.end]
|
| 128 |
+
|
| 129 |
+
|
| 130 |
class FirstCharacter(FieldOperator):
|
| 131 |
def process_value(self, text: Any) -> Any:
|
| 132 |
match = re.search(r"\s*(\w)", text)
|
|
|
|
| 152 |
return text
|
| 153 |
|
| 154 |
|
| 155 |
+
class StrToFloatFormat(FieldOperator):
|
| 156 |
+
def process_value(self, text: Any) -> Any:
|
| 157 |
+
try:
|
| 158 |
+
return str(float(text))
|
| 159 |
+
except Exception:
|
| 160 |
+
return str(text)
|
| 161 |
+
|
| 162 |
+
|
| 163 |
class ToYesOrNone(FieldOperator):
|
| 164 |
def process_value(self, text: Any) -> Any:
|
| 165 |
if text == "yes":
|