Thursday, June 14, 2012

Calculating Levenshtein Distance Between Two Strings in Fuzuli

Hi! I am so happy I can code with Fuzuli programming language. In this article, I'll show you how to calculate the distance between two strings on Fuzuli. I usually use Levenshtein distance on PHP. This situation is the same on Fuzuli. Before introducing my sample, sharing the Levenshtein function would be nice, I think.






For this article, I've got an example here: 
The code given belown is about how to calculate the distance between strings. 

(require "nfl/io.nfl")
(require "nfl/string.nfl")

(print "Please enter a word for calculating distance: ")
(let word(readline))

(let Array (list "windows" "ubuntu" "android"))

(foreach i in Array
   (block
  (let distance (levenshtein word i))
  (print distance " for " i "\n")
    )
)

(require "nfl/string.nfl")
(require "nfl/io.nfl")


The code shown above shows how we import a required package. string package is for Levenshtein function, namely it is not "fuzuli" :) io package is for readline.


You can run it by typing:

fuzuli levenshtein.fzl
Screen View
Screen View
If you compare screen views, you can see the differency. First, I wrote "fuzuli" and the system has found distances, but when I write "android", the system has found zero distance for "android".


Here, I actually wanted to show you many things. One of'em was how to get a piece of array with foreach. Other one was the point of this article, Levenshtein function. I hope that was enough and helpful for you!


See you!

No comments:

Post a Comment

Thanks