splitText
This commit is contained in:
@@ -3,4 +3,4 @@ module Main (main) where
|
||||
import Lib
|
||||
|
||||
main :: IO ()
|
||||
main = someFunc
|
||||
main = putStrLn "Temp"
|
||||
|
||||
@@ -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
|
||||
13
coursework/part2/stack.yaml.lock
Normal file
13
coursework/part2/stack.yaml.lock
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user