-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMorph.hs
29 lines (26 loc) · 1012 Bytes
/
Morph.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- This file is part of tersmu
-- Copyright (C) 2014 Martin Bays <[email protected]>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of version 3 of the GNU General Public License as
-- published by the Free Software Foundation.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see http://www.gnu.org/licenses/.
module Morph (morph) where
import Morphology
import Pappy.Pos
import Pappy.Parse
import Data.Char
morph :: String -> Either Int String
morph s = let
Parsed words d _ = morphologywords $ morphologyParse "words" $ stripPunc s ++ " "
p = posCol (dvPos d) - 1
in if p < length s
then Left p
else Right $ map toLower $ unwords $ words
stripPunc :: String -> String
stripPunc =
-- TODO: shouldn't strip inside zoi quotes
-- (but shouldn't allow "%%%END%%%" in them either...)
map $ \c -> if isAlphaNum c || isSpace c || c `elem` ",'" then c else ' '