Upload processors.py with huggingface_hub
Browse files- processors.py +14 -0
processors.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
from .operator import BaseFieldOperator
|
2 |
|
3 |
|
@@ -6,4 +8,16 @@ class ToString(BaseFieldOperator):
|
|
6 |
return str(instance)
|
7 |
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
# add_to_catalog(ToString('prediction'), 'processors', 'to_string')
|
|
|
1 |
+
import re
|
2 |
+
|
3 |
from .operator import BaseFieldOperator
|
4 |
|
5 |
|
|
|
8 |
return str(instance)
|
9 |
|
10 |
|
11 |
+
class RegexParser(BaseFieldOperator):
|
12 |
+
"""
|
13 |
+
A processor that uses regex in order to parse a string.
|
14 |
+
"""
|
15 |
+
|
16 |
+
regex: str
|
17 |
+
|
18 |
+
def process(self, text):
|
19 |
+
matches = re.findall(self.regex, text)
|
20 |
+
return matches
|
21 |
+
|
22 |
+
|
23 |
# add_to_catalog(ToString('prediction'), 'processors', 'to_string')
|