1
0
forked from GitHub/gf-core

restore the depth flag for gt and gr

This commit is contained in:
Krasimir Angelov
2023-03-13 14:01:14 +01:00
parent ed45bf9ebd
commit 92c2840b2b

View File

@@ -164,29 +164,31 @@ pgfCommands = Map.fromList [
mkEx "gr -- one tree in the startcat of the current grammar", mkEx "gr -- one tree in the startcat of the current grammar",
mkEx "gr -cat=NP -number=16 -- 16 trees in the category NP", mkEx "gr -cat=NP -number=16 -- 16 trees in the category NP",
mkEx "gr -lang=LangHin,LangTha -cat=Cl -- Cl, both in LangHin and LangTha", mkEx "gr -lang=LangHin,LangTha -cat=Cl -- Cl, both in LangHin and LangTha",
mkEx "gr -probs=FILE -- generate with bias", mkEx "gr (AdjCN ? (UseN ?)) -- fills in the metavariables in the expression"
mkEx "gr (AdjCN ? (UseN ?)) -- generate trees of form (AdjCN ? (UseN ?))"
], ],
explanation = unlines [ explanation = unlines [
"Generates a list of random trees, by default one tree.", "Generates a list of random trees, by default one tree.",
"If a tree argument is given, the command completes the Tree with values to", "If a tree argument is given, the command fills in",
"all metavariables in the tree. The generation can be biased by probabilities", "the metavariables in the tree with values. The generation is",
"if the grammar was compiled with option -probs" "biased by probabilities if the grammar was compiled with",
"option -probs."
], ],
options = [ options = [
("show_probs", "show the probability of each result") ("show_probs", "show the probability of each result")
], ],
flags = [ flags = [
("cat","generation category"), ("cat","generation category"),
("depth","the maximum generation depth, default 4"),
("lang","uses only functions that have linearizations in all these languages"), ("lang","uses only functions that have linearizations in all these languages"),
("number","number of trees generated") ("number","number of trees generated")
], ],
exec = needPGF $ \opts arg pgf -> do exec = needPGF $ \opts arg pgf -> do
gen <- newStdGen gen <- newStdGen
let ts = case mexp (toExprs arg) of let dp = valIntOpts "depth" 4 opts
Just ex -> generateRandomFrom gen pgf ex es = case mexp (toExprs arg) of
Nothing -> generateRandom gen pgf (optType pgf opts) Just ex -> generateRandomFromDepth gen pgf ex dp
returnFromExprs (isOpt "show_probs" opts) $ take (optNum opts) ts Nothing -> generateRandomDepth gen pgf (optType pgf opts) dp
returnFromExprs (isOpt "show_probs" opts) $ take (optNum opts) es
}), }),
("gt", emptyCommandInfo { ("gt", emptyCommandInfo {
@@ -194,26 +196,31 @@ pgfCommands = Map.fromList [
synopsis = "generates a list of trees, by default exhaustive", synopsis = "generates a list of trees, by default exhaustive",
explanation = unlines [ explanation = unlines [
"Generates all trees of a given category.", "Generates all trees of a given category.",
"If a Tree argument is given, the command completes the Tree with values", "If a tree argument is given, the command completes",
"to all metavariables in the tree." "the metavariables in the tree with values.",
"The generated trees are listed in decreasing probability order",
"(increasing negated log-probability)."
], ],
options = [ options = [
("show_probs", "show the probability of each result") ("show_probs", "show the probability of each result")
], ],
flags = [ flags = [
("cat","the generation category"), ("cat","the generation category"),
("depth","the maximum generation depth, default 4"),
("lang","excludes functions that have no linearization in this language"), ("lang","excludes functions that have no linearization in this language"),
("number","the number of trees generated") ("number","the number of trees generated")
], ],
examples = [ examples = [
mkEx "gt -- all trees in the startcat", mkEx "gt -- all trees in the startcat with maximal depth 4",
mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP", mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP with maximal depth 4",
mkEx "gt -cat=NP -depth=2 -- all trees in the category NP with up to depth 2",
mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))" mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))"
], ],
exec = needPGF $ \opts arg pgf -> do exec = needPGF $ \opts arg pgf -> do
let es = case mexp (toExprs arg) of let dp = valIntOpts "depth" 4 opts
Just ex -> generateAllFrom pgf ex es = case mexp (toExprs arg) of
Nothing -> generateAll pgf (optType pgf opts) Just ex -> generateAllFromDepth pgf ex dp
Nothing -> generateAllDepth pgf (optType pgf opts) dp
returnFromExprs (isOpt "show_probs" opts) $ takeOptNum opts es returnFromExprs (isOpt "show_probs" opts) $ takeOptNum opts es
}), }),