57 lines
1.2 KiB
Text
57 lines
1.2 KiB
Text
' version 09-10-2016
|
|
' compile with: fbc -s console
|
|
|
|
#Macro max(x, y)
|
|
IIf((x) > (y), (x), (y))
|
|
#EndMacro
|
|
|
|
#Macro min(x, y)
|
|
IIf((x) < (y), (x), (y))
|
|
#EndMacro
|
|
|
|
Function jaro(word1 As String, word2 As String) As Double
|
|
|
|
If Len(word1) > Len(word2) Then Swap word1, word2
|
|
|
|
Dim As Long i, j, j1, m, t
|
|
Dim As Long s1 = Len(word1)
|
|
Dim As Long s2 = Len(word2)
|
|
Dim As Long max_dist = s2 \ 2 -1 ' integer division
|
|
|
|
For i = 0 To s1 -1
|
|
If word1[i] = word2[j] Then
|
|
m = m +1
|
|
word2[j] = 32
|
|
Else
|
|
For j1 = max(0, i - max_dist) To min(s2 -1, i + max_dist)
|
|
If word1[i] = word2[j1] Then
|
|
t = t +1
|
|
m = m +1
|
|
word2[j1] = 32
|
|
If j1 > j Then j = j1
|
|
End If
|
|
Next
|
|
End If
|
|
j = j + 1
|
|
Next
|
|
|
|
If m = 0 Then Return 0
|
|
|
|
t = t \ 2
|
|
Return (m / s1 + m / s2 + ((m - t) / m)) / 3
|
|
|
|
End Function
|
|
|
|
' ------=< MAIN >=------
|
|
|
|
Print
|
|
Print " jaro (MARTHA, MARHTA) ="; jaro("MARTHA", "MARHTA")
|
|
Print " jaro (DIXON, DICKSONX) ="; jaro("DIXON", "DICKSONX")
|
|
Print " jaro (JELLYFISH, SMELLYFISH) ="; jaro("JELLYFISH", "SMELLYFISH")
|
|
|
|
|
|
' empty keyboard buffer
|
|
While Inkey <> "" : Wend
|
|
Print : Print "hit any key to end program"
|
|
Sleep
|
|
End
|