text: # Version 1.1
  # 2012 Doug Hogan
  # https://github.com/DigTheDoug/SyllableCounter
  
  # Based on/modified from Joe Basirico's JS code here:
  # http://stackoverflow.com/a/5615724/188221
  
  def CountSyllables(word, isName=True):
      '''
  	Counting syllables,
  	Although prone to some error 
  	makes perfect Haiku 
  
  	This function is taken from https://github.com/DigTheDoug/SyllableCounter
  	More accurate would have been textstat library, not at available in Athena
  	
      '''
  
  	#import textstat
  	#return textstat.textstat.syllable_count( word )	
  
      vowels = "aeiouy"
      #single syllables in words like bread and lead, but split in names like Breanne and Adreann
      specials = ["ia","ea"] if isName else ["ia"]
      specials_except_end = ["ie","ya","es","ed"]  #seperate syllables unless ending the word
      currentWord = word.lower()
      numVowels = 0
      lastWasVowel = False
      last_letter = ""
  
      for letter in currentWord:
          if letter in vowels:
              #don't count diphthongs unless special cases
              combo = last_letter+letter
              if lastWasVowel and combo not in specials and combo not in specials_except_end:
                  lastWasVowel = True
              else:
                  numVowels += 1
                  lastWasVowel = True
          else:
              lastWasVowel = False
  
          last_letter = letter
  
      #remove es & ed which are usually silent
      if len(currentWord) > 2 and currentWord[-2:] in specials_except_end:
          numVowels -= 1
  
      #remove silent single e, but not ee since it counted it before and we should be correct
      elif len(currentWord) > 2 and currentWord[-1:] == "e" and currentWord[-2:] != "ee":
          numVowels -= 1
  
      return numVowels
  