summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2006-08-16 08:48:26 +0000
committeraarne <aarne@cs.chalmers.se>2006-08-16 08:48:26 +0000
commitdc5f5811dcd26e8a67d1fb5a30c5db756c9d7391 (patch)
tree3ef4dd5f8d52dfb3ec5116dfc17f6f88127e1e8e /src
parent6bf419c50c719ac1b2d2808c84760eb0d1258d1d (diff)
some more options to gt
Diffstat (limited to 'src')
-rw-r--r--src/GF/Shell/HelpFile.hs5
-rw-r--r--src/GF/UseGrammar/Generate.hs22
-rw-r--r--src/HelpFile5
3 files changed, 18 insertions, 14 deletions
diff --git a/src/GF/Shell/HelpFile.hs b/src/GF/Shell/HelpFile.hs
index e989d5104..e4a24cb9f 100644
--- a/src/GF/Shell/HelpFile.hs
+++ b/src/GF/Shell/HelpFile.hs
@@ -349,14 +349,15 @@ txtHelpFile =
"\n the tree." ++
"\n options:" ++
"\n -metas also return trees that include metavariables" ++
- "\n -all generate all (lazily)" ++
+ "\n -all generate all (can be infinitely many, lazily)" ++
"\n -lin linearize result of -all (otherwise, use pipe to linearize)" ++
"\n flags:" ++
"\n -depth generate to this depth (default 3)" ++
"\n -atoms take this number of atomic rules of each category (default unlimited)" ++
"\n -alts take this number of alternatives at each branch (default unlimited)" ++
"\n -cat generate in this category" ++
- "\n -old use an older algorithm (usually more memory-consuming)" ++
+ "\n -nonub don't remove duplicates (faster, not effective with -mem)" ++
+ "\n -mem use a memorizing algorithm (often faster, usually more memory-consuming)" ++
"\n -lang use the abstract syntax of this grammar" ++
"\n -number generate (at most) this number of trees (also works with -all)" ++
"\n -noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)" ++
diff --git a/src/GF/UseGrammar/Generate.hs b/src/GF/UseGrammar/Generate.hs
index 25e27df1c..dfc0783aa 100644
--- a/src/GF/UseGrammar/Generate.hs
+++ b/src/GF/UseGrammar/Generate.hs
@@ -41,7 +41,7 @@ import Data.List
-- | the main function takes an abstract syntax and returns a list of trees
generateTrees ::
Options -> GFCGrammar -> Cat -> Int -> Maybe Int -> Maybe Tree -> [Exp]
-generateTrees opts gr cat n mn mt = map str2tr $ generate gr' ifm cat' n mn mt'
+generateTrees opts gr cat n mn mt = map str2tr $ generate gr' opts cat' n mn mt'
where
gr' = gr2sgr opts emptyProbs gr
cat' = prt $ snd cat
@@ -55,7 +55,7 @@ generateAll opts io gr cat = mapM_ (io . str2tr) $ num $ gen cat'
num = optIntOrAll opts flagNumber
gr' = gr2sgr opts emptyProbs gr
cat' = prt $ snd cat
- gen c = generate gr' False c 10 Nothing Nothing
+ gen c = generate gr' opts c 10 Nothing Nothing
@@ -66,14 +66,16 @@ generateAll opts io gr cat = mapM_ (io . str2tr) $ num $ gen cat'
-- if the depth is large (more than 3)
-- If a tree is given as argument, generation concerns its metavariables.
-generate :: SGrammar -> Bool -> SCat -> Int -> Maybe Int -> Maybe STree -> [STree]
-generate gr ifm cat i mn mt = case mt of
- Nothing -> gen ifm cat
+generate :: SGrammar -> Options -> SCat -> Int -> Maybe Int -> Maybe STree -> [STree]
+generate gr opts cat i mn mt = case mt of
+ Nothing -> gen opts cat
Just t -> genM t
where
--- now use ifm to choose between two algorithms
- gen True cat = concat $ errVal [] $ lookupTree id cat $ allTrees -- -old
- gen _ cat = nub $ concatMap (\i -> gener i cat) [0..i-1] -- new
+ gen opts cat
+ | oElem (iOpt "mem") opts = concat $ errVal [] $ lookupTree id cat $ allTrees -- -old
+ | oElem (iOpt "nonub") opts = concatMap (\i -> gener i cat) [0..i-1] -- some duplicates
+ | otherwise = nub $ concatMap (\i -> gener i cat) [0..i-1] -- new
gener 0 c = [SApp (f, []) | (f,([],_)) <- funs c]
gener i c = [
@@ -81,8 +83,8 @@ generate gr ifm cat i mn mt = case mt of
(f,(cs,_)) <- funs c,
let alts = map (gener (i-1)) cs,
ts <- combinations alts,
- let tr = SApp (f, ts)
--- depth tr >= i
+ let tr = SApp (f, ts),
+ depth tr >= i
]
allTrees = genAll i
@@ -110,5 +112,5 @@ generate gr ifm cat i mn mt = case mt of
genM t = case t of
SApp (f,ts) -> [SApp (f,ts') | ts' <- combinations (map genM ts)]
- SMeta k -> gen ifm k
+ SMeta k -> gen opts k
_ -> [t]
diff --git a/src/HelpFile b/src/HelpFile
index 25965d075..1fbb50b85 100644
--- a/src/HelpFile
+++ b/src/HelpFile
@@ -320,14 +320,15 @@ gt, generate_trees: gt Tree?
the tree.
options:
-metas also return trees that include metavariables
- -all generate all (lazily)
+ -all generate all (can be infinitely many, lazily)
-lin linearize result of -all (otherwise, use pipe to linearize)
flags:
-depth generate to this depth (default 3)
-atoms take this number of atomic rules of each category (default unlimited)
-alts take this number of alternatives at each branch (default unlimited)
-cat generate in this category
- -old use an older algorithm (usually more memory-consuming)
+ -nonub don't remove duplicates (faster, not effective with -mem)
+ -mem use a memorizing algorithm (often faster, usually more memory-consuming)
-lang use the abstract syntax of this grammar
-number generate (at most) this number of trees (also works with -all)
-noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)