For our final project for CIS552: Advanced Programming, my partner and I implemented a poetry parser. The program identifies a body of text piped from STDIN as one of: haiku, rhyming poem (aba, or aabba), sonnet, or limerick.
The project source is located at: https://github.com/jamiely/poetry-parser.
The project involved using the CMU Pronouncing Dictionary found here, creating parsers for the dictionary, and base parsers that could be combined for various forms.
For example, we implemented a parser for syllables that allows us to create a haiku parser.
1 2 3 4 5 6 7 8 | -- | Parses a Haikuhaiku :: PoemParser RhymeMaphaiku = do ns 5 ns 7 ns 5 return Map.empty where ns = nSyllables |
and a rhyming scheme parser that allowed us to recognize limericks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | aabba :: PoemParser RhymeMapaabba = rhymeScheme &;quot;aabba&quot; Map.empty-- | The stress pattern of a limerick-- note: syllable requirement is implicitlimerickStress :: PoemParser RhymeMaplimerickStress = do stressLine [D,U, D,D,U, D,D,U] stressLine [D,U, D,D,U, D,D,U] stressLine [D,U, D,D,U]<;br /> stressLine [D,U, D,D,U]<;br /> stressLine [D,U, D,D,U, D,D,U]limerick :: PoemParser RhymeMaplimerick = limerickStress &;lt;&;amp;&;gt; aabba |
For example, we can determine the type of the following poem:
An old silent pond… A frog jumps into the pond, splash! Silence again. – Basho
by running the program thusly:
1 | > ./Main < extra/basho.haiku |
with the result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Opened filePoem: An old silent pond...A frog jumps into the pond,splash! Silence again.Dictionary:A AH0AGAIN AH0 G EH1 NAN AE1 NFROG F R AA1 GINTO IH0 N T UW1JUMPS JH AH1 M P SOLD OW1 L DPOND P AA1 N DPOND'S P AA1 N D ZSILENCE S AY1 L AH0 N SSILENT S AY1 L AH0 N TSPLASH S P L AE1 SHTHE DH AH0Type: Haiku |
And the following poem:
something something fox apple jacks word here pox
by running the program thusly:
1 | > ./Main < extra/fox.rhyming |
with the result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Opened filePoem: something something foxapple jacksword here poxDictionary:APPLE AE1 P AH0 LFOX F AA1 K SHERE HH IY1 RJACKS JH AE1 K SPOX P AA1 K SSOMETHING S AH1 M TH IH0 NGWORD W ER1 DType: Rhyming poem: aba |