Elron commited on
Commit
1545557
1 Parent(s): 1f56124

Upload processors.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. processors.py +46 -0
processors.py CHANGED
@@ -75,6 +75,16 @@ class TakeFirstNonEmptyLine(BaseFieldOperator):
75
  return splitted[0].strip()
76
 
77
 
 
 
 
 
 
 
 
 
 
 
78
  class LowerCaseTillPunc(BaseFieldOperator):
79
  def process(self, instance):
80
  non_empty_line = instance.lower()
@@ -85,6 +95,11 @@ class LowerCaseTillPunc(BaseFieldOperator):
85
  return non_empty_line
86
 
87
 
 
 
 
 
 
88
  class FirstCharacter(BaseFieldOperator):
89
  def process(self, instance):
90
  match = re.search(r"\s*(\w)", instance)
@@ -93,6 +108,37 @@ class FirstCharacter(BaseFieldOperator):
93
  return ""
94
 
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  class StringOrNotString(BaseFieldOperator):
97
  string: str
98
 
 
75
  return splitted[0].strip()
76
 
77
 
78
+ class ConvertToBoolean(BaseFieldOperator):
79
+ def process(self, instance):
80
+ clean_instance = str(instance).strip().lower()
81
+ if any(w in clean_instance for w in ["no", "not", "wrong", "false"]):
82
+ return "FALSE"
83
+ if any(w in clean_instance for w in ["yes", "right", "correct", "true"]):
84
+ return "TRUE"
85
+ return "OTHER"
86
+
87
+
88
  class LowerCaseTillPunc(BaseFieldOperator):
89
  def process(self, instance):
90
  non_empty_line = instance.lower()
 
95
  return non_empty_line
96
 
97
 
98
+ class LowerCase(BaseFieldOperator):
99
+ def process(self, instance):
100
+ return instance.lower()
101
+
102
+
103
  class FirstCharacter(BaseFieldOperator):
104
  def process(self, instance):
105
  match = re.search(r"\s*(\w)", instance)
 
108
  return ""
109
 
110
 
111
+ class TakeFirstWord(BaseFieldOperator):
112
+ def process(self, instance):
113
+ match = re.search(r"[\w]+", instance)
114
+ if match:
115
+ return instance[match.start() : match.end()]
116
+ return ""
117
+
118
+
119
+ class YesNoToInt(BaseFieldOperator):
120
+ def process(self, instance):
121
+ if instance == "yes":
122
+ return "1"
123
+ return "0"
124
+
125
+
126
+ class ToYesOrNone(BaseFieldOperator):
127
+ def process(self, instance):
128
+ if instance == "yes":
129
+ return "yes"
130
+ return "none"
131
+
132
+
133
+ class StanceToProCon(BaseFieldOperator):
134
+ def process(self, instance):
135
+ if instance == "positive":
136
+ return "PRO"
137
+ if instance in ["negative", "suggestion"]:
138
+ return "CON"
139
+ return "none"
140
+
141
+
142
  class StringOrNotString(BaseFieldOperator):
143
  string: str
144