From de9d8681f3b426baecf1a0c63c59214f45e47414 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Mon, 9 Dec 2024 13:22:08 +0300 Subject: [PATCH] splitText --- coursework/part2/app/Main.hs | 2 +- coursework/part2/src/Lib.hs | 29 ++++++++++++++++++++++++----- coursework/part2/stack.yaml.lock | 13 +++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 coursework/part2/stack.yaml.lock diff --git a/coursework/part2/app/Main.hs b/coursework/part2/app/Main.hs index 4c6b30f..c2958dc 100644 --- a/coursework/part2/app/Main.hs +++ b/coursework/part2/app/Main.hs @@ -3,4 +3,4 @@ module Main (main) where import Lib main :: IO () -main = someFunc +main = putStrLn "Temp" diff --git a/coursework/part2/src/Lib.hs b/coursework/part2/src/Lib.hs index d36ff27..d0be732 100644 --- a/coursework/part2/src/Lib.hs +++ b/coursework/part2/src/Lib.hs @@ -1,6 +1,25 @@ -module Lib - ( someFunc - ) where +module Lib where -someFunc :: IO () -someFunc = putStrLn "someFunc" +import Data.Char (isLetter, toLower) + + +splitText :: String -> [[String]] +splitText text = map (processSentence . words) (splitSentences text) + where + splitSentences :: String -> [String] + splitSentences [] = [] + splitSentences s = + let (sentence, rest) = break isSeparator s + rest' = dropWhile isSeparator rest + in if null sentence + then splitSentences rest' + else sentence : splitSentences rest' + + isSeparator :: Char -> Bool + isSeparator c = c `elem` ".!?;:()" + + processSentence :: [String] -> [String] + processSentence = filter (not . null) . map cleanWord + + cleanWord :: String -> String + cleanWord = map toLower . filter isLetter \ No newline at end of file diff --git a/coursework/part2/stack.yaml.lock b/coursework/part2/stack.yaml.lock new file mode 100644 index 0000000..e542442 --- /dev/null +++ b/coursework/part2/stack.yaml.lock @@ -0,0 +1,13 @@ +# This file was autogenerated by Stack. +# You should not edit this file by hand. +# For more information, please see the documentation at: +# https://docs.haskellstack.org/en/stable/lock_files + +packages: [] +snapshots: +- completed: + sha256: 08bd13ce621b41a8f5e51456b38d5b46d7783ce114a50ab604d6bbab0d002146 + size: 720271 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/43.yaml + original: + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/43.yaml