From 538ea8889efc19b619b26d9605835ef33eddc70f Mon Sep 17 00:00:00 2001 From: aarne Date: Wed, 28 Jun 2006 12:31:16 +0000 Subject: [PATCH] started looking at gt -all, not ready --- src/GF/Shell.hs | 5 +++++ src/GF/UseGrammar/Generate.hs | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/GF/Shell.hs b/src/GF/Shell.hs index 3dcec9fbd..66297ddc8 100644 --- a/src/GF/Shell.hs +++ b/src/GF/Shell.hs @@ -28,6 +28,7 @@ import qualified GF.Grammar.MMacros as MMacros import qualified GF.Compile.GrammarToCanon as GrammarToCanon import GF.Grammar.Values import GF.UseGrammar.GetTree +import GF.UseGrammar.Generate (generateAll) ---- should be in API import GF.UseGrammar.Treebank import GF.Shell.ShellCommands @@ -302,6 +303,10 @@ execC co@(comm, opts0) sa@(sh@(st,(h,_,_,_)),a) = checkOptions st co >> case com _ -> do ts <- randomTreesIO opts gro (optIntOrN opts flagNumber 1) returnArg (ATrms ts) sa + + CGenerateTrees | oElem showAll opts -> do + let cat = firstAbsCat opts gro + justOutput opts (generateAll opts (putStrLn . prt_) cgr cat) sa CGenerateTrees -> do let a' = case a of diff --git a/src/GF/UseGrammar/Generate.hs b/src/GF/UseGrammar/Generate.hs index d368056d4..a3173635e 100644 --- a/src/GF/UseGrammar/Generate.hs +++ b/src/GF/UseGrammar/Generate.hs @@ -17,7 +17,7 @@ -- guarantee the correctness of bindings\/dependences. ----------------------------------------------------------------------------- -module GF.UseGrammar.Generate (generateTrees) where +module GF.UseGrammar.Generate (generateTrees,generateAll) where import GF.Canon.GFC import GF.Grammar.LookAbs @@ -29,7 +29,6 @@ import GF.Grammar.SGrammar import GF.Data.Operations import GF.Data.Zipper import GF.Infra.Option - import Data.List -- Generate all trees of given category and depth. AR 30/4/2004 @@ -48,6 +47,18 @@ generateTrees opts gr cat n mn mt = map str2tr $ generate gr' ifm cat' n mn mt' mt' = maybe Nothing (return . tr2str) mt ifm = oElem withMetas opts +generateAll :: Options -> (Exp -> IO ()) -> GFCGrammar -> Cat -> IO () +generateAll opts io gr cat = mapM_ (io . str2tr) $ gen cat' + where + gr' = gr2sgr opts emptyProbs gr + cat' = prt $ snd cat + gen c = [SApp (f, xs) | + (f,(cs,_)) <- funs c, + xs <- combinations (map gen cs) + ] + funs c = errVal [] $ lookupTree id c gr' + + ------------------------------------------ -- do the main thing with a simpler data structure