NaturalNode / natural

general natural language facilities for node
MIT License
10.6k stars 860 forks source link

Determining if words rhyme #166

Open johnmastri opened 10 years ago

johnmastri commented 10 years ago

Trying to find a solution to determine if two words rhyme - is it possible to do this with the current functionality of natural?

Thanks

martijndeb commented 10 years ago

There are soundex and metaphone implementations in Natural. Both can be used. I find this (non Natural) article pretty explainatory for differences and why one is better and both are not 100% covering rhymes a good read. http://www.blackbeltcoder.com/Articles/algorithms/phonetic-string-comparison-with-soundex .

If you want better results you might want to check the soundex of the last part of the word rather than the full word this might help apparent rhyme as well.

chrisumbel commented 10 years ago

Seems to me the problem with Rhyme is that most (at least the ones in natural) phonetic algorithms ignore all but the first vowel except inasmuch as determining the hardness of an adjacent consonant. Reversing words would potentially work if you reversed the order inside the rules perhaps.

One option would be to try to integrate with some online rhyme dictionary's API, but another would be to try to dig up a phonetic algorithm that concerns itself more with vowel pronunciation.