diff --git a/src/StringHelp.hs b/src/StringHelp.hs new file mode 100644 index 000000000..dba885ac3 --- /dev/null +++ b/src/StringHelp.hs @@ -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" + ]