Skip to content

Commit c23a03a

Browse files
authored
Merge pull request #184 from inariksit/update-depth-documentation
Update default depth to 5 + less hardcoding in documentation
2 parents af09351 + 183e421 commit c23a03a

File tree

5 files changed

+48
-37
lines changed

5 files changed

+48
-37
lines changed

doc/gf-help-full.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#TINY
4747

4848
The command has one argument which is either function, expression or
49-
a category defined in the abstract syntax of the current grammar.
49+
a category defined in the abstract syntax of the current grammar.
5050
If the argument is a function then ?its type is printed out.
5151
If it is a category then the category definition is printed.
5252
If a whole expression is given it prints the expression with refined
@@ -303,7 +303,7 @@ but the resulting .gf file must be imported separately.
303303

304304
#TINY
305305

306-
Generates a list of random trees, by default one tree.
306+
Generates a list of random trees, by default one tree up to depth 5.
307307
If a tree argument is given, the command completes the Tree with values to
308308
all metavariables in the tree. The generation can be biased by probabilities,
309309
given in a file in the -probs flag.
@@ -315,13 +315,14 @@ given in a file in the -probs flag.
315315
| ``-cat`` | generation category
316316
| ``-lang`` | uses only functions that have linearizations in all these languages
317317
| ``-number`` | number of trees generated
318-
| ``-depth`` | the maximum generation depth
318+
| ``-depth`` | the maximum generation depth (default: 5)
319319
| ``-probs`` | file with biased probabilities (format 'f 0.4' one by line)
320320

321321
- Examples:
322322

323323
| ``gr`` | one tree in the startcat of the current grammar
324324
| ``gr -cat=NP -number=16`` | 16 trees in the category NP
325+
| ``gr -cat=NP -depth=2`` | one tree in the category NP, up to depth 2
325326
| ``gr -lang=LangHin,LangTha -cat=Cl`` | Cl, both in LangHin and LangTha
326327
| ``gr -probs=FILE`` | generate with bias
327328
| ``gr (AdjCN ? (UseN ?))`` | generate trees of form (AdjCN ? (UseN ?))
@@ -338,8 +339,8 @@ given in a file in the -probs flag.
338339

339340
#TINY
340341

341-
Generates all trees of a given category. By default,
342-
the depth is limited to 4, but this can be changed by a flag.
342+
Generates all trees of a given category. By default,
343+
the depth is limited to 5, but this can be changed by a flag.
343344
If a Tree argument is given, the command completes the Tree with values
344345
to all metavariables in the tree.
345346

@@ -353,7 +354,7 @@ to all metavariables in the tree.
353354

354355
- Examples:
355356

356-
| ``gt`` | all trees in the startcat, to depth 4
357+
| ``gt`` | all trees in the startcat, to depth 5
357358
| ``gt -cat=NP -number=16`` | 16 trees in the category NP
358359
| ``gt -cat=NP -depth=2`` | trees in the category NP to depth 2
359360
| ``gt (AdjCN ? (UseN ?))`` | trees of form (AdjCN ? (UseN ?))
@@ -582,7 +583,7 @@ trees where a function node is a metavariable.
582583

583584
- Examples:
584585

585-
| ``l -lang=LangSwe,LangNor -chunks ? a b (? c d)`` |
586+
| ``l -lang=LangSwe,LangNor -chunks ? a b (? c d)`` |
586587

587588

588589
#NORMAL
@@ -647,7 +648,7 @@ The -lang flag can be used to restrict this to fewer languages.
647648
The default start category can be overridden by the -cat flag.
648649
See also the ps command for lexing and character encoding.
649650

650-
The -openclass flag is experimental and allows some robustness in
651+
The -openclass flag is experimental and allows some robustness in
651652
the parser. For example if -openclass="A,N,V" is given, the parser
652653
will accept unknown adjectives, nouns and verbs with the resource grammar.
653654

doc/tutorial/gf-tutorial.t2t

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ use ``generate_trees = gt``.
11881188
this wine is fresh
11891189
this wine is warm
11901190
```
1191-
The default **depth** is 3; the depth can be
1191+
The default **depth** is 5; the depth can be
11921192
set by using the ``depth`` flag:
11931193
```
11941194
> generate_trees -depth=2 | l
@@ -1739,9 +1739,9 @@ A new module can **extend** an old one:
17391739
Pizza : Kind ;
17401740
}
17411741
```
1742-
Note that the extended grammar doesn't inherit the start
1743-
category from the grammar it extends, so if you want to
1744-
generate sentences with this grammar, you'll have to either
1742+
Note that the extended grammar doesn't inherit the start
1743+
category from the grammar it extends, so if you want to
1744+
generate sentences with this grammar, you'll have to either
17451745
add a startcat (e.g. ``flags startcat = Question ;``),
17461746
or in the GF shell, specify the category to ``generate_random`` or ``geneate_trees``
17471747
(e.g. ``gr -cat=Comment`` or ``gt -cat=Question``).
@@ -3746,7 +3746,7 @@ However, type-incorrect commands are rejected by the typecheck:
37463746
The parsing is successful but the type checking failed with error(s):
37473747
Couldn't match expected type Device light
37483748
against the interred type Device fan
3749-
In the expression: DKindOne fan
3749+
In the expression: DKindOne fan
37503750
```
37513751

37523752
#NEW
@@ -4184,7 +4184,7 @@ division of integers.
41844184
```
41854185
abstract Calculator = {
41864186
flags startcat = Exp ;
4187-
4187+
41884188
cat Exp ;
41894189

41904190
fun

src/compiler/GF/Command/Commands.hs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import GF.Infra.SIO
2222
import GF.Command.Abstract
2323
import GF.Command.CommandInfo
2424
import GF.Command.CommonCommands
25+
import qualified GF.Command.CommonCommands as Common
2526
import GF.Text.Clitics
2627
import GF.Quiz
2728

@@ -166,14 +167,15 @@ pgfCommands = Map.fromList [
166167
synopsis = "generate random trees in the current abstract syntax",
167168
syntax = "gr [-cat=CAT] [-number=INT]",
168169
examples = [
169-
mkEx "gr -- one tree in the startcat of the current grammar",
170-
mkEx "gr -cat=NP -number=16 -- 16 trees in the category NP",
171-
mkEx "gr -lang=LangHin,LangTha -cat=Cl -- Cl, both in LangHin and LangTha",
172-
mkEx "gr -probs=FILE -- generate with bias",
173-
mkEx "gr (AdjCN ? (UseN ?)) -- generate trees of form (AdjCN ? (UseN ?))"
170+
mkEx $ "gr -- one tree in the startcat of the current grammar, up to depth " ++ Common.default_depth_str,
171+
mkEx "gr -cat=NP -number=16 -- 16 trees in the category NP",
172+
mkEx "gr -cat=NP -depth=2 -- one tree in the category NP, up to depth 2",
173+
mkEx "gr -lang=LangHin,LangTha -cat=Cl -- Cl, both in LangHin and LangTha",
174+
mkEx "gr -probs=FILE -- generate with bias",
175+
mkEx "gr (AdjCN ? (UseN ?)) -- generate trees of form (AdjCN ? (UseN ?))"
174176
],
175177
explanation = unlines [
176-
"Generates a list of random trees, by default one tree.",
178+
"Generates a list of random trees, by default one tree up to depth " ++ Common.default_depth_str ++ ".",
177179
"If a tree argument is given, the command completes the Tree with values to",
178180
"all metavariables in the tree. The generation can be biased by probabilities,",
179181
"given in a file in the -probs flag."
@@ -182,13 +184,13 @@ pgfCommands = Map.fromList [
182184
("cat","generation category"),
183185
("lang","uses only functions that have linearizations in all these languages"),
184186
("number","number of trees generated"),
185-
("depth","the maximum generation depth"),
187+
("depth","the maximum generation depth (default: " ++ Common.default_depth_str ++ ")"),
186188
("probs", "file with biased probabilities (format 'f 0.4' one by line)")
187189
],
188190
exec = getEnv $ \ opts arg (Env pgf mos) -> do
189191
pgf <- optProbs opts (optRestricted opts pgf)
190192
gen <- newStdGen
191-
let dp = valIntOpts "depth" 4 opts
193+
let dp = valIntOpts "depth" Common.default_depth opts
192194
let ts = case mexp (toExprs arg) of
193195
Just ex -> generateRandomFromDepth gen pgf ex (Just dp)
194196
Nothing -> generateRandomDepth gen pgf (optType pgf opts) (Just dp)
@@ -199,25 +201,25 @@ pgfCommands = Map.fromList [
199201
synopsis = "generates a list of trees, by default exhaustive",
200202
explanation = unlines [
201203
"Generates all trees of a given category. By default, ",
202-
"the depth is limited to 4, but this can be changed by a flag.",
204+
"the depth is limited to " ++ Common.default_depth_str ++ ", but this can be changed by a flag.",
203205
"If a Tree argument is given, the command completes the Tree with values",
204206
"to all metavariables in the tree."
205207
],
206208
flags = [
207209
("cat","the generation category"),
208-
("depth","the maximum generation depth"),
210+
("depth","the maximum generation depth (default: " ++ Common.default_depth_str ++ ")"),
209211
("lang","excludes functions that have no linearization in this language"),
210212
("number","the number of trees generated")
211213
],
212214
examples = [
213-
mkEx "gt -- all trees in the startcat, to depth 4",
214-
mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP",
215-
mkEx "gt -cat=NP -depth=2 -- trees in the category NP to depth 2",
216-
mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))"
215+
mkEx $ "gt -- all trees in the startcat, to depth " ++ Common.default_depth_str,
216+
mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP",
217+
mkEx "gt -cat=NP -depth=2 -- trees in the category NP to depth 2",
218+
mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))"
217219
],
218220
exec = getEnv $ \ opts arg (Env pgf mos) -> do
219221
let pgfr = optRestricted opts pgf
220-
let dp = valIntOpts "depth" 4 opts
222+
let dp = valIntOpts "depth" Common.default_depth opts
221223
let ts = case toExprs arg of
222224
[] -> generateAllDepth pgfr (optType pgf opts) (Just dp)
223225
es -> concat [generateFromDepth pgfr e (Just dp) | e <- es]
@@ -547,7 +549,7 @@ pgfCommands = Map.fromList [
547549
"which is processed by dot (graphviz) and displayed by the program indicated",
548550
"by the view flag. The target format is png, unless overridden by the",
549551
"flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).",
550-
"See also 'vp -showdep' for another visualization of dependencies."
552+
"See also 'vp -showdep' for another visualization of dependencies."
551553
],
552554
exec = getEnv $ \ opts arg (Env pgf mos) -> do
553555
let absname = abstractName pgf
@@ -760,7 +762,7 @@ pgfCommands = Map.fromList [
760762
[] -> [parse_ pgf lang (optType pgf opts) (Just dp) s | lang <- optLangs pgf opts]
761763
open_typs -> [parseWithRecovery pgf lang (optType pgf opts) open_typs (Just dp) s | lang <- optLangs pgf opts]
762764
where
763-
dp = valIntOpts "depth" 4 opts
765+
dp = valIntOpts "depth" Common.default_depth opts
764766

765767
fromParse opts = foldr (joinPiped . fromParse1 opts) void
766768

@@ -800,9 +802,9 @@ pgfCommands = Map.fromList [
800802
_ | isOpt "tabtreebank" opts ->
801803
return $ concat $ intersperse "\t" $ (showExpr [] t) :
802804
[s | lang <- optLangs pgf opts, s <- linear pgf opts lang t]
803-
_ | isOpt "chunks" opts -> map snd $ linChunks pgf opts t
805+
_ | isOpt "chunks" opts -> map snd $ linChunks pgf opts t
804806
_ -> [s | lang <- optLangs pgf opts, s<-linear pgf opts lang t]
805-
linChunks pgf opts t =
807+
linChunks pgf opts t =
806808
[(lang, unwords (intersperse "<+>" (map (unlines . linear pgf opts lang) (treeChunks t)))) | lang <- optLangs pgf opts]
807809

808810
linear :: PGF -> [Option] -> CId -> Expr -> [String]
@@ -1006,13 +1008,13 @@ viewLatex view name grphs = do
10061008
restrictedSystem $ "pdflatex " ++ texfile
10071009
restrictedSystem $ view ++ " " ++ pdffile
10081010
return void
1009-
1011+
10101012
---- copied from VisualizeTree ; not sure about proper place AR Nov 2015
10111013
latexDoc :: [String] -> String
10121014
latexDoc body = unlines $
10131015
"\\batchmode"
10141016
: "\\documentclass{article}"
1015-
: "\\usepackage[utf8]{inputenc}"
1017+
: "\\usepackage[utf8]{inputenc}"
10161018
: "\\begin{document}"
10171019
: spaces body
10181020
++ ["\\end{document}"]

src/compiler/GF/Command/CommonCommands.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import Data.Char (isSpace)
1919

2020
import qualified PGF as H(showCId,showExpr,toATree,toTrie,Trie(..))
2121

22+
-- store default generation depth in a variable and use everywhere
23+
default_depth :: Int
24+
default_depth = 5
25+
default_depth_str = show default_depth
26+
27+
2228
extend old new = Map.union (Map.fromList new) old -- Map.union is left-biased
2329

2430
commonCommands :: (Monad m,MonadSIO m) => Map.Map String (CommandInfo m)

src/server/PGFService.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ limit, depth :: CGI (Maybe Int)
571571
limit = readInput "limit"
572572
depth = readInput "depth"
573573

574+
default_depth_server = 4
575+
574576
start :: CGI Int
575577
start = maybe 0 id # readInput "start"
576578

@@ -781,7 +783,7 @@ doRandom pgf mcat mdepth mlimit to =
781783
| tree <- limit trees]
782784
where cat = fromMaybe (PGF.startCat pgf) mcat
783785
limit = take (fromMaybe 1 mlimit)
784-
depth = fromMaybe 4 mdepth
786+
depth = fromMaybe default_depth_server mdepth
785787

786788
doGenerate :: PGF -> Maybe PGF.Type -> Maybe Int -> Maybe Int -> To -> JSValue
787789
doGenerate pgf mcat mdepth mlimit tos =
@@ -794,7 +796,7 @@ doGenerate pgf mcat mdepth mlimit tos =
794796
trees = PGF.generateAllDepth pgf cat (Just depth)
795797
cat = fromMaybe (PGF.startCat pgf) mcat
796798
limit = take (fromMaybe 1 mlimit)
797-
depth = fromMaybe 4 mdepth
799+
depth = fromMaybe default_depth_server mdepth
798800

799801
doGrammar :: (UTCTime,PGF) -> Either IOError (UTCTime,l) -> Maybe (Accept Language) -> CGI CGIResult
800802
doGrammar (t1,pgf) elbls macc = out t $ showJSON $ makeObj

0 commit comments

Comments
 (0)