mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 08:32:50 -06:00
MinGrammar compilation more robust
This commit is contained in:
45
lib/src/mini/Compile.hs
Normal file
45
lib/src/mini/Compile.hs
Normal file
@@ -0,0 +1,45 @@
|
||||
import List
|
||||
import System
|
||||
|
||||
-- (c) Aarne Ranta 2010 under GNU LGPL
|
||||
|
||||
-- Compile files into pgf, in chosen combinations.
|
||||
|
||||
-- Usage: runghc Compile (-make | -link)? Eng Fre Fin ...
|
||||
-- The -make option links all pgf files to one in the end
|
||||
-- The -link option only links, without first compiling
|
||||
-- Arguments whose length are 3 characters are prefixed with mainmodu.
|
||||
-- Other arguments are passed literally.
|
||||
|
||||
-- Thus, for instance, to produce an English-Swedish-Romanian phrasebook with English
|
||||
-- disambiguation, the command is
|
||||
--
|
||||
-- runghc Compile -link Eng Swe Ron DisambPhrasebookEng
|
||||
|
||||
|
||||
-- change this to apply to another project; alternatively, just use full file names
|
||||
mainmodu = "MiniGrammar"
|
||||
|
||||
main = do
|
||||
(opts,langs) <- getArgs >>= return . partition ((=='-') . head)
|
||||
let modus = [mkFile la | la <- langs]
|
||||
putStrLn $ unwords modus
|
||||
if notElem "-link" opts
|
||||
then mapM_ compileOne modus >> return ()
|
||||
else return ()
|
||||
case opts of
|
||||
_ | elem "-make" opts || elem "-link" opts -> do
|
||||
let comm = "gf -make -s " ++ unwords (map (++ ".pgf") modus)
|
||||
putStrLn comm
|
||||
system comm
|
||||
return ()
|
||||
_ -> return ()
|
||||
|
||||
compileOne modu = do
|
||||
let comm = "gf -make -s -optimize-pgf -name=" ++
|
||||
modu ++ " " ++ modu ++ ".gf" ++
|
||||
" +RTS -K32M"
|
||||
putStrLn comm
|
||||
system comm
|
||||
|
||||
mkFile la = if length la == 3 then mainmodu ++ la else la
|
||||
@@ -1,3 +1,5 @@
|
||||
compile = runghc Compile
|
||||
|
||||
all: src pgf
|
||||
|
||||
src:
|
||||
@@ -8,3 +10,9 @@ pgf: src
|
||||
|
||||
gf: src
|
||||
gf -batch MiniGrammar???.gf
|
||||
|
||||
compdemo:
|
||||
$(compile) Afr Bul Cat Dan Dut Eng Fin Fre Ger Ita Nep Nor Pnb Pes Pol Rus Spa Swe Tha Urd
|
||||
|
||||
linkdemo:
|
||||
$(compile) -link Afr Bul Cat Dan Dut Eng Fin Fre Ger Ita Nep Nor Pnb Pes Pol Rus Spa Swe Tha Urd
|
||||
|
||||
@@ -108,7 +108,7 @@ abstract MiniGrammar = Lexicon, Grammar [
|
||||
here_Adv, -- Adv,
|
||||
by_Prep, in_Prep, of_Prep, with_Prep, -- Prep,
|
||||
can_VV, must_VV, want_VV, -- VV,
|
||||
although_Subj, because_Subj, when_Subj, -- Subj,
|
||||
although_Subj, because_Subj, when_Subj, if_Subj, -- Subj,
|
||||
when_IAdv, where_IAdv, why_IAdv-- IAdv,
|
||||
|
||||
] ** {
|
||||
@@ -128,7 +128,7 @@ fun
|
||||
this_Det, these_Det : Det ;
|
||||
that_Det, those_Det : Det ;
|
||||
i_NP, youSg_NP, he_NP, she_NP, we_NP, youPl_NP, they_NP : NP ;
|
||||
-- SubjS : S -> Subj -> S -> S ; -- she walks because we run
|
||||
SubjS : Subj -> S -> S -> Utt ; -- if she walks we run
|
||||
CompAdv : Adv -> VP ; -- be here
|
||||
-- SlashV2 : NP -> V2 -> ClSlash ; -- she loves
|
||||
SlashPrep : Cl -> Prep -> ClSlash ; -- she walks with
|
||||
|
||||
@@ -112,7 +112,7 @@ concrete MiniGrammarEng of MiniGrammar = LexiconEng, GrammarEng [
|
||||
here_Adv, -- Adv,
|
||||
by_Prep, in_Prep, of_Prep, with_Prep, -- Prep,
|
||||
can_VV, must_VV, want_VV, -- VV,
|
||||
although_Subj, because_Subj, when_Subj, -- Subj,
|
||||
although_Subj, because_Subj, when_Subj, if_Subj, -- Subj,
|
||||
when_IAdv, where_IAdv, why_IAdv-- IAdv,
|
||||
|
||||
] ** open SyntaxEng, (S = SyntaxEng) in {
|
||||
@@ -139,7 +139,7 @@ lin
|
||||
we_NP = S.we_NP ;
|
||||
youPl_NP = S.youPl_NP ;
|
||||
they_NP = S.they_NP ;
|
||||
-- SubjS s subj s = mkS s (mkAdv subj s) ;
|
||||
SubjS subj a b = mkUtt (mkS (S.mkAdv <subj : Subj> <a : S>) b) ;
|
||||
CompAdv adv = mkVP (lin Adv adv) ;
|
||||
-- SlashV2 np v2 = mkClSlash np v2 ;
|
||||
SlashPrep cl p = mkClSlash (lin Cl cl) <p : Prep> ;
|
||||
|
||||
@@ -180,7 +180,7 @@ lin
|
||||
leaf_N = mkN (thword "ใบ") ;
|
||||
-- learn_V2 = dirV2 (regV "learn") ;
|
||||
-- leather_N = regN "leather" ;
|
||||
-- leave_V2 = dirV2 (irregV "leave" "left" "left") ;
|
||||
leave_V2 = mkV2 "ละ" ;
|
||||
-- left_Ord = ss "left" ;
|
||||
leg_N = mkN (thword "ขา") ;
|
||||
lie_V = mkV (thword "นอน") ;
|
||||
|
||||
Reference in New Issue
Block a user