I've created a function I plan to use with a simple spell check I'm adding to a text adventure.
It will certainly work with and predefined dictionary.
word1$ = the source (misspelled) word
word2$ = the proposed correct spelling
The returned value gap is the number of changes/edits need to alter word1$ to word2$
simply loop through all recognized words in program's "dictionary". The closest match (unless it's way off) may included in a message like: "Do you mean, ";
statement before the unknown word; closest valid word$; "?"
DIM dif(16,16)
gap = wordgap("darkwaterpro","darkbasicpro")
PRINT gap
WAIT KEY
END
FUNCTION wordgap(word1$,word2$)
w1 = LEN(word1$)
w2 = LEN(word2$)
FOR lp1 = 0 TO w2
dif(0,lp1)= lp1
NEXT lp1
FOR lp1 = 0 TO w1
dif(lp1,0)=lp1
NEXT lp1
FOR lp1 = 1 TO w1
NEXT lp1
FOR lp1 = 1 TO w1
FOR lp2 = 1 TO w2
IF MID$(word1$,lp1)= MID$(word2$,lp2)
adddif = 0
ELSE
adddif = 1
ENDIF
d1 = dif(lp1-1,lp2-1)
d2 = dif(lp1,lp2-1)
d3 = dif(lp1-1,lp2)
dif(lp1,lp2) = d1
IF d2 < d1 THEN dif(lp1,lp2) = d2
IF d3 < d2 THEN dif(lp1,lp2) = d3
INC dif(lp1,lp2), adddif
NEXT lp2
NEXT lp1
gap =dif(w1,w2)
ENDFUNCTION gap