Last active
December 27, 2015 17:19
-
-
Save damianmoore/7361670 to your computer and use it in GitHub Desktop.
Syllables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VOWELS = ['a', 'e', 'i', 'o', 'u',] | |
def syllables(word): | |
''' Really basic syllable counter ''' | |
num = 0 | |
previously_vowel = False | |
for char in word: | |
if char in VOWELS: | |
if not previously_vowel: | |
num += 1 | |
previously_vowel = True | |
else: | |
previously_vowel = False | |
return num | |
from hyphen import Hyphenator | |
def syllables2(word): | |
''' Better syllable counter using PyHyphen ''' | |
h_gb = Hyphenator('en_GB') | |
return len(h_gb.syllables(u'ligature')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment