Hello,
I'm working on a string comparison function based on the Levenshtein algorithm as a ranking between titles that the user can pick from. This needs a two dimensional array.
I've tried:
d: array[0..10][0..10] of integer;
d: array[0..10, 0..10] of integer;
but both give errors (expecting the 'of' keyword). Looking through other scripts, they define single dimensional arrays only.
How would I define a two dimensional array?
Thanks
Multiple Arrays, String Comparisons
[REQ] Multiple Arrays, String Comparisons
Lucky you green !
I get a type mismatch when trying to implement the Array of Array of integer with the SetLength method given by antp.
By the way no other method seems to work.
Did you finaly succeed with your script ?
Here's the code :
Can someone help me ?
Thanks.
I get a type mismatch when trying to implement the Array of Array of integer with the SetLength method given by antp.
By the way no other method seems to work.
Did you finaly succeed with your script ?
Here's the code :
Code: Select all
function Levenshtein(strWord1, strWord2: String; CoutSubst: Integer ): Integer;
Var
Matrix : Array of Array of integer;
L,C,H,W,R: Integer; // Line, Column, Heigt, Width
Begin
H := Length(strWord1);
W := Length(strWord2);
SetLength(Matrix, 3); // <-- Here I get a type mismatch without any reason at all to me !
SetLength(Matrix[0], H + 1);
SetLength(Matrix[1], W + 1);
For L := 0 to H do
Matrix[0, L] := L;
For C := 1 to W do
Begin
Matrix[1, 0] := C;
For L := 1 to H do
Begin
R := Min(Matrix[0, L]+1, Matrix[1, L-1]+1);
If strWord1[L] = strWord2[C] then
Matrix[1,L] := Min(R, Matrix[0,L-1])
Else
Matrix[1,L] := Min(R, Matrix[0,L-1] + CoutSubst);
End;
Matrix[2] := Matrix[0];
Matrix[0] := Matrix[1];
Matrix[1] := Matrix[2];
End;
Levenshtein := Matrix[0,H];
End;
Thanks.