Upload processors.py with huggingface_hub
Browse files12349 unmodified lines14151617181920212223import refrom .operator import BaseFieldOperator9 unmodified lines"""regex: strdef process(self, text):matches = re.findall(self.regex, text)return matches# add_to_catalog(ToString('prediction'), 'processors', 'to_string')1234569 unmodified lines161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import jsonimport refrom typing import Anyfrom .operator import BaseFieldOperator9 unmodified lines"""regex: strtermination_regex: str = Nonedef process(self, text):if self.termination_regex is not None and re.fullmatch(self.termination_regex, text):return []matches = re.findall(self.regex, text)return matchesclass LoadJson(BaseFieldOperator):def process(self, text):try:return json.loads(text)except json.JSONDecodeError:return []class ListToEmptyEntitiesTuples(BaseFieldOperator):def process(self, lst):try:return [(str(item), "") for item in lst]except json.JSONDecodeError:return []class DictOfListsToPairs(BaseFieldOperator):position_key_before_value: bool = Truedef process(self, obj):try:result = []for key, values in obj.items():for value in values:assert isinstance(value, str)pair = (key, value) if self.position_key_before_value else (value, key)result.append(pair)return resultexcept:return []# add_to_catalog(ToString('prediction'), 'processors', 'to_string')
processors.py+37