Created
July 11, 2015 19:58
-
-
Save afonsomatos/730b6557b0c65f037323 to your computer and use it in GitHub Desktop.
words syllabes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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