views:

330

answers:

5
+3  Q: 

Rhyme in PHP

I am having a hard time to find a way to detect if two words has the same rhyme in English. It has not to be the same syllabic ending but something closer to phonetically similarity.

I can not believe in 2009 the only way of doing it is using those old fashioned rhyme dictionaries. Do you know any resources (in PHP would be a plus) to help me in this painful task?

Thank you.

Your hints were all really hepful. I will take some time to investigate it. Anyway, more info about DoubleMetaPhone can be found here in a proper PHP code (the other one is an extension). There are interesting information about MethaPhone function and doublemetaphone in Php.net.

They specially alert about how slow double metaphone is compared with metaphone (something like 100 times slower).

A: 

Did you try the soundex() function? It should give you at least some indication if the words sound alike.

i don't think the soundex function is well suited for this. look at the examples - two words that produce the same soundex rhyme almost never. double metaphone may make more sense.
Schnalle
the double metaphone algorithm is available as a pecl package here: http://pecl.php.net/package/doublemetaphone
Schnalle
+1  A: 

Besides the soundex() function ramonzoellner mentioned, there is another function called levenshtein() which calculates the levenshtein distance between the two words. That may help you further.

daddz
+3  A: 

See Bradley Buda's CS project summary from U. Michigan, which uses Levenshtein distance as an atom in finding rhyming English words. I believe combining Levenshtein and soundex should give better results.

Yuval F
+5  A: 

Soundex won't help you. Soundex focuses on the beginning of the word, not its ending. Generally it think you'll have hard time finding any tool to do this. Even to the linguist the root of the word is more interesting, than it's ending.

Generally what you'll have to do is to divide words in syllables and compare their last syllable. Even better if you could divide it in phonemes, reverse their order and do comparison on reversed word.
You might trying comparing last part of metaphone keys.

vartec
Double Metaphone is a nice idea. Alternatively, Sortea2 could reverse the original words and compare their Soundex.
Yuval F
A: 

Seems like you need to find a database containing pronunciation, and possibly stress/emphasis: multisyllabic words with similar last syllables, but stresses on different syllables don't quite rhyme, at least in the sense of being able to use them in poems; e.g. "poems" and "hems". The other answers (levenshtein & soundex) should help for locating candidates, but they won't confirm it:

  • tough
  • cough
  • dough
  • through
  • bough
Jason S