From 401285f87fd08a7039f5bbf488e4f5d7a616f66b Mon Sep 17 00:00:00 2001 From: "ra.monique" Date: Sun, 23 Oct 2011 13:13:11 +0000 Subject: [PATCH] added script that converts a gf lexicon file to the format required by the abstrat to api translation grammar - to be used as a controlled language for writing linearizations for GF functions in the web editor --- lib/src/api/abstract_to_api/AbsToAPI.gf | 2 +- lib/src/api/abstract_to_api/AbsToAPIAbs.gf | 2 +- lib/src/api/abstract_to_api/AbsToAPIapi.gf | 2 +- lib/src/api/abstract_to_api/ConvertLex.hs | 47 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 lib/src/api/abstract_to_api/ConvertLex.hs diff --git a/lib/src/api/abstract_to_api/AbsToAPI.gf b/lib/src/api/abstract_to_api/AbsToAPI.gf index 02654ee69..3905a5268 100644 --- a/lib/src/api/abstract_to_api/AbsToAPI.gf +++ b/lib/src/api/abstract_to_api/AbsToAPI.gf @@ -1,7 +1,7 @@ abstract AbsToAPI = { cat -A; A2; AP; AdA; AdN; AdV; Adv; Ant; Art; CAdv; CN; Card; Cl; ClSlash; Comp; Conj; Det; Dig; Digit; Digits; IAdv; IComp; IDet; IP; IQuant; Imp; Interj; ListAP; ListAdv; ListCN; ListIAdv; ListNP; ListRS; ListS; N; N2; N3; NP; Num; Numeral; Ord; PConj; PN; Phr; Pol; Predet; Prep; Pron; QCl; QS; QVP; Quant; RCl; RP; RS; S; SC; SSlash; Subj; Temp; Tense; Text; Utt; V; V2; V2A; V2Q; V2S; V2V; V3; VA; VP; VPSlash; VQ; VS; VV; Voc; Punct; String ; ImpForm ; QuantSg; QuantPl ; +A; A2; A2V; AV; AP; AS; AdA; AdN; AdV; Adv; Ant; Art; CAdv; CN; Card; Cl; ClSlash; Comp; Conj; Det; Dig; Digit; Digits; IAdv; IComp; IDet; IP; IQuant; Imp; Interj; ListAP; ListAdv; ListCN; ListIAdv; ListNP; ListRS; ListS; N; N2; N3; NP; Num; Numeral; Ord; PConj; PN; Phr; Pol; Predet; Prep; Pron; QCl; QS; QVP; Quant; RCl; RP; RS; S; SC; SSlash; Subj; Temp; Tense; Text; Utt; V; V0; V2; V2A; V2Q; V2S; V2V; V3; VA; VP; VPSlash; VQ; VS; VV; Voc; Punct; String ; ImpForm ; QuantSg; QuantPl ; fun diff --git a/lib/src/api/abstract_to_api/AbsToAPIAbs.gf b/lib/src/api/abstract_to_api/AbsToAPIAbs.gf index 8c6407d59..73e7a9b97 100644 --- a/lib/src/api/abstract_to_api/AbsToAPIAbs.gf +++ b/lib/src/api/abstract_to_api/AbsToAPIAbs.gf @@ -1,7 +1,7 @@ concrete AbsToAPIAbs of AbsToAPI = { lincat -A, A2, AP, AdA, AdN, AdV, Adv, Ant, Art, CAdv, CN, Card, Cl, ClSlash, Comp, Conj, Det, Dig, Digit, Digits, IAdv, IComp, IDet, IP, IQuant, Imp, Interj, ListAP, ListAdv, ListCN, ListIAdv, ListNP, ListRS, ListS, N, N2, N3, NP, Num, Numeral, Ord, PConj, PN, Phr, Pol, Predet, Prep, Pron, QCl, QS, QVP, Quant, RCl, RP, RS, S, SC, SSlash, Subj, Temp, Tense, Text, Utt, V, V2, V2A, V2Q, V2S, V2V, V3, VA, VP, VPSlash, VQ, VS, VV, Voc, String, QuantSg, QuantPl = {ind : Str; attr : Str} ; +A, A2, A2V, AV, AS, AP, AdA, AdN, AdV, Adv, Ant, Art, CAdv, CN, Card, Cl, ClSlash, Comp, Conj, Det, Dig, Digit, Digits, IAdv, IComp, IDet, IP, IQuant, Imp, Interj, ListAP, ListAdv, ListCN, ListIAdv, ListNP, ListRS, ListS, N, N2, N3, NP, Num, Numeral, Ord, PConj, PN, Phr, Pol, Predet, Prep, Pron, QCl, QS, QVP, Quant, RCl, RP, RS, S, SC, SSlash, Subj, Temp, Tense, Text, Utt, V, V0, V2, V2A, V2Q, V2S, V2V, V3, VA, VP, VPSlash, VQ, VS, VV, Voc, String, QuantSg, QuantPl = {ind : Str; attr : Str} ; ImpForm = {ind : Str; attr : Str; iform : IForm} ; Punct = {ind : Str; attr : Str; pform : PForm } ; diff --git a/lib/src/api/abstract_to_api/AbsToAPIapi.gf b/lib/src/api/abstract_to_api/AbsToAPIapi.gf index 2ea734c57..cdb148957 100644 --- a/lib/src/api/abstract_to_api/AbsToAPIapi.gf +++ b/lib/src/api/abstract_to_api/AbsToAPIapi.gf @@ -1,7 +1,7 @@ concrete AbsToAPIapi of AbsToAPI = { lincat -A, A2, AP, AdA, AdN, AdV, Adv, Ant, Art, CAdv, CN, Card, Cl, ClSlash, Comp, Conj, Det, Dig, Digit, Digits, IAdv, IComp, IDet, IP, IQuant, Imp, Interj, ListAP, ListAdv, ListCN, ListIAdv, ListNP, ListRS, ListS, N, N2, N3, NP, Num, Numeral, Ord, PConj, PN, Phr, Pol, Predet, Prep, Pron, QCl, QS, QVP, Quant, RCl, RP, RS, S, SC, SSlash, Subj, Temp, Tense, Text, Utt, V, V2, V2A, V2Q, V2S, V2V, V3, VA, VP, VPSlash, VQ, VS, VV, Voc, Punct, String , QuantSg , QuantPl , ImpForm = {ind : Str; attr : Str} ; +A, A2, A2V, AV, AS, AP, AdA, AdN, AdV, Adv, Ant, Art, CAdv, CN, Card, Cl, ClSlash, Comp, Conj, Det, Dig, Digit, Digits, IAdv, IComp, IDet, IP, IQuant, Imp, Interj, ListAP, ListAdv, ListCN, ListIAdv, ListNP, ListRS, ListS, N, N2, N3, NP, Num, Numeral, Ord, PConj, PN, Phr, Pol, Predet, Prep, Pron, QCl, QS, QVP, Quant, RCl, RP, RS, S, SC, SSlash, Subj, Temp, Tense, Text, Utt, V, V0, V2, V2A, V2Q, V2S, V2V, V3, VA, VP, VPSlash, VQ, VS, VV, Voc, Punct, String , QuantSg , QuantPl , ImpForm = {ind : Str; attr : Str} ; lin diff --git a/lib/src/api/abstract_to_api/ConvertLex.hs b/lib/src/api/abstract_to_api/ConvertLex.hs new file mode 100644 index 000000000..08affeb27 --- /dev/null +++ b/lib/src/api/abstract_to_api/ConvertLex.hs @@ -0,0 +1,47 @@ +module ConvertLex where + +import System.Environment (getArgs) +import System.Exit (exitFailure) +import System.IO + +import Data.List +import Data.Char + +main = + do args <- getArgs + case args of + [fname] -> + do file <- readFile fname + let newName = "Abs" ++ (reverse $ takeWhile (/= '/') $ reverse fname) + let rootName = reverse $ drop 3 $ takeWhile (/='/') $ reverse newName + let absContent = unlines $ map (makeAbstract (\bf pos hd -> bf ++" fun " ++ hd ++ " : " ++ pos ++ " ; ")) (lines file) + let intContent = unlines $ map (makeAbstract (\bf pos hd -> bf ++ " lin " ++ hd ++ " = " ++ "mkSimpCat" ++ "\"" ++ hd ++ "\" ;")) (lines file) + let absFile = "abstract " ++ rootName ++ " = AbsToAPI ** { \n\n" ++ absContent ++ "\n\n}" + let intFile = "incomplete concrete " ++ rootName ++ "I of " ++ rootName ++ " = AbsToAPI ** {\n\n" ++ intContent ++ "\n\n}" + let concAbs = "concrete " ++ rootName ++ "Abs of " ++ rootName ++ " = AbsToAPIAbs, "++ rootName ++ "I ** {}" + let concApi = "concrete " ++ rootName ++ "api of " ++ rootName ++ " = AbsToAPIapi, "++ rootName ++ "I ** {}" + writeFile newName absFile + putStrLn $ "Wrote file "++ newName + writeFile (rootName ++ "I.gf") intFile + putStrLn $ "Wrote file " ++ rootName ++ "I.gf" + writeFile (rootName ++ "Abs.gf") concAbs + putStrLn $ "Wrote file " ++ rootName ++ "Abs.gf" + writeFile (rootName ++ "api.gf") concApi + putStrLn $ "Wrote file " ++ rootName ++ "api.gf" + _ -> error "usage ConvertLex file_name" + + +makeAbstract :: (String -> String -> String -> String) -> String -> String +makeAbstract fcs str = + let newss = dropWhile isSpace str + in + if isInfixOf "=" newss && isInfixOf ";" newss then + let hd = head $ words newss + maybepos = dropWhile (/='_') hd + pos = if null maybepos then "??" else tail maybepos + bf = if null maybepos then "--" else "" + in + if isInfixOf "flags" newss && bf == "--" then "" + else fcs bf pos hd + else "" +