plint

French poetry validator (local mirror of https://gitlab.com/a3nm/plint)
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

count_syllables_lexique.py (583B)


      1 #!/usr/bin/python3
      2 
      3 # count the number of syllables of words according to lexique
      4 
      5 import sys
      6 
      7 vowels = "ae$E2@#u)9ioO(y"
      8 consonants = "dpgmtRwszlbkZjknfvSNJx8"
      9 
     10 for l in sys.stdin.readlines():
     11     f = l.strip().split("\t")
     12     nsyl = 0
     13     for a in f[1]:
     14         if a in vowels:
     15             nsyl += 1
     16         elif a in consonants:
     17             pass
     18         else:
     19             print("unknown phoneme %s" % a, file=sys.stderr)
     20             sys.exit(1)
     21     # workaround bug in lexique
     22     if f[1].endswith("@") and f[0] != "afin de":
     23         nsyl -= 1
     24     print("%s\t%d" % (f[0], nsyl))
     25