Search code examples
phpjavascriptdictionarylevenshtein-distance

Any known javascript/php dictionaries like 'word1', 'word2'?


Just recently I was looking up about Levenshtein algorithm and after searching for an hour I couldn't find a javascript file like:

var dictionary =
    [
      'coke',
      'cokeman',
      'cokeney'
      ]

Is there a faster way to do this? I haven't found any files like this and I've heard this function is kind of slow. If I could how could I do this with php?


Solution

  • In order to get that javascript file you could run cat /usr/share/dict/words | sed "s/^.*$/\'&\'\,/g"

    replacing /usr/share/dict/words with a newline separated wordfile. Then all you have to do is add var dictionary = [ and ] maybe throwing in a semicolon at the end if you feel like it.