File size: 993 Bytes
3018c75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#

import cc_net.text_normalizer as txt


def test_unicode_punct():
    weird = ",。、„”“«»1」「《》´∶:?!();–—.~’…━〈〉【】%"
    replaced = ',.,""""""""""\'::?!();- - . ~\'...-<>[]%'
    assert txt.replace_unicode_punct(weird) == replaced

    assert txt.remove_unicode_punct(weird) == ""


def test_numbers():
    weird = "023456789 | 0123456789"
    normalized = "000000000 | 0000000000"
    assert txt.normalize(weird, numbers=True) == normalized
    assert txt.normalize(weird, numbers=False) == weird


def test_normalize_for_dedup():
    weird = "023´∶:\x10 | ;012 hèllo"
    normalized = "000 | ;000 hèllo"
    assert normalized == txt.slow_normalize_for_dedup(weird)
    assert normalized == txt.normalize_for_dedup(weird)