{-# LANGUAGE OverloadedStrings #-}

module NLP.Brillig where

import Control.Arrow ( second, (***) )
import qualified Data.Text as T
import qualified Data.Map as Map 
import Data.Text ( Text )

newtype Tag = Tag { fromTag :: Text } deriving (Ord, Eq)

instance Show Tag where
  show = show . fromTag 

type Tagged a = (a, Tag)

type Count = Map.Map Text (Map.Map Tag Int)

readTag :: Text -> (Text, Tag)
readTag = (T.init *** Tag) . T.breakOnEnd "/"

showTag :: Tagged Text -> Text
showTag (w,t) = T.concat [ w, "/", fromTag t]

retag :: ([Tag] -> [Tag]) -> [Tagged Text] -> [Tagged Text]
retag f ts = zipWith replace newtags ts
 where
  newtags = f (map snd ts)
  replace t2 (w,_) = (w, t2)