{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
module NLP.Concraft.Disamb.Positional
( Tier (..)
, Atom (..)
, select
, split
) where
import Control.Applicative ((<$>), (<*>))
import Data.Binary (Binary, put, get)
import Data.Text.Binary ()
import qualified Data.Set as S
import qualified Data.Map as M
import qualified Data.Text as T
import qualified Data.Tagset.Positional as TP
data Tier = Tier {
withPos :: Bool
, withEos :: Bool
, withAtts :: S.Set TP.Attr
}
instance Binary Tier where
put Tier{..} = put withPos >> put withEos >> put withAtts
get = Tier <$> get <*> get <*> get
data Atom = Atom
{ pos :: Maybe TP.POS
, atts :: M.Map TP.Attr T.Text
, eos :: Maybe Bool
} deriving (Show, Eq, Ord)
instance Binary Atom where
put Atom{..} = put pos >> put atts >> put eos
get = Atom <$> get <*> get <*> get
select
:: Tier
-> TP.Tag
-> Maybe Bool
-> Atom
select Tier{..} tag eos = Atom
{ pos = if withPos then Just (TP.pos tag) else Nothing
, atts = M.filterWithKey (\k _ -> k `S.member` withAtts) (TP.atts tag)
, eos = if withEos then eos else Nothing
}
split
:: [Tier]
-> TP.Tag
-> Maybe Bool
-> [Atom]
split tiers tag eos =
[ select tier tag eos
| tier <- tiers ]