Sponsors

Flash Games Page 3

Posted by Darshan Patil Sat, 11 Nov 2006 23:00:00 GMT

I’m going to keep this one short, I am in the process of creating a flash games website. You can see a preliminary version of the site here. It is functional right now and I have a lot of features I want to add to this page. Just wanted something interesting to learn while I learn PHP.

I will make the code available for download along with the data once I am finished.

Update:

I was wasting too much time with PHP. I rewrote the whole thing with Ruby on Rails. Not bad for one day of work. The game data is from a turnkey script I downloaded.

Phonetic searches 2

Posted by Darshan Patil Fri, 22 Sep 2006 21:17:00 GMT

Soundex is an algorithm for indexing names by their sound in English. This algorithm tries to encode words with roughly the same pronounciation to the same string. It is a very well known algorithm. Even David E Knuth mentions it in his magnum opus.

The algorithm is as follows: ( courtesy Wikipedia )
  1. Retain the first letter of the string
  2. Remove all occurrences of the following letters, unless it is the first letter:
    a, e, h, i, o, u, w, y
  3. Assign numbers to the remaining letters (after the first) as follows:
    • b, f, p, v = 1
    • c, g, j, k, q, s, x, z = 2
    • d, t = 3
    • l = 4
    • m, n = 5
    • r = 6
  4. If two or more letters with the same number were adjacent in the original name (before step 1), or adjacent except for any intervening h and w (American census only), then omit all but the first.
  5. Return the first four bytes padded with 0.

Applications:

  1. You can use it to suggest words that a user may have misspelt
  2. You can use it for phonetic searches.

I needed this for an application which required phonetic searches. Here is sample code in Ruby

#require 'profile'

class Soundex
 def Soundex.encode(word)
   puts "You entered #{word}"
   word = word.upcase()
   first_character = word[0]
   word = word.gsub(/[AEIOUHWY]/, '0')
   word = word.gsub(/[BFPV]/, '1')
   word = word.gsub(/[CGJKQSXZ]/, '2')
   word = word.gsub(/[DT]/, '3')
   word = word.gsub(/[L]/, '4')
   word = word.gsub(/[MN]/, '5')
   word = word.gsub(/[R]/, '6')
   word[0] = first_character

   # Remove duplicates
   temp = ""
   last_byte = 0
   word.each_byte do |curr_byte|
     temp << curr_byte if curr_byte != last_byte
     last_byte = curr_byte
   end
   word = temp

   #Remove zeros
   word = word.gsub(/0/, '')

   #Pad if necessary
   while( word.length() < 4 )
     word << '0'
   end

   word = word[0,4]

   puts "'#{word}'"
 end
end

if __FILE__ == $0
 Soundex.encode("Great")
 Soundex.encode("Grate")

 Soundex.encode("Robert")
 Soundex.encode("Rupert")
 Soundex.encode("Rubin")
end