splitText

This commit is contained in:
2024-12-09 13:22:08 +03:00
parent 92e1cb96ea
commit de9d8681f3
3 changed files with 38 additions and 6 deletions

View File

@@ -3,4 +3,4 @@ module Main (main) where
import Lib
main :: IO ()
main = someFunc
main = putStrLn "Temp"

View File

@@ -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

View 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