mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
some more options to gt
This commit is contained in:
@@ -349,14 +349,15 @@ txtHelpFile =
|
|||||||
"\n the tree." ++
|
"\n the tree." ++
|
||||||
"\n options:" ++
|
"\n options:" ++
|
||||||
"\n -metas also return trees that include metavariables" ++
|
"\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 -lin linearize result of -all (otherwise, use pipe to linearize)" ++
|
||||||
"\n flags:" ++
|
"\n flags:" ++
|
||||||
"\n -depth generate to this depth (default 3)" ++
|
"\n -depth generate to this depth (default 3)" ++
|
||||||
"\n -atoms take this number of atomic rules of each category (default unlimited)" ++
|
"\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 -alts take this number of alternatives at each branch (default unlimited)" ++
|
||||||
"\n -cat generate in this category" ++
|
"\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 -lang use the abstract syntax of this grammar" ++
|
||||||
"\n -number generate (at most) this number of trees (also works with -all)" ++
|
"\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)" ++
|
"\n -noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)" ++
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import Data.List
|
|||||||
-- | the main function takes an abstract syntax and returns a list of trees
|
-- | the main function takes an abstract syntax and returns a list of trees
|
||||||
generateTrees ::
|
generateTrees ::
|
||||||
Options -> GFCGrammar -> Cat -> Int -> Maybe Int -> Maybe Tree -> [Exp]
|
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
|
where
|
||||||
gr' = gr2sgr opts emptyProbs gr
|
gr' = gr2sgr opts emptyProbs gr
|
||||||
cat' = prt $ snd cat
|
cat' = prt $ snd cat
|
||||||
@@ -55,7 +55,7 @@ generateAll opts io gr cat = mapM_ (io . str2tr) $ num $ gen cat'
|
|||||||
num = optIntOrAll opts flagNumber
|
num = optIntOrAll opts flagNumber
|
||||||
gr' = gr2sgr opts emptyProbs gr
|
gr' = gr2sgr opts emptyProbs gr
|
||||||
cat' = prt $ snd cat
|
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 the depth is large (more than 3)
|
||||||
-- If a tree is given as argument, generation concerns its metavariables.
|
-- If a tree is given as argument, generation concerns its metavariables.
|
||||||
|
|
||||||
generate :: SGrammar -> Bool -> SCat -> Int -> Maybe Int -> Maybe STree -> [STree]
|
generate :: SGrammar -> Options -> SCat -> Int -> Maybe Int -> Maybe STree -> [STree]
|
||||||
generate gr ifm cat i mn mt = case mt of
|
generate gr opts cat i mn mt = case mt of
|
||||||
Nothing -> gen ifm cat
|
Nothing -> gen opts cat
|
||||||
Just t -> genM t
|
Just t -> genM t
|
||||||
where
|
where
|
||||||
--- now use ifm to choose between two algorithms
|
--- now use ifm to choose between two algorithms
|
||||||
gen True cat = concat $ errVal [] $ lookupTree id cat $ allTrees -- -old
|
gen opts cat
|
||||||
gen _ cat = nub $ concatMap (\i -> gener i cat) [0..i-1] -- new
|
| 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 0 c = [SApp (f, []) | (f,([],_)) <- funs c]
|
||||||
gener i c = [
|
gener i c = [
|
||||||
@@ -81,8 +83,8 @@ generate gr ifm cat i mn mt = case mt of
|
|||||||
(f,(cs,_)) <- funs c,
|
(f,(cs,_)) <- funs c,
|
||||||
let alts = map (gener (i-1)) cs,
|
let alts = map (gener (i-1)) cs,
|
||||||
ts <- combinations alts,
|
ts <- combinations alts,
|
||||||
let tr = SApp (f, ts)
|
let tr = SApp (f, ts),
|
||||||
-- depth tr >= i
|
depth tr >= i
|
||||||
]
|
]
|
||||||
|
|
||||||
allTrees = genAll i
|
allTrees = genAll i
|
||||||
@@ -110,5 +112,5 @@ generate gr ifm cat i mn mt = case mt of
|
|||||||
|
|
||||||
genM t = case t of
|
genM t = case t of
|
||||||
SApp (f,ts) -> [SApp (f,ts') | ts' <- combinations (map genM ts)]
|
SApp (f,ts) -> [SApp (f,ts') | ts' <- combinations (map genM ts)]
|
||||||
SMeta k -> gen ifm k
|
SMeta k -> gen opts k
|
||||||
_ -> [t]
|
_ -> [t]
|
||||||
|
|||||||
@@ -320,14 +320,15 @@ gt, generate_trees: gt Tree?
|
|||||||
the tree.
|
the tree.
|
||||||
options:
|
options:
|
||||||
-metas also return trees that include metavariables
|
-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)
|
-lin linearize result of -all (otherwise, use pipe to linearize)
|
||||||
flags:
|
flags:
|
||||||
-depth generate to this depth (default 3)
|
-depth generate to this depth (default 3)
|
||||||
-atoms take this number of atomic rules of each category (default unlimited)
|
-atoms take this number of atomic rules of each category (default unlimited)
|
||||||
-alts take this number of alternatives at each branch (default unlimited)
|
-alts take this number of alternatives at each branch (default unlimited)
|
||||||
-cat generate in this category
|
-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
|
-lang use the abstract syntax of this grammar
|
||||||
-number generate (at most) this number of trees (also works with -all)
|
-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)
|
-noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)
|
||||||
|
|||||||
Reference in New Issue
Block a user