module GF.Compile.ToAPI 
 (stringToAPI,exprToAPI)
  where

import PGF.Internal
import PGF(showCId)
import Data.Maybe
--import System.IO
--import Control.Monad
--import Data.Set as Set (fromList,toList)
import Data.List
--import Data.Map(Map)
import qualified Data.Map as Map


-- intermediate structure for representing the translated expression
data APIfunc = BasicFunc String | AppFunc String [APIfunc] | NoAPI  
  deriving (Int -> APIfunc -> ShowS
[APIfunc] -> ShowS
APIfunc -> String
(Int -> APIfunc -> ShowS)
-> (APIfunc -> String) -> ([APIfunc] -> ShowS) -> Show APIfunc
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [APIfunc] -> ShowS
$cshowList :: [APIfunc] -> ShowS
show :: APIfunc -> String
$cshow :: APIfunc -> String
showsPrec :: Int -> APIfunc -> ShowS
$cshowsPrec :: Int -> APIfunc -> ShowS
Show,APIfunc -> APIfunc -> Bool
(APIfunc -> APIfunc -> Bool)
-> (APIfunc -> APIfunc -> Bool) -> Eq APIfunc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: APIfunc -> APIfunc -> Bool
$c/= :: APIfunc -> APIfunc -> Bool
== :: APIfunc -> APIfunc -> Bool
$c== :: APIfunc -> APIfunc -> Bool
Eq)




-- translates a GF expression/tree into an equivalent one which uses functions from the GF
-- API instead of the syntactic modules
exprToAPI :: Expr -> String
exprToAPI :: Expr -> String
exprToAPI Expr
expr = 
    let ffs :: APIfunc
ffs = Expr -> APIfunc
exprToFunc Expr
expr 
       in APIfunc -> String
printAPIfunc APIfunc
ffs




-- translates a GF expression/tree written as a string to its correspondent which uses API functions
-- the string is parsed into a GF expression/tree first
stringToAPI :: String -> String
stringToAPI :: ShowS
stringToAPI String
expressionToRead = 
        case String -> Maybe Expr
readExpr String
expressionToRead of
             Just Expr
ex -> Expr -> String
exprToAPI Expr
ex                
             Maybe Expr
_       -> ShowS
forall a. HasCallStack => String -> a
error String
"incorrect expression given as input "




-- function for translating an expression into APIFunc with type inference for  
-- the type of the expression
exprToFunc :: Expr -> APIfunc
exprToFunc :: Expr -> APIfunc
exprToFunc Expr
expr = 
   case Expr -> Maybe (CId, [Expr])
unApp Expr
expr of
      Just (CId
cid,[Expr]
l) -> 
         case String -> Map String (String, [String]) -> Maybe (String, [String])
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (CId -> String
showCId CId
cid) Map String (String, [String])
syntaxFuncs of 
            Just (String, [String])
sig -> Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True ((String, [String]) -> String
forall a b. (a, b) -> a
fst (String, [String])
sig,Expr
expr)
            Maybe (String, [String])
_        -> case [Expr]
l of 
                          [] -> String -> APIfunc
BasicFunc (CId -> String
showCId CId
cid) 
                          [Expr]
_  -> let es :: [APIfunc]
es = (Expr -> APIfunc) -> [Expr] -> [APIfunc]
forall a b. (a -> b) -> [a] -> [b]
map Expr -> APIfunc
exprToFunc [Expr]
l 
                                   in  String -> [APIfunc] -> APIfunc
AppFunc (CId -> String
showCId CId
cid) [APIfunc]
es
      Maybe (CId, [Expr])
_ -> String -> APIfunc
BasicFunc ([CId] -> Expr -> String
showExpr [] Expr
expr)

        
       
                             

-- main function for translating an expression along with its type into an APIFunc
-- the boolean controls the need to optimize the result
mkAPI :: Bool -> (String, Expr) -> APIfunc
mkAPI :: Bool -> (String, Expr) -> APIfunc
mkAPI Bool
opt (String
ty,Expr
expr) = 
 if String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
ty [String]
rephraseable then String -> Expr -> APIfunc
rephraseSentence String
ty Expr
expr 
  else if Bool
opt then if String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
ty [String]
optimizable then Expr -> APIfunc
optimize Expr
expr else (String, Expr) -> APIfunc
computeAPI (String
ty,Expr
expr)
        else (String, Expr) -> APIfunc
computeAPI (String
ty,Expr
expr) 
  where
     rephraseSentence :: String -> Expr -> APIfunc
rephraseSentence String
ty Expr
expr = 
       case Expr -> Maybe (CId, [Expr])
unApp Expr
expr of 
         Just (CId
cid,[Expr]
es) -> if String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
"Use" (CId -> String
showCId CId
cid) then 
                                                             let newCat :: String
newCat = Int -> ShowS
forall a. Int -> [a] -> [a]
drop Int
3 (CId -> String
showCId CId
cid)
                                                                 afClause :: APIfunc
afClause = Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True (String
newCat, [Expr]
es [Expr] -> Int -> Expr
forall a. [a] -> Int -> a
!! Int
2)
                                                                 afPol :: APIfunc
afPol = Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True (String
"Pol",[Expr]
es [Expr] -> Int -> Expr
forall a. [a] -> Int -> a
!! Int
1)                                         
                                                                 lTense :: APIfunc
lTense = Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True (String
"Temp", [Expr] -> Expr
forall a. [a] -> a
head [Expr]
es)                                        
                                                              in case APIfunc
lTense of 
                                                                  AppFunc String
_ [BasicFunc String
s1, BasicFunc String
s2] -> 
                                                                      let (APIfunc
r1,APIfunc
r2) = String -> String -> (APIfunc, APIfunc)
getTemporalParam String
s1 String
s2 in  
                                                                         String -> [APIfunc] -> APIfunc
AppFunc (String
"mk"String -> ShowS
forall a. [a] -> [a] -> [a]
++String
newCat) [APIfunc
r1,APIfunc
r2,APIfunc
afPol,APIfunc
afClause] 
                                                                  APIfunc
_ ->  String -> APIfunc
forall a. HasCallStack => String -> a
error String
"erroneous tense"          
                           else (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False) (String
ty,Expr
expr)
         Maybe (CId, [Expr])
_             -> String -> APIfunc
forall a. HasCallStack => String -> a
error (String -> APIfunc) -> String -> APIfunc
forall a b. (a -> b) -> a -> b
$ String
"incorrect for for expression "String -> ShowS
forall a. [a] -> [a] -> [a]
++ [CId] -> Expr -> String
showExpr [] Expr
expr
     
     getTemporalParam :: String -> String -> (APIfunc, APIfunc)
getTemporalParam String
s1 String
s2 = 
                         let r1 :: APIfunc
r1 = case String
s1 of 
                                     String
"TPres" -> APIfunc
NoAPI
                                     String
"TPast" -> String -> APIfunc
BasicFunc String
"pastTense"
                                     String
"TFut"  -> String -> APIfunc
BasicFunc String
"futureTense" 
                                     String
"TCond" -> String -> APIfunc
BasicFunc String
"conditionalTense"
                             r2 :: APIfunc
r2 = case String
s2 of
                                     String
"ASimul" -> APIfunc
NoAPI
                                     String
"AAnter" -> String -> APIfunc
BasicFunc String
"anteriorAnt"
                              in (APIfunc
r1,APIfunc
r2) 



computeAPI :: (String,Expr) ->  APIfunc
computeAPI :: (String, Expr) -> APIfunc
computeAPI (String
ty,Expr
expr) =
   case (Expr -> Maybe (CId, [Expr])
unApp Expr
expr) of 
     Just (CId
cid,[]) ->  String -> String -> APIfunc
getSimpCat (CId -> String
showCId CId
cid) String
ty
     Just (CId
cid,[Expr]
es) -> 
        let p :: Maybe APIfunc
p = String -> [Expr] -> Maybe APIfunc
specFunction (CId -> String
showCId CId
cid) [Expr]
es  
          in if Maybe APIfunc -> Bool
forall a. Maybe a -> Bool
isJust Maybe APIfunc
p then Maybe APIfunc -> APIfunc
forall a. HasCallStack => Maybe a -> a
fromJust Maybe APIfunc
p
              else case String -> Map String (String, [String]) -> Maybe (String, [String])
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (CId -> String
forall a. Show a => a -> String
show CId
cid) Map String (String, [String])
syntaxFuncs of
                    Maybe (String, [String])
Nothing -> Expr -> APIfunc
exprToFunc Expr
expr    
                    Just (String
nameCat,[String]
typesExps) -> 
                      if String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
nameCat [String]
hiddenCats Bool -> Bool -> Bool
&& [Expr] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Expr]
es Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 then  (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True) ([String] -> String
forall a. [a] -> a
head [String]
typesExps,[Expr] -> Expr
forall a. [a] -> a
head [Expr]
es)
                       else if String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
nameCat [String]
hiddenCats then String -> APIfunc
forall a. HasCallStack => String -> a
error (String -> APIfunc) -> String -> APIfunc
forall a b. (a -> b) -> a -> b
$ String
"incorrect coercion "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
nameCatString -> ShowS
forall a. [a] -> [a] -> [a]
++String
" - "String -> ShowS
forall a. [a] -> [a] -> [a]
++[Expr] -> String
forall a. Show a => a -> String
show [Expr]
es   
                              else let afs :: [APIfunc]
afs = ((String, Expr) -> APIfunc) -> [(String, Expr)] -> [APIfunc]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True) ([String] -> [Expr] -> [(String, Expr)]
forall a b. [a] -> [b] -> [(a, b)]
zip [String]
typesExps [Expr]
es)
                                      in String -> [APIfunc] -> APIfunc
AppFunc (String
"mk" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
nameCat) [APIfunc]
afs 
     Maybe (CId, [Expr])
_         -> String -> APIfunc
forall a. HasCallStack => String -> a
error String
"error"          
  where 
    getSimpCat :: String -> String -> APIfunc
getSimpCat String
"IdRP" String
_     = String -> APIfunc
BasicFunc String
"which_RP"
    getSimpCat String
"DefArt" String
_   = String -> APIfunc
BasicFunc String
"the_Art"
    getSimpCat String
"IndefArt" String
_ = String -> APIfunc
BasicFunc String
"a_Art"
    getSimpCat String
"NumSg" String
_    = APIfunc
NoAPI
    getSimpCat String
"NumPl" String
_    = String -> APIfunc
BasicFunc String
"plNum"
    getSimpCat String
"PPos" String
_     = APIfunc
NoAPI
    getSimpCat String
"PNeg" String
_     = String -> APIfunc
BasicFunc String
"negativePol"
    getSimpCat String
cid String
ty       = if String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem String
ty [String
"PConj",String
"Voc"] Bool -> Bool -> Bool
&& String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isInfixOf String
"No" String
cid
                                 then APIfunc
NoAPI 
                                  else String -> APIfunc
BasicFunc String
cid

    specFunction :: String -> [Expr] -> Maybe APIfunc
specFunction String
"PassV2" [Expr]
es     = String -> String -> [Expr] -> Maybe APIfunc
rephraseUnary String
"passiveVP" String
"V2" [Expr]
es
    specFunction String
"ReflA2" [Expr]
es     = String -> String -> [Expr] -> Maybe APIfunc
rephraseUnary String
"reflAP" String
"A2" [Expr]
es
    specFunction String
"UseComparA" [Expr]
es = String -> String -> [Expr] -> Maybe APIfunc
rephraseUnary String
"comparAP" String
"A" [Expr]
es
    specFunction String
"TFullStop" [Expr]
es  = String -> [Expr] -> Maybe APIfunc
rephraseText String
"fullStopPunct" [Expr]
es
    specFunction String
"TExclMark" [Expr]
es  = String -> [Expr] -> Maybe APIfunc
rephraseText String
"exclMarkPunct" [Expr]
es
    specFunction String
"TQuestMark" [Expr]
es = String -> [Expr] -> Maybe APIfunc
rephraseText String
"questMarkPunct" [Expr]
es
    specFunction String
_ [Expr]
_             = Maybe APIfunc
forall a. Maybe a
Nothing

    rephraseUnary :: String -> String -> [Expr] -> Maybe APIfunc
rephraseUnary String
ss String
ty [Expr]
es = 
     let afs :: APIfunc
afs = Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True (String
ty,[Expr] -> Expr
forall a. [a] -> a
head [Expr]
es) 
        in APIfunc -> Maybe APIfunc
forall a. a -> Maybe a
Just (String -> [APIfunc] -> APIfunc
AppFunc String
ss [APIfunc
afs])

    rephraseText :: String -> [Expr] -> Maybe APIfunc
rephraseText String
ss [Expr]
es = 
     let afs :: [APIfunc]
afs = ((String, Expr) -> APIfunc) -> [(String, Expr)] -> [APIfunc]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
True) ([String] -> [Expr] -> [(String, Expr)]
forall a b. [a] -> [b] -> [(a, b)]
zip [String
"Phr",String
"Text"] [Expr]
es) in
        if [APIfunc]
afs [APIfunc] -> Int -> APIfunc
forall a. [a] -> Int -> a
!! Int
1 APIfunc -> APIfunc -> Bool
forall a. Eq a => a -> a -> Bool
== String -> APIfunc
BasicFunc String
"TEmpty" then  APIfunc -> Maybe APIfunc
forall a. a -> Maybe a
Just (String -> [APIfunc] -> APIfunc
AppFunc String
"mkText" [[APIfunc] -> APIfunc
forall a. [a] -> a
head [APIfunc]
afs,String -> APIfunc
BasicFunc String
ss])
           else APIfunc -> Maybe APIfunc
forall a. a -> Maybe a
Just (String -> [APIfunc] -> APIfunc
AppFunc String
"mkText" [[APIfunc] -> APIfunc
forall a. [a] -> a
head [APIfunc]
afs, String -> APIfunc
BasicFunc String
ss, [APIfunc] -> APIfunc
forall a. [a] -> a
last [APIfunc]
afs])



-- optimizations for the translation of some categories
optimize :: Expr -> APIfunc
optimize Expr
expr = Expr -> APIfunc
optimizeNP Expr
expr

optimizeNP :: Expr -> APIfunc
optimizeNP Expr
expr = 
   case Expr -> Maybe (CId, [Expr])
unApp Expr
expr of
     Just (CId
cid,[Expr]
es) -> 
         if CId -> String
showCId CId
cid String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"MassNP" then let afs :: APIfunc
afs = Expr -> APIfunc
nounAsCN ([Expr] -> Expr
forall a. [a] -> a
head [Expr]
es)
                                           in String -> [APIfunc] -> APIfunc
AppFunc String
"mkNP" [APIfunc
afs]
           else if CId -> String
showCId CId
cid String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"DetCN" then let quants :: [APIfunc]
quants = Expr -> [APIfunc]
quantAsDet ([Expr] -> Expr
forall a. [a] -> a
head [Expr]
es)
                                                   ns :: APIfunc
ns     = Expr -> APIfunc
nounAsCN ([Expr] -> Expr
forall a. [a] -> a
head ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> [Expr]
forall a. [a] -> [a]
tail [Expr]
es)
                                                  in String -> [APIfunc] -> APIfunc
AppFunc String
"mkNP" ([APIfunc]
quants [APIfunc] -> [APIfunc] -> [APIfunc]
forall a. [a] -> [a] -> [a]
++ [APIfunc
ns])
                 else Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False (String
"NP",Expr
expr)
     Maybe (CId, [Expr])
_             -> String -> APIfunc
forall a. HasCallStack => String -> a
error (String -> APIfunc) -> String -> APIfunc
forall a b. (a -> b) -> a -> b
$ String
"incorrect expression " String -> ShowS
forall a. [a] -> [a] -> [a]
++ ([CId] -> Expr -> String
showExpr [] Expr
expr)
    where 
     nounAsCN :: Expr -> APIfunc
nounAsCN Expr
expr = 
      case Expr -> Maybe (CId, [Expr])
unApp Expr
expr of 
       Just (CId
cid,[Expr]
es) -> if CId -> String
showCId CId
cid String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"UseN" then (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False) (String
"N",[Expr] -> Expr
forall a. [a] -> a
head [Expr]
es)
           else (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False) (String
"CN",Expr
expr)
       Maybe (CId, [Expr])
_ -> String -> APIfunc
forall a. HasCallStack => String -> a
error (String -> APIfunc) -> String -> APIfunc
forall a b. (a -> b) -> a -> b
$ String
"incorrect expression "String -> ShowS
forall a. [a] -> [a] -> [a]
++ ([CId] -> Expr -> String
showExpr [] Expr
expr)

     quantAsDet :: Expr -> [APIfunc]
quantAsDet Expr
expr =
       case Expr -> Maybe (CId, [Expr])
unApp Expr
expr of
        Just (CId
cid,[Expr]
es) -> if CId -> String
showCId CId
cid String -> String -> Bool
forall a. Eq a => a -> a -> Bool
== String
"DetQuant" then ((String, Expr) -> APIfunc) -> [(String, Expr)] -> [APIfunc]
forall a b. (a -> b) -> [a] -> [b]
map (Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False) [(String
"Quant", [Expr] -> Expr
forall a. [a] -> a
head [Expr]
es),(String
"Num",[Expr] -> Expr
forall a. [a] -> a
head ([Expr] -> Expr) -> [Expr] -> Expr
forall a b. (a -> b) -> a -> b
$ [Expr] -> [Expr]
forall a. [a] -> [a]
tail [Expr]
es)]
                           else [Bool -> (String, Expr) -> APIfunc
mkAPI Bool
False (String
"Det",Expr
expr)]
                                  
        Maybe (CId, [Expr])
_             -> String -> [APIfunc]
forall a. HasCallStack => String -> a
error (String -> [APIfunc]) -> String -> [APIfunc]
forall a b. (a -> b) -> a -> b
$ String
"incorrect expression "String -> ShowS
forall a. [a] -> [a] -> [a]
++ ([CId] -> Expr -> String
showExpr [] Expr
expr)
        

     
-- categories not present in the API - rephrasing needed
hiddenCats :: [String]
hiddenCats :: [String]
hiddenCats = [String
"N2",String
"V2",String
"Comp",String
"SC"]



-- categories for which optimization of the translation is provided at the moment
optimizable :: [String]
optimizable :: [String]
optimizable = [String
"NP"]



-- categories for which the compositional translation needs to be rephrased
rephraseable :: [String]
rephraseable :: [String]
rephraseable = [String
"S",String
"QS",String
"RS"]



-- converts the intermediate structure APIFunc to plain string
printAPIfunc :: APIfunc -> String 
printAPIfunc :: APIfunc -> String
printAPIfunc (BasicFunc String
f) = String
f 
printAPIfunc APIfunc
NoAPI = String
""
printAPIfunc (AppFunc String
f [APIfunc]
es) = [String] -> String
unwords (String
f String -> [String] -> [String]
forall a. a -> [a] -> [a]
: (APIfunc -> String) -> [APIfunc] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (\APIfunc
x -> APIfunc -> String
printAPIArgfunc APIfunc
x ) [APIfunc]
es) 
 where 
   printAPIArgfunc :: APIfunc -> String
printAPIArgfunc (BasicFunc String
f) = String
f
   printAPIArgfunc APIfunc
NoAPI = String
""
   printAPIArgfunc APIfunc
f = String
"(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ APIfunc -> String
printAPIfunc APIfunc
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")" 






--------------------------------------------------------------------------------
{-
constFuncs :: Map.Map String (String,[String])
constFuncs = Map.fromList [("AAnter",("Ant",[])),("ASimul",("Ant",[])),("D_0",("Dig",[])),("D_1",("Dig",[])),("D_2",("Dig",[])),("D_3",("Dig",[])),("D_4",("Dig",[])),("D_5",("Dig",[])),("D_6",("Dig",[])),("D_7",("Dig",[])),("D_8",("Dig",[])),("D_9",("Dig",[])),("DefArt",("Quant",[])),("IdRP",("RP",[])),("IndefArt",("Quant",[])),("NoPConj",("PConj",[])),("NoVoc",("Voc",[])),("NumPl",("Num",[])),("NumSg",("Num",[])),("PNeg",("Pol",[])),("PPos",("Pol",[])),("TCond",("Tense",[])),("TEmpty",("Text",[])),("TFut",("Tense",[])),("TPast",("Tense",[])),("TPres",("Tense",[])),("UseCopula",("VP",[])),("above_Prep",("Prep",[])),("after_Prep",("Prep",[])),("alas_Interj",("Interj",[])),("all_Predet",("Predet",[])),("almost_AdA",("AdA",[])),("almost_AdN",("AdN",[])),("already_Adv",("Adv",[])),("although_Subj",("Subj",[])),("always_AdV",("AdV",[])),("and_Conj",("Conj",[])),("answer_V2S",("V2S",[])),("as_CAdv",("CAdv",[])),("ask_V2Q",("V2Q",[])),("at_least_AdN",("AdN",[])),("at_most_AdN",("AdN",[])),("because_Subj",("Subj",[])),("before_Prep",("Prep",[])),("beg_V2V",("V2V",[])),("behind_Prep",("Prep",[])),("between_Prep",("Prep",[])),("both7and_DConj",("Conj",[])),("but_PConj",("PConj",[])),("by8agent_Prep",("Prep",[])),("by8means_Prep",("Prep",[])),("during_Prep",("Prep",[])),("either7or_DConj",("Conj",[])),("every_Det",("Det",[])),("everybody_NP",("NP",[])),("everything_NP",("NP",[])),("everywhere_Adv",("Adv",[])),("except_Prep",("Prep",[])),("far_Adv",("Adv",[])),("few_Det",("Det",[])),("for_Prep",("Prep",[])),("from_Prep",("Prep",[])),("he_Pron",("Pron",[])),("here7from_Adv",("Adv",[])),("here7to_Adv",("Adv",[])),("here_Adv",("Adv",[])),("how8many_IDet",("IDet",[])),("how8much_IAdv",("IAdv",[])),("how_IAdv",("IAdv",[])),("i_Pron",("Pron",[])),("if_Subj",("Subj",[])),("if_then_Conj",("Conj",[])),("in8front_Prep",("Prep",[])),("in_Prep",("Prep",[])),("it_Pron",("Pron",[])),("language_title_Utt",("Utt",[])),("left_Ord",("Ord",[])),("less_CAdv",("CAdv",[])),("many_Det",("Det",[])),("more_CAdv",("CAdv",[])),("most_Predet",("Predet",[])),("much_Det",("Det",[])),("n2",("Digit",[])),("n3",("Digit",[])),("n4",("Digit",[])),("n5",("Digit",[])),("n6",("Digit",[])),("n7",("Digit",[])),("n8",("Digit",[])),("n9",("Digit",[])),("no_Quant",("Quant",[])),("no_Utt",("Utt",[])),("nobody_NP",("NP",[])),("not_Predet",("Predet",[])),("nothing_NP",("NP",[])),("now_Adv",("Adv",[])),("on_Prep",("Prep",[])),("only_Predet",("Predet",[])),("or_Conj",("Conj",[])),("otherwise_PConj",("PConj",[])),("paint_V2A",("V2A",[])),("part_Prep",("Prep",[])),("please_Voc",("Voc",[])),("possess_Prep",("Prep",[])),("pot01",("Sub10",[])),("pot110",("Sub100",[])),("pot111",("Sub100",[])),("quite_Adv",("AdA",[])),("right_Ord",("Ord",[])),("she_Pron",("Pron",[])),("so_AdA",("AdA",[])),("somePl_Det",("Det",[])),("someSg_Det",("Det",[])),("somebody_NP",("NP",[])),("something_NP",("NP",[])),("somewhere_Adv",("Adv",[])),("that_Quant",("Quant",[])),("that_Subj",("Subj",[])),("there7from_Adv",("Adv",[])),("there7to_Adv",("Adv",[])),("there_Adv",("Adv",[])),("therefore_PConj",("PConj",[])),("they_Pron",("Pron",[])),("this_Quant",("Quant",[])),("through_Prep",("Prep",[])),("to_Prep",("Prep",[])),("today_Adv",("Adv",[])),("too_AdA",("AdA",[])),("under_Prep",("Prep",[])),("very_AdA",("AdA",[])),("we_Pron",("Pron",[])),("whatPl_IP",("IP",[])),("whatSg_IP",("IP",[])),("when_IAdv",("IAdv",[])),("when_Subj",("Subj",[])),("where_IAdv",("IAdv",[])),("which_IQuant",("IQuant",[])),("whoPl_IP",("IP",[])),("whoSg_IP",("IP",[])),("why_IAdv",("IAdv",[])),("with_Prep",("Prep",[])),("without_Prep",("Prep",[])),("yes_Utt",("Utt",[])),("youPl_Pron",("Pron",[])),("youPol_Pron",("Pron",[])),("youSg_Pron",("Pron",[]))]
-}


syntaxFuncs :: Map.Map String (String,[String])
syntaxFuncs :: Map String (String, [String])
syntaxFuncs = [(String, (String, [String]))] -> Map String (String, [String])
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(String
"AdAP",(String
"AP",[String
"AdA",String
"AP"])),(String
"AdAdv",(String
"Adv",[String
"AdA",String
"Adv"])),(String
"AdNum",(String
"Card",[String
"AdN",String
"Card"])),(String
"AdVVP",(String
"VP",[String
"AdV",String
"VP"])),(String
"AddAdvQVP",(String
"QVP",[String
"QVP",String
"IAdv"])),(String
"AdjCN",(String
"CN",[String
"AP",String
"CN"])),(String
"AdjOrd",(String
"AP",[String
"Ord"])),(String
"AdnCAdv",(String
"AdN",[String
"CAdv"])),(String
"AdvAP",(String
"AP",[String
"AP",String
"Adv"])),(String
"AdvCN",(String
"CN",[String
"CN",String
"Adv"])),(String
"AdvIAdv",(String
"IAdv",[String
"IAdv",String
"Adv"])),(String
"AdvIP",(String
"IP",[String
"IP",String
"Adv"])),(String
"AdvNP",(String
"NP",[String
"NP",String
"Adv"])),(String
"AdvQVP",(String
"QVP",[String
"VP",String
"IAdv"])),(String
"AdvS",(String
"S",[String
"Adv",String
"S"])),(String
"AdvSlash",(String
"ClSlash",[String
"ClSlash",String
"Adv"])),(String
"AdvVP",(String
"VP",[String
"VP",String
"Adv"])),(String
"ApposCN",(String
"CN",[String
"CN",String
"NP"])),(String
"BaseAP",(String
"ListAP",[String
"AP",String
"AP"])),(String
"BaseAdv",(String
"ListAdv",[String
"Adv",String
"Adv"])),(String
"BaseCN",(String
"ListCN",[String
"CN",String
"CN"])),(String
"BaseIAdv",(String
"ListIAdv",[String
"IAdv",String
"IAdv"])),(String
"BaseNP",(String
"ListNP",[String
"NP",String
"NP"])),(String
"BaseRS",(String
"ListRS",[String
"RS",String
"RS"])),(String
"BaseS",(String
"ListS",[String
"S",String
"S"])),(String
"CAdvAP",(String
"AP",[String
"CAdv",String
"AP",String
"NP"])),(String
"CleftAdv",(String
"Cl",[String
"Adv",String
"S"])),(String
"CleftNP",(String
"Cl",[String
"NP",String
"RS"])),(String
"CompAP",(String
"Comp",[String
"AP"])),(String
"CompAdv",(String
"Comp",[String
"Adv"])),(String
"CompCN",(String
"Comp",[String
"CN"])),(String
"CompIAdv",(String
"IComp",[String
"IAdv"])),(String
"CompIP",(String
"IComp",[String
"IP"])),(String
"CompNP",(String
"Comp",[String
"NP"])),(String
"ComparA",(String
"AP",[String
"A",String
"NP"])),(String
"ComparAdvAdj",(String
"Adv",[String
"CAdv",String
"A",String
"NP"])),(String
"ComparAdvAdjS",(String
"Adv",[String
"CAdv",String
"A",String
"S"])),(String
"ComplA2",(String
"AP",[String
"A2",String
"NP"])),(String
"ComplN2",(String
"CN",[String
"N2",String
"NP"])),(String
"ComplN3",(String
"N2",[String
"N3",String
"NP"])),(String
"ComplSlash",(String
"VP",[String
"VPSlash",String
"NP"])),(String
"ComplSlashIP",(String
"QVP",[String
"VPSlash",String
"IP"])),(String
"ComplVA",(String
"VP",[String
"VA",String
"AP"])),(String
"ComplVQ",(String
"VP",[String
"VQ",String
"QS"])),(String
"ComplVS",(String
"VP",[String
"VS",String
"S"])),(String
"ComplVV",(String
"VP",[String
"VV",String
"VP"])),(String
"ConjAP",(String
"AP",[String
"Conj",String
"ListAP"])),(String
"ConjAdv",(String
"Adv",[String
"Conj",String
"ListAdv"])),(String
"ConjCN",(String
"CN",[String
"Conj",String
"ListCN"])),(String
"ConjIAdv",(String
"IAdv",[String
"Conj",String
"ListIAdv"])),(String
"ConjNP",(String
"NP",[String
"Conj",String
"ListNP"])),(String
"ConjRS",(String
"RS",[String
"Conj",String
"ListRS"])),(String
"ConjS",(String
"S",[String
"Conj",String
"ListS"])),(String
"ConsAP",(String
"ListAP",[String
"AP",String
"ListAP"])),(String
"ConsAdv",(String
"ListAdv",[String
"Adv",String
"ListAdv"])),(String
"ConsCN",(String
"ListCN",[String
"CN",String
"ListCN"])),(String
"ConsIAdv",(String
"ListIAdv",[String
"IAdv",String
"ListIAdv"])),(String
"ConsNP",(String
"ListNP",[String
"NP",String
"ListNP"])),(String
"ConsRS",(String
"ListRS",[String
"RS",String
"ListRS"])),(String
"ConsS",(String
"ListS",[String
"S",String
"ListS"])),(String
"DetCN",(String
"NP",[String
"Det",String
"CN"])),(String
"DetNP",(String
"NP",[String
"Det"])),(String
"DetQuant",(String
"Det",[String
"Quant",String
"Num"])),(String
"DetQuantOrd",(String
"Det",[String
"Quant",String
"Num",String
"Ord"])),(String
"EmbedQS",(String
"SC",[String
"QS"])),(String
"EmbedS",(String
"SC",[String
"S"])),(String
"EmbedVP",(String
"SC",[String
"VP"])),(String
"ExistIP",(String
"QCl",[String
"IP"])),(String
"ExistNP",(String
"Cl",[String
"NP"])),(String
"FunRP",(String
"RP",[String
"Prep",String
"NP",String
"RP"])),(String
"GenericCl",(String
"Cl",[String
"VP"])),(String
"IDig",(String
"Digits",[String
"Dig"])),(String
"IIDig",(String
"Digits",[String
"Dig",String
"Digits"])),(String
"IdetCN",(String
"IP",[String
"IDet",String
"CN"])),(String
"IdetIP",(String
"IP",[String
"IDet"])),(String
"IdetQuant",(String
"IDet",[String
"IQuant",String
"Num"])),(String
"ImpP3",(String
"Utt",[String
"NP",String
"VP"])),(String
"ImpPl1",(String
"Utt",[String
"VP"])),(String
"ImpVP",(String
"Imp",[String
"VP"])),(String
"ImpersCl",(String
"Cl",[String
"VP"])),(String
"MassNP",(String
"NP",[String
"CN"])),(String
"NumCard",(String
"Num",[String
"Card"])),(String
"NumDigits",(String
"Card",[String
"Digits"])),(String
"NumNumeral",(String
"Card",[String
"Numeral"])),(String
"OrdDigits",(String
"Ord",[String
"Digits"])),(String
"OrdNumeral",(String
"Ord",[String
"Numeral"])),(String
"OrdSuperl",(String
"Ord",[String
"A"])),(String
"PConjConj",(String
"PConj",[String
"Conj"])),(String
"PPartNP",(String
"NP",[String
"NP",String
"V2"])),(String
"PassV2",(String
"VP",[String
"V2"])),(String
"PhrUtt",(String
"Phr",[String
"PConj",String
"Utt",String
"Voc"])),(String
"PositA",(String
"AP",[String
"A"])),(String
"PositAdAAdj",(String
"AdA",[String
"A"])),(String
"PositAdvAdj",(String
"Adv",[String
"A"])),(String
"PossPron",(String
"Quant",[String
"Pron"])),(String
"PredSCVP",(String
"Cl",[String
"SC",String
"VP"])),(String
"PredVP",(String
"Cl",[String
"NP",String
"VP"])),(String
"PredetNP",(String
"NP",[String
"Predet",String
"NP"])),(String
"PrepIP",(String
"IAdv",[String
"Prep",String
"IP"])),(String
"PrepNP",(String
"Adv",[String
"Prep",String
"NP"])),(String
"ProgrVP",(String
"VP",[String
"VP"])),(String
"QuestCl",(String
"QCl",[String
"Cl"])),(String
"QuestIAdv",(String
"QCl",[String
"IAdv",String
"Cl"])),(String
"QuestIComp",(String
"QCl",[String
"IComp",String
"NP"])),(String
"QuestQVP",(String
"QCl",[String
"IP",String
"QVP"])),(String
"QuestSlash",(String
"QCl",[String
"IP",String
"ClSlash"])),(String
"QuestVP",(String
"QCl",[String
"IP",String
"VP"])),(String
"ReflA2",(String
"AP",[String
"A2"])),(String
"ReflVP",(String
"VP",[String
"VPSlash"])),(String
"RelCN",(String
"CN",[String
"CN",String
"RS"])),(String
"RelCl",(String
"RCl",[String
"Cl"])),(String
"RelNP",(String
"NP",[String
"NP",String
"RS"])),(String
"RelS",(String
"S",[String
"S",String
"RS"])),(String
"RelSlash",(String
"RCl",[String
"RP",String
"ClSlash"])),(String
"RelVP",(String
"RCl",[String
"RP",String
"VP"])),(String
"SSubjS",(String
"S",[String
"S",String
"Subj",String
"S"])),(String
"SentAP",(String
"AP",[String
"AP",String
"SC"])),(String
"SentCN",(String
"CN",[String
"CN",String
"SC"])),(String
"Slash2V3",(String
"VPSlash",[String
"V3",String
"NP"])),(String
"Slash3V3",(String
"VPSlash",[String
"V3",String
"NP"])),(String
"SlashPrep",(String
"ClSlash",[String
"Cl",String
"Prep"])),(String
"SlashV2A",(String
"VPSlash",[String
"V2A",String
"AP"])),(String
"SlashV2Q",(String
"VPSlash",[String
"V2Q",String
"QS"])),(String
"SlashV2S",(String
"VPSlash",[String
"V2S",String
"S"])),(String
"SlashV2V",(String
"VPSlash",[String
"V2V",String
"VP"])),(String
"SlashV2VNP",(String
"VPSlash",[String
"V2V",String
"NP",String
"VPSlash"])),(String
"SlashV2a",(String
"VPSlash",[String
"V2"])),(String
"SlashVP",(String
"ClSlash",[String
"NP",String
"VPSlash"])),(String
"SlashVS",(String
"ClSlash",[String
"NP",String
"VS",String
"SSlash"])),(String
"SlashVV",(String
"VPSlash",[String
"VV",String
"VPSlash"])),(String
"SubjS",(String
"Adv",[String
"Subj",String
"S"])),(String
"TExclMark",(String
"Text",[String
"Phr",String
"Text"])),(String
"TFullStop",(String
"Text",[String
"Phr",String
"Text"])),(String
"TQuestMark",(String
"Text",[String
"Phr",String
"Text"])),(String
"TTAnt",(String
"Temp",[String
"Tense",String
"Ant"])),(String
"Use2N3",(String
"N2",[String
"N3"])),(String
"Use3N3",(String
"N2",[String
"N3"])),(String
"UseA2",(String
"AP",[String
"A2"])),(String
"UseCl",(String
"S",[String
"Temp",String
"Pol",String
"Cl"])),(String
"UseComp",(String
"VP",[String
"Comp"])),(String
"UseComparA",(String
"AP",[String
"A"])),(String
"UseN",(String
"CN",[String
"N"])),(String
"UseN2",(String
"CN",[String
"N2"])),(String
"UsePN",(String
"NP",[String
"PN"])),(String
"UsePron",(String
"NP",[String
"Pron"])),(String
"UseQCl",(String
"QS",[String
"Temp",String
"Pol",String
"QCl"])),(String
"UseRCl",(String
"RS",[String
"Temp",String
"Pol",String
"RCl"])),(String
"UseSlash",(String
"SSlash",[String
"Temp",String
"Pol",String
"ClSlash"])),(String
"UseV",(String
"VP",[String
"V"])),(String
"UttAP",(String
"Utt",[String
"AP"])),(String
"UttAdv",(String
"Utt",[String
"Adv"])),(String
"UttCN",(String
"Utt",[String
"CN"])),(String
"UttCard",(String
"Utt",[String
"Card"])),(String
"UttIAdv",(String
"Utt",[String
"IAdv"])),(String
"UttIP",(String
"Utt",[String
"IP"])),(String
"UttImpPl",(String
"Utt",[String
"Pol",String
"Imp"])),(String
"UttImpPol",(String
"Utt",[String
"Pol",String
"Imp"])),(String
"UttImpSg",(String
"Utt",[String
"Pol",String
"Imp"])),(String
"UttInterj",(String
"Utt",[String
"Interj"])),(String
"UttNP",(String
"Utt",[String
"NP"])),(String
"UttQS",(String
"Utt",[String
"QS"])),(String
"UttS",(String
"Utt",[String
"S"])),(String
"UttVP",(String
"Utt",[String
"VP"])),(String
"VocNP",(String
"Voc",[String
"NP"])),(String
"dconcat",(String
"Digits",[String
"Digits",String
"Digits"])),(String
"digits2num",(String
"Numeral",[String
"Digits"])),(String
"dn",(String
"Digit",[String
"Dig"])),(String
"dn10",(String
"Sub10",[String
"Dig"])),(String
"dn100",(String
"Sub100",[String
"Dig",String
"Dig"])),(String
"dn1000",(String
"Sub1000",[String
"Dig",String
"Dig",String
"Dig"])),(String
"dn1000000a",(String
"Sub1000000",[String
"Dig",String
"Dig",String
"Dig",String
"Dig"])),(String
"dn1000000b",(String
"Sub1000000",[String
"Dig",String
"Dig",String
"Dig",String
"Dig",String
"Dig"])),(String
"dn1000000c",(String
"Sub1000000",[String
"Dig",String
"Dig",String
"Dig",String
"Dig",String
"Dig",String
"Dig"])),(String
"nd",(String
"Dig",[String
"Digit"])),(String
"nd10",(String
"Digits",[String
"Sub10"])),(String
"nd100",(String
"Digits",[String
"Sub100"])),(String
"nd1000",(String
"Digits",[String
"Sub1000"])),(String
"nd1000000",(String
"Digits",[String
"Sub1000000"])),(String
"num",(String
"Numeral",[String
"Sub1000000"])),(String
"num2digits",(String
"Digits",[String
"Numeral"])),(String
"pot0",(String
"Sub10",[String
"Digit"])),(String
"pot0as1",(String
"Sub100",[String
"Sub10"])),(String
"pot1",(String
"Sub100",[String
"Digit"])),(String
"pot1as2",(String
"Sub1000",[String
"Sub100"])),(String
"pot1plus",(String
"Sub100",[String
"Digit",String
"Sub10"])),(String
"pot1to19",(String
"Sub100",[String
"Digit"])),(String
"pot2",(String
"Sub1000",[String
"Sub10"])),(String
"pot2as3",(String
"Sub1000000",[String
"Sub1000"])),(String
"pot2plus",(String
"Sub1000",[String
"Sub10",String
"Sub100"])),(String
"pot3",(String
"Sub1000000",[String
"Sub1000"])),(String
"pot3plus",(String
"Sub1000000",[String
"Sub1000",String
"Sub1000"]))]