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_plint.py (769B)


      1 #!/usr/bin/python3
      2 
      3 import os
      4 import sys
      5 
      6 # modules are in the parent folder
      7 import plint.pattern
      8 from plint.rhyme import Rhyme
      9 from plint.template import Template
     10 from plint.verse import Verse
     11 
     12 sys.path.insert(1, os.path.join(sys.path[0], '..'))
     13 
     14 template = Template()
     15 pattern = plint.pattern.Pattern("12")
     16 
     17 for l in sys.stdin.readlines():
     18     w = (l.strip().split("\t"))[0]
     19     verse = Verse(w, template, pattern)
     20     rhyme = Rhyme(verse.normalized,
     21                   pattern.constraint, template.mergers, template.options)
     22     verse.phon = rhyme.phon
     23     verse.annotate()
     24     mx = 0
     25     mn = 0
     26     for c in verse.chunks:
     27         if 'weights' in c.keys():
     28             mn += min(c['weights'])
     29             mx += max(c['weights'])
     30     print("%s\t%d\t%d" % (w, mn, mx))
     31