Skip to content

Instantly share code, notes, and snippets.

@afonsomatos
Created July 11, 2015 19:58
Show Gist options
  • Save afonsomatos/730b6557b0c65f037323 to your computer and use it in GitHub Desktop.
Save afonsomatos/730b6557b0c65f037323 to your computer and use it in GitHub Desktop.
words syllabes
-- Format src.txt so that it gives us a list of words and correspondig syllabes
-- divided by 1 space
import System.IO
import System.Directory
import System.Environment
import Data.List
main = do
-- Open input and output files
srcHandle <- openFile "src.txt" ReadMode
(outName, outHandle) <- openTempFile "." "temp"
-- Filter out the dashes, spaces and hiphens
contents <- hGetContents srcHandle
let separators = "¥- "
getSyllabes line = filter (`notElem` separators) line ++ " " ++ show (1 + sum [ 1 | x <- line, x `elem` separators])
output = map getSyllabes $ lines contents
-- Save everything to the output file
hPutStr outHandle (unlines output)
hClose srcHandle
hClose outHandle
-- Rename the output file
renameFile outName "out.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment