-
Notifications
You must be signed in to change notification settings - Fork 2
/
pseudocode.txt
130 lines (81 loc) · 3.05 KB
/
pseudocode.txt
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
ITERATION 1
def matchAll():
for item in Avalara_dict:
iterator = UNSPSC_tree
while iterator is not a leaf node:
for child in iterator.child_list:
for word in item.word_list:
for comparator in child.word_list:
if word == comparator:
curr_count += 1
if curr_count > max_count:
max_count = curr_count
max_child = child
iterator = max_child
ITERATION 2
def rabinKarp(pattern, text):
d = 26 # num of letters
q = 5381 # large prime number
m = length of pattern
n = length of text
h = 1
num_matches = 0
for i in range (0 -> m - 1):
h = (h * d) % q
for i in range (0 -> (n - m + 1))
if p == t:
for j in range (0 -> m):
if text[i + j] != pattern[j]:
break
j += 1
if j == m:
num_matches += 1
if i < n - m:
t = (d * h * (t - ord(text[i]) + ord(text[i + m])) % q
if t < 0:
t = t + q
return num_matches
def rabinKarpMatch():
for ava_item in Avalara_dict:
for unspsc_item in UNSPSC_dict:
for word in ava_item.word_list:
curr_count = rabinKarp(word, unspsc_item.string)
if curr_count > max_count:
max_count = curr_count
max_item = unspsc_item
ITERATION 3
def sortedMatch():
for ava_item in Avalara_dict:
max_count = 0, max_item = None
for unspsc_item in UNSPSC_dict():
while ava_index <= ava_lastindex and unspsc_index <= unspsc_lastindex
while ava_index <= ava_lastindex:
while unspsc_index <= unspsc_lastindex:
if ava_item.wordlist[ava_index] == unspsc_item[unspsc_index]:
curr_count += 1
break
else:
unspsc_index += 1
ava_index += 1
if curr_count > max_count:
max_count = curr_count
max_item = unspsc_item
ITERATION 4
def sortedMatch():
for ava_item in Avalara_dict:
max_count = 0, max_item = None
for unspsc_item in UNSPSC_dict():
while ava_index <= ava_lastindex and unspsc_index <= unspsc_lastindex
while ava_index <= ava_lastindex:
while unspsc_index <= unspsc_lastindex:
if ava_item.wordlist[ava_index] == unspsc_item[unspsc_index]:
curr_count += 1
break
elif ava_item.wordlist[ava_index] > unspsc_item[unspsc_index]:
unspsc_index += 1
else:
break
ava_index += 1
if curr_count > max_count:
max_count = curr_count
max_item = unspsc_item