Add file
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
module StringHelp where
|
||||||
|
|
||||||
|
--import Data.Char
|
||||||
|
|
||||||
|
import Data.Set (Set)
|
||||||
|
import qualified Data.Set as Set
|
||||||
|
|
||||||
|
isVowel :: Char -> Bool
|
||||||
|
isVowel x = case x of
|
||||||
|
'a' -> True
|
||||||
|
'e' -> True
|
||||||
|
'i' -> True
|
||||||
|
'o' -> True
|
||||||
|
'u' -> True
|
||||||
|
_ -> False
|
||||||
|
|
||||||
|
addIndefiniteArticle :: String -> String
|
||||||
|
addIndefiniteArticle [] = error "tried to add indefinite article to empty string"
|
||||||
|
addIndefiniteArticle (x : xs) = genarticle ++ (x : xs)
|
||||||
|
where
|
||||||
|
flipexception
|
||||||
|
| w `Set.member` indefiniteExceptions = not
|
||||||
|
| otherwise = id
|
||||||
|
w = head (words (x : xs))
|
||||||
|
genarticle
|
||||||
|
| flipexception (isVowel x) = "an "
|
||||||
|
| otherwise = "a "
|
||||||
|
|
||||||
|
indefiniteExceptions :: Set String
|
||||||
|
indefiniteExceptions =
|
||||||
|
Set.fromList
|
||||||
|
[ "one"
|
||||||
|
, "usual"
|
||||||
|
, "union"
|
||||||
|
, "honor"
|
||||||
|
, "honest"
|
||||||
|
, "honorable"
|
||||||
|
, "heir"
|
||||||
|
, "hourglass"
|
||||||
|
, "eulogy"
|
||||||
|
, "united"
|
||||||
|
, "used"
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user