-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_common.py
More file actions
49 lines (37 loc) · 1.26 KB
/
Copy pathtest_common.py
File metadata and controls
49 lines (37 loc) · 1.26 KB
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
from common import get_ngram, get_match_size, get_trim_string
def test_ngram_1():
sentence = '我是孙维松'
n_size = 2
print(get_ngram(sentence, n_size))
def test_ngram_2():
sentence = '中华人民共和国'
n_size = 1
print(get_ngram(sentence, n_size))
def test_match_size_1():
cand = '我是中华人民共和国公民'
ref = '中华人民的一份子我'
n_size = 2
cand_ngram = get_ngram(cand, n_size)
ref_ngram = get_ngram(ref, n_size)
match_size, cand_size = get_match_size(cand_ngram, ref_ngram)
print('match size: {}'.format(match_size))
print('cand size: {}'.format(cand_size))
def test_match_size_2():
cand = '我我我我我我'
ref = '中华人民的一份子我'
n_size = 1
cand_ngram = get_ngram(cand, n_size)
ref_ngram = get_ngram(ref, n_size)
match_size, cand_size = get_match_size(cand_ngram, ref_ngram)
print('match size: {}'.format(match_size))
print('cand size: {}'.format(cand_size))
def test_trim_string():
sentence = '我的, 达芬奇激发的 扩大。'
sentence = get_trim_string(sentence)
print(sentence)
if __name__ == '__main__':
test_ngram_1()
test_ngram_2()
test_match_size_1()
test_match_size_2()
test_trim_string()