From 127b2d93e44f06ed2ca0e6194db33b6aab7cf4cb Mon Sep 17 00:00:00 2001 From: Clarissa Littler Date: Sat, 1 Aug 2020 20:59:19 -0700 Subject: [PATCH] initial cimmit --- PFGAug1st.hs | 50 +++++++++++++++++++++++++++++++++++++++ PoetryFormGenerator.hs | 53 ++++++++++++++++++++++++++++++++++++++++++ forms/1.txt | 15 ++++++++++++ forms/2.txt | 38 ++++++++++++++++++++++++++++++ forms/3.txt | 21 +++++++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 PFGAug1st.hs create mode 100644 PoetryFormGenerator.hs create mode 100644 forms/1.txt create mode 100644 forms/2.txt create mode 100644 forms/3.txt diff --git a/PFGAug1st.hs b/PFGAug1st.hs new file mode 100644 index 0000000..a96bce2 --- /dev/null +++ b/PFGAug1st.hs @@ -0,0 +1,50 @@ +{- This is a poetry form generator. It'll get more sophisticated as I go, +but to start it'll come up with a number of lines, stanzas, and syllables per +line, then add in different constraints as we go. -} + +import Control.Monad.Random + +data Poem = PS [([Int],[IntraStanza])] [InterStanza] + deriving (Eq) + +instance Show Poem where + show (PS stanzas _) = unlines $ map stanzaShow stanzas + where stanzaShow (ls,_) = unlines $ map (\x -> lineshow x x) ls + lineshow m n | n > 0 = '-' : (lineshow m $ n - 1) + | otherwise = ": "++(show m) + +data IntraStanza = Indent Int Int + | Length Int Int + | RhymeMatch Int Int + | SlantMatch Int Int + deriving (Eq,Show) + +data InterStanza = Rotational Int Int Int + | LineShare Int Int Int Int + deriving (Eq,Show) + + +-- the initial version of things is going to involve picking a line length +-- per stanza and then varying it up and down, choosing a number of stanzas +-- and lines per stanza of a reasonable amount + +makeLine m = do + shift <- getRandomR (-m `div` 2,m `div` 2) + return $ shift + m + +genStanzaNoCons :: Rand StdGen ([Int], [IntraStanza]) +genStanzaNoCons = do + linesNum <- getRandomR (2 :: Int,10) + medianLine <- getRandomR (3 :: Int,20) + ls <- mapM (\x -> makeLine medianLine) [0..linesNum] + return $ (ls,[]) + +genPoem :: Int -> Rand StdGen Poem +genPoem stanzaNum = do + -- stanzaNum <- getRandomR (1 :: Int,5) + stanzas <- mapM (\x -> genStanzaNoCons) [0..stanzaNum] + return $ PS stanzas [] + +gen n = do + p <- evalRandIO $ genPoem n + print p diff --git a/PoetryFormGenerator.hs b/PoetryFormGenerator.hs new file mode 100644 index 0000000..beeb297 --- /dev/null +++ b/PoetryFormGenerator.hs @@ -0,0 +1,53 @@ +{- This is a poetry form generator. It'll get more sophisticated as I go, +but to start it'll come up with a number of lines, stanzas, and syllables per +line, then add in different constraints as we go. -} + +import Control.Monad.Random + +data Poem = PS [([Int],[IntraStanza])] [InterStanza] + deriving (Eq) + +instance Show Poem where + show (PS stanzas _) = unlines $ map stanzaShow stanzas + where stanzaShow (ls,_) = unlines $ map (\x -> lineshow x x) ls + lineshow m n | n > 0 = '-' : (lineshow m $ n - 1) + | otherwise = ": "++(show m) + +data IntraStanza = Indent Int Int + | Length Int Int + | RhymeMatch Int Int + | SlantMatch Int Int + deriving (Eq,Show) + +data InterStanza = Rotational Int Int Int + | LineShare Int Int Int Int + deriving (Eq,Show) + + +-- the initial version of things is going to involve picking a line length +-- per stanza and then varying it up and down, choosing a number of stanzas +-- and lines per stanza of a reasonable amount + +makeLine m = do + shift <- getRandomR (-m `div` 2,m `div` 2) + return $ shift + m + +genStanzaNoCons :: Rand StdGen ([Int], [IntraStanza]) +genStanzaNoCons = do + linesNum <- getRandomR (2 :: Int,10) + medianLine <- getRandomR (4 :: Int,10) + ls <- mapM (\x -> makeLine medianLine) [0..linesNum] + return $ (ls,[]) + +genPoem :: Int -> Rand StdGen Poem +genPoem stanzaNum = do + stanzas <- mapM (\x -> genStanzaNoCons) [0..stanzaNum] + return $ PS stanzas [] + +gen n = do + p <- evalRandIO $ genPoem n + print p + +main = do + stanzaNum <- getRandomR (1 :: Int,4) + gen stanzaNum diff --git a/forms/1.txt b/forms/1.txt new file mode 100644 index 0000000..153da18 --- /dev/null +++ b/forms/1.txt @@ -0,0 +1,15 @@ +------: 6 +---------: 9 +------------: 12 +-----: 5 +------: 6 +----: 4 +------: 6 + +---------: 9 +------: 6 +-----: 5 +-------------: 13 +-----------: 11 + + diff --git a/forms/2.txt b/forms/2.txt new file mode 100644 index 0000000..8ca6311 --- /dev/null +++ b/forms/2.txt @@ -0,0 +1,38 @@ +----------: 10 +-----------: 11 +----------: 10 +------------: 12 + +--------------: 14 +-------: 7 +------: 6 +--------: 8 + +-----: 5 +-----: 5 +-----: 5 +------: 6 +----: 4 +------: 6 + +------: 6 +-------: 7 +----: 4 +----: 4 +----: 4 +------: 6 +-----: 5 +---: 3 +----: 4 +----: 4 + +-----: 5 +------: 6 +---------: 9 +--------: 8 +-----: 5 +----: 4 +-------: 7 +---------: 9 + + diff --git a/forms/3.txt b/forms/3.txt new file mode 100644 index 0000000..4291628 --- /dev/null +++ b/forms/3.txt @@ -0,0 +1,21 @@ +--: 2 +------: 6 +---: 3 +------: 6 +----: 4 +----: 4 +------: 6 +-----: 5 +--: 2 +-----: 5 +-----: 5 + +-----: 5 +------: 6 +-----: 5 +---: 3 +--: 2 +---: 3 +----: 4 + +