-
Notifications
You must be signed in to change notification settings - Fork 0
/
similitud.h
230 lines (196 loc) · 5.07 KB
/
similitud.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//
// Created by jorge on 25-11-17.
//
#ifndef SIMILITUD_SIMILITUD_H
#define SIMILITUD_SIMILITUD_H
#endif //SIMILITUD_SIMILITUD_H
#include <string.h>
#define TAMAN_DIC 77455 //8606 //7746 // 77455
#define NUM_PIV 32
#define NUM_QUERYS 8606 //34 //860 //8606
#define MAX_LINE 28 //34 //860 //8606
//#define TAMAN_B 32
extern long int cuentaeditdist;
int min_antigua(int a, int b, int c){
if(a<=b && a<=c)
{
return a;
}
else if(b<=a && b<=c)
{
return b;
}
return c;
}
int min(int a, int b)
{
if (a<b)
return a;
return b;
}
int edit(char *s1, char *s2, int x1, int x2)
{
//int N1; // = strlen(s1);
int N2; // = strlen(s2);
int i, j, retorno, corner, upper;
int T[MAX_LINE+1];
cuentaeditdist++;
/*T = (int *)malloc(sizeof(int)*(N2+1));*/
for ( i = 0; s2[(x2*MAX_LINE)+i]!= '\0'; i++ )
T[i] = i;
T[i]=i; /*1 mas*/
N2=i;
for ( i = 0; s1[(x1*MAX_LINE)+i]!= '\0' /*i < N1*/; i++ )
{
T[0] = i+1;
corner = i;
for ( j = 0; j < N2; j++ )
{
upper = T[j+1];
if ( s1[(x1*MAX_LINE)+i] == s2[(x2*MAX_LINE)+j] )
T[j+1] = corner;
else
T[j+1] = min(T[j], min(upper, corner)) + 1;
corner = upper;
}
}
retorno = T[N2];
/*free(T);*/
return retorno;
}
int edit_2011yantes (char *q, char *p, int x, int i)
{
int j,ind_q,ind_p, pos=0, aux_dis;
int min_iz,min_ar,min_di;
int tam_q,tam_p;
int encontrado_q,encontrado_p;
char vector_aux[MAX_LINE], caldis[MAX_LINE*MAX_LINE];//MAX_LINE*MAX_LINE=784
//vector_aux = (char *) malloc(sizeof(char)*MAX_LINE);
//caldis = (char *) malloc(sizeof(char)*MAX_LINE*MAX_LINE);
cuentaeditdist++;
for (j = 0; j<MAX_LINE; j++)
vector_aux[j] = j;
ind_q = -1;
encontrado_q = 0;
encontrado_p = 0;
for(j = 0; j<(MAX_LINE*MAX_LINE) && encontrado_q!= 1; j++)
{
//caldis[pos+j] = x;
if (j%MAX_LINE == 0)
{
ind_q++;
ind_p=-1;
}
ind_p++;
if (j < MAX_LINE) //PRIMERA FILA
{
if (q[(x*MAX_LINE)+ind_q]== p[(i*MAX_LINE)+ind_p])//vector aux es de un elemento mas
min_di = vector_aux[j] + 0;
else
min_di = vector_aux[j] + 1;
if (j == 0)
min_iz = vector_aux[j+1] + 1;
else
min_iz = caldis[(pos+j)-1] + 1;
min_ar = vector_aux[j+1] + 1;
caldis[pos+j] = (char)min_antigua(min_di,min_iz,min_ar);
if (p[(i*MAX_LINE)+ind_p] == 0 && !encontrado_p){ // 0 == caracter nulo
tam_p = ind_p - 1;
encontrado_p = 1;
}
}
else if(j%MAX_LINE == 0)//PRIMERA COLUMNA
{
if ( q[(x*MAX_LINE)+ind_q]== p[(i*MAX_LINE)+ind_p])//vector aux es de un elemento mas
min_di = vector_aux[ind_q] + 0;
else
min_di = vector_aux[ind_q ] + 1;
min_iz = vector_aux[ind_q + 1] + 1;
min_ar = caldis[(pos+j)-MAX_LINE] + 1;
caldis[pos+j] = (char)min_antigua(min_di,min_iz,min_ar);
}
else
{
if (q[(x*MAX_LINE)+ind_q]== p[(i*MAX_LINE)+ind_p])//vector aux es de un elemento mas
min_di = caldis[(((pos+j) - MAX_LINE) - 1)] + 0;
else
min_di = caldis[(((pos+j) - MAX_LINE) - 1)] + 1;
min_iz = caldis[(pos+j)-1] + 1;
min_ar = caldis[(pos+j)-MAX_LINE] + 1;
caldis[pos+j] = (char)min_antigua(min_di,min_iz,min_ar);
if (encontrado_p == 1 && encontrado_q == 1 && (j+1)%tam_q==0)
{
j= j+(tam_q-j);
}
}
if (q[(x*MAX_LINE)+ind_q] == 0 && !encontrado_q)
{
tam_q = ind_q - 1;
encontrado_q = 1;
}
}//FIN FOR j
aux_dis = caldis[pos + (tam_q*MAX_LINE)+tam_p];
//free(caldis);
//free(vector_aux);
return aux_dis;
} /*end edit*/
/*int edit (char *p1, char *p2)
{
int c[1000];
int pcc;
int nc;
int j;
int i;
char cc;
int m = strlen (p1);
nc = m;
p1--;
for (j = 0; j <= m; j++)
c[j] = j;
for (i = 0; cc = p2[i]; i++)
{
pcc = i;
nc = i + 1;
for (j = 1; j <= m; j++)
{
if (c[j] < nc)
nc = c[j];
pcc += (cc != p1[j]);
if (pcc <= nc)
nc = pcc;
else
nc++;
pcc = c[j];
c[j] = nc;
}
}
return (int) nc;
}*/
void ordearr(unsigned int* array,int inf, int sup)
{
int elem_div=array[sup];
int temp;
int i = inf - 1;
int j = sup;
int cont = 1;
if (inf >= sup)
return;
while (cont)
{
while (array[++i] < elem_div);
while (array[--j] > elem_div);
if (i < j)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
else
cont = 0;
}
temp = array[i];
array[i] = array[sup];
array[sup] = temp;
ordearr (array, inf, i - 1);
ordearr(array, i + 1, sup);
}