-
Notifications
You must be signed in to change notification settings - Fork 191
/
test_clean_email_mapper.py
55 lines (44 loc) · 1.77 KB
/
test_clean_email_mapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unittest
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.clean_email_mapper import CleanEmailMapper
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class CleanEmailMapperTest(DataJuicerTestCaseBase):
def _run_clean_email(self, op, samples):
dataset = Dataset.from_list(samples)
dataset = dataset.map(op.process, batch_size=2)
for data in dataset:
self.assertEqual(data['text'], data['target'])
def test_clean_email(self):
samples = [{
'text': 'happy day [email protected]',
'target': 'happy day '
}, {
'text': '请问你是谁[email protected]',
'target': '请问你是谁[email protected]'
}, {
'text': 'ftp://examplema-niè[email protected]',
'target': 'ftp://examplema-niè'
}, {
'text': '👊[email protected]',
'target': '👊'
}]
op = CleanEmailMapper()
self._run_clean_email(op, samples)
def test_replace_email(self):
samples = [{
'text': 'happy day [email protected]',
'target': 'happy day <EMAIL>'
}, {
'text': '请问你是谁[email protected]',
'target': '请问你是谁[email protected]'
}, {
'text': 'ftp://examplema-niè[email protected]',
'target': 'ftp://examplema-niè<EMAIL>'
}, {
'text': '👊[email protected]',
'target': '👊<EMAIL>'
}]
op = CleanEmailMapper(repl='<EMAIL>')
self._run_clean_email(op, samples)
if __name__ == '__main__':
unittest.main()