-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_diff_match_patch.py
executable file
·62 lines (46 loc) · 1.44 KB
/
search_diff_match_patch.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
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
from diff_match_patch import diff_match_patch
def search(key, text, from_position=0):
diff = diff_match_patch()
start = diff.match_main(text, key, from_position)
if start < 0: return
better_start = start
eol_left = text.rfind('\n', 0, start)
if eol_left >= 0:
better_start = eol_left + 1;
end = text.find('\n', start+1)
if start < end:
return text[better_start:end]
if __name__ == '__main__':
key = ' 16 kbit/s Return Channel DCH Data Rate'
file_path = './test_files/feature_name.txt'
def test_search():
with open(file_path, 'r') as f:
text = f.read()
print search(key, text)
def print_list(in_list):
for line in in_list:
print line
def test_diff_match_patch():
diff = diff_match_patch()
with open(file_path, 'r') as f:
text = f.read()
#print text
result = diff.match_main(text, key, 0)
print result
def test_diff_main():
diff = diff_match_patch()
with open(file_path, 'r') as f:
text = f.read()
lines = text.splitlines()
i = 0
for line in lines:
print line
print diff.diff_main(line, key)
i += 1
if i > 4: return
def test():
#test_diff_match_patch()
#test_search()
test_diff_main()
test()