Jamie Ly () and Nicholas McAvoy ()
A legacy Haskell (2011) poetry parser/classifier, modernized to compile and run on current toolchains (GHC 9.x, Docker, 2026-era systems).
docker build -t poetry-parser .
printf 'fox\nvision\npox\n' | docker run --rm -i poetry-parserExpected final line:
Type: Rhyming poem: aba
Given a poem on stdin, the app tries to classify it as one of:
- Rhyming poem (
aba) - Rhyming poem (
aabba) - Haiku
- Limerick
- Iambic pentameter
- Shakespearean-sonnet style rhyme schemes
If no parser matches, it prints unsupported form.
This repository was updated to run on modern Haskell environments:
-
Prelude
Wordconflict fixed- The project defines its own
Wordtype. Modern Prelude also exportsWord, causing ambiguity. - Fixed by hiding Prelude’s
Wordwhere needed.
- The project defines its own
-
Parser instances updated for modern GHC
- Older code defined only
MonadforPoemParser. - Modern GHC requires
FunctorandApplicativesuperclasses too. - Added
FunctorandApplicativeinstances.
- Older code defined only
-
Dictionary handling made robust
- Original code used a hardcoded dictionary path.
- Now dictionary path selection is:
CMUDICT_PATH(if set)extra/cmudict.0.7adictionary-small.txtfallback
-
Build setup modernized
- Removed obsolete platform-specific linker flags in
Makefile. - Added Docker support for reproducible builds/runs.
- Removed obsolete platform-specific linker flags in
Download a full CMU dictionary into extra/cmudict.0.7a:
make dictionaryYou can still run without this file; the app will use dictionary-small.txt.
Requirements:
ghcmakeHUnitpackage (libghc-hunit-devon Debian/Ubuntu)
Build:
make clean
make Main./Main < extra/fox.rhyming
./Main < extra/arb.hkuUse a custom dictionary:
CMUDICT_PATH=/path/to/cmudict ./Main < extra/fox.rhymingBuild image:
docker build -t poetry-parser .Run with sample input file:
docker run --rm -i poetry-parser < extra/fox.rhymingRun with inline sample input:
printf 'fox\nvision\npox\n' | docker run --rm -i poetry-parserInput:
fox
vision
pox
Output:
Using dictionary: dictionary-small.txt
Poem:
fox
vision
pox
Dictionary:
FOX F AA1 K S
POX P AA1 K S
VISION V IH1 ZH AH0 N
Type: Rhyming poem: aba
Input (extra/fox.rhyming):
something something fox
apple jacks
word here pox
Output:
Using dictionary: dictionary-small.txt
Poem:
something something fox
apple jacks
word here pox
Dictionary:
FOX F AA1 K S
POX P AA1 K S
SOMETHING S AH1 M TH IH0 NG
Type: unsupported form
In ghci:
:l PoemClassifier
PoemClassifier.test
:l PoemAnalyzer
PoemAnalyzer.testMain.hs: reads poem input, finds dictionary, runs classifierPoemClassifier.hs: chooses poem type by applying parsersCMUPronouncingDictionary.hs: dictionary parsing and word metadataPoemAnalyzer.hs: converts strings into analyzed word dataPoemParser.hs: parser combinators and poem-form parsers