forked from GitHub/gf-core
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
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
abstract AbsToAPI = {
|
abstract AbsToAPI = {
|
||||||
|
|
||||||
cat
|
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
|
fun
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
concrete AbsToAPIAbs of AbsToAPI = {
|
concrete AbsToAPIAbs of AbsToAPI = {
|
||||||
|
|
||||||
lincat
|
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} ;
|
ImpForm = {ind : Str; attr : Str; iform : IForm} ;
|
||||||
Punct = {ind : Str; attr : Str; pform : PForm } ;
|
Punct = {ind : Str; attr : Str; pform : PForm } ;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
concrete AbsToAPIapi of AbsToAPI = {
|
concrete AbsToAPIapi of AbsToAPI = {
|
||||||
|
|
||||||
lincat
|
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
|
lin
|
||||||
|
|
||||||
|
|||||||
47
lib/src/api/abstract_to_api/ConvertLex.hs
Normal file
47
lib/src/api/abstract_to_api/ConvertLex.hs
Normal file
@@ -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 ""
|
||||||
|
|
||||||
Reference in New Issue
Block a user