diff --git a/examples/animals/QuestionsEng.gf b/examples/animals/QuestionsEng.gf index 8a4c5c406..c8f51fb82 100644 --- a/examples/animals/QuestionsEng.gf +++ b/examples/animals/QuestionsEng.gf @@ -1,2 +1,2 @@ concrete QuestionsEng of Questions = QuestionsI with - (Lang = LangEng) ; + (Syntax = SyntaxEng) ; diff --git a/examples/animals/QuestionsI.gf b/examples/animals/QuestionsI.gf index ce0cb627a..eb7c2f697 100644 --- a/examples/animals/QuestionsI.gf +++ b/examples/animals/QuestionsI.gf @@ -1,7 +1,7 @@ --- to compile: echo "eb -file=QuestionsI.gfe" -probs=probs | gf $GF_LIB_PATH/present/LangEng.gfo +-- to compile: echo "eb -probs=probs -api -file=QuestionsI.gfe" | gf $GF_LIB_PATH/present/LangEng.gfo -- or use directly gf do let file = optFile opts pgf <- optProbs opts pgf - let conf = configureExBased pgf (optMorpho opts) (optLang opts) + let printer = if (isOpt "api" opts) then exprToAPI else (showExpr []) + let conf = configureExBased pgf (optMorpho opts) (optLang opts) printer (file',ws) <- parseExamplesInGrammar conf file if null ws then return () else putStrLn ("unknown words: " ++ unwords ws) return (fromString ("wrote " ++ file')), diff --git a/src/compiler/GF/Compile/ExampleBased.hs b/src/compiler/GF/Compile/ExampleBased.hs index 24944d9b6..b4c0caf75 100644 --- a/src/compiler/GF/Compile/ExampleBased.hs +++ b/src/compiler/GF/Compile/ExampleBased.hs @@ -6,6 +6,7 @@ module GF.Compile.ExampleBased ( import PGF import PGF.Probabilistic import PGF.Morphology +import PGF.ToAPI import Data.List @@ -55,11 +56,16 @@ convertFile conf src file = do return [] ParseOk ts -> case rank ts of - (t:tt) -> appv ("WARNING: ambiguous example " ++ ex) >> - appn t >> mapM_ (appn . (" --- " ++)) tt >> return [] - appn ")" + (t:tt) -> do + if null tt + then return () + else appv ("WARNING: ambiguous example " ++ ex) + appn t + mapM_ (appn . (" --- " ++)) tt + appn ")" + return [] return ws - rank ts = [showExpr [] t ++ " -- " ++ show p | (t,p) <- rankTreesByProbs pgf ts] + rank ts = [printExp conf t ++ " -- " ++ show p | (t,p) <- rankTreesByProbs pgf ts] appf = appendFile file appn s = appf s >> appf "\n" appv s = appn ("--- " ++ s) >> putStrLn s @@ -68,9 +74,10 @@ data ExConfiguration = ExConf { resource_pgf :: PGF, resource_morpho :: Morpho, verbose :: Bool, - language :: Language + language :: Language, + printExp :: Tree -> String } -configureExBased :: PGF -> Morpho -> Language -> ExConfiguration -configureExBased pgf morpho lang = ExConf pgf morpho False lang +configureExBased :: PGF -> Morpho -> Language -> (Tree -> String) -> ExConfiguration +configureExBased pgf morpho lang pr = ExConf pgf morpho False lang pr