Measure the pronounceability of a word?

前端 未结 3 1444
闹比i
闹比i 2020-12-05 04:33

I\'m tinkering with a domain name finder and want to favour those words which are easy to pronounce.

Example: nameoic.com (bad) versus namelet.com (good).

Wa

3条回答
  •  猫巷女王i
    2020-12-05 04:57

    Here is a function which should work with the most common of words... It should give you a nice result between 1 (perfect pronounceability according to the rules) to 0.

    The following function far from perfect (it doesn't quite like words like Tsunami [0.857]). But it should be fairly easy to tweak for your needs.

    = 0 && !in_array($word[$pos - 1], $vowels)) {
                    $score += 1;
                    $pos += 1;
                    continue;
                }
            } else { // Not a vowel, check if next one is, or if is end of word
                if (($pos + 1) < $len && in_array($word[$pos + 1], $vowels)) {
                    $score += 2;
                    $pos += 2;
                    continue;
                } elseif (($pos + 1) == $len) {
                    $score += 1;
                    break;
                }
            }
    
            $pos += 1;
        }
    
        return $score / $len;
    }
    

提交回复
热议问题