# SPELL.BAS -- VERSION 4

September 10 2007 at 3:34 PM

Response to Spell Check Program

DECLARE FUNCTION DISTANCE% (S\$, T\$)
DECLARE FUNCTION MINIMUM% (A%, B%, C%)
DEFINT A-Z
OPEN "DICT.DAT" FOR INPUT AS #1
OPEN "RESULTS.TMP" FOR OUTPUT AS #2
INPUT SEARCH\$
SEARCH\$ = LTRIM\$(RTRIM\$(UCASE\$(SEARCH\$)))
WHILE NOT EOF(1)
INPUT #1, WORD\$
WORD\$ = UCASE\$(WORD\$)
IF DISTANCE(WORD\$, SEARCH\$) < 2 THEN PRINT #2, WORD\$; " "
WEND
CLOSE #1
CLOSE #2
SHELL "FIND /I /C " + CHR\$(34) + SEARCH\$ + CHR\$(32) + CHR\$(34) + " RESULTS.TMP > FOUND.TMP"
OPEN "FOUND.TMP" FOR INPUT AS #1
INPUT #1, LINE\$: INPUT #1, LINE\$
IF INSTR(LINE\$, " 0") THEN SHELL "MORE RESULTS.TMP": END ELSE PRINT "IN DICTIONARY"
CLOSE #1
SHELL "DEL *.TMP"
END

FUNCTION DISTANCE (S\$, T\$)
' RETURNS THE LEVENSHTEIN DISTANCE BETWEEN TWO STRINGS
DIM D(0 TO LEN(S\$), 0 TO LEN(T\$))
FOR I = 0 TO LEN(S\$)
D(I, 0) = I
NEXT
FOR J = 1 TO LEN(T\$)
D(0, J) = J
NEXT
FOR I = 1 TO LEN(S\$)
FOR J = 1 TO LEN(T\$)
IF MID\$(S\$, I, 1) = MID\$(T\$, J, 1) THEN COST = 0 ELSE COST = 1
A = D(I - 1, J) + 1
IF J = LEN(T\$) THEN B = 32767 ELSE B = D(I, J + 1) + 2
C = D(I - 1, J - 1) + COST
D(I, J) = MINIMUM(A, B, C)
NEXT
NEXT
DISTANCE = D(LEN(S\$), LEN(T\$))
END FUNCTION

FUNCTION MINIMUM (A, B, C)
IF A <= B AND A <= C THEN MINIMUM = A
IF B <= A AND B <= C THEN MINIMUM = B
IF C <= A AND C <= B THEN MINIMUM = C
END FUNCTION

 Respond to this message