mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
Merge pull request #184 from inariksit/update-depth-documentation
Update default depth to 5 + less hardcoding in documentation
This commit is contained in:
@@ -303,7 +303,7 @@ but the resulting .gf file must be imported separately.
|
|||||||
|
|
||||||
#TINY
|
#TINY
|
||||||
|
|
||||||
Generates a list of random trees, by default one tree.
|
Generates a list of random trees, by default one tree up to depth 5.
|
||||||
If a tree argument is given, the command completes the Tree with values to
|
If a tree argument is given, the command completes the Tree with values to
|
||||||
all metavariables in the tree. The generation can be biased by probabilities,
|
all metavariables in the tree. The generation can be biased by probabilities,
|
||||||
given in a file in the -probs flag.
|
given in a file in the -probs flag.
|
||||||
@@ -315,13 +315,14 @@ given in a file in the -probs flag.
|
|||||||
| ``-cat`` | generation category
|
| ``-cat`` | generation category
|
||||||
| ``-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
|
||||||
| ``-depth`` | the maximum generation depth
|
| ``-depth`` | the maximum generation depth (default: 5)
|
||||||
| ``-probs`` | file with biased probabilities (format 'f 0.4' one by line)
|
| ``-probs`` | file with biased probabilities (format 'f 0.4' one by line)
|
||||||
|
|
||||||
- Examples:
|
- Examples:
|
||||||
|
|
||||||
| ``gr`` | one tree in the startcat of the current grammar
|
| ``gr`` | one tree in the startcat of the current grammar
|
||||||
| ``gr -cat=NP -number=16`` | 16 trees in the category NP
|
| ``gr -cat=NP -number=16`` | 16 trees in the category NP
|
||||||
|
| ``gr -cat=NP -depth=2`` | one tree in the category NP, up to depth 2
|
||||||
| ``gr -lang=LangHin,LangTha -cat=Cl`` | Cl, both in LangHin and LangTha
|
| ``gr -lang=LangHin,LangTha -cat=Cl`` | Cl, both in LangHin and LangTha
|
||||||
| ``gr -probs=FILE`` | generate with bias
|
| ``gr -probs=FILE`` | generate with bias
|
||||||
| ``gr (AdjCN ? (UseN ?))`` | generate trees of form (AdjCN ? (UseN ?))
|
| ``gr (AdjCN ? (UseN ?))`` | generate trees of form (AdjCN ? (UseN ?))
|
||||||
@@ -339,7 +340,7 @@ given in a file in the -probs flag.
|
|||||||
#TINY
|
#TINY
|
||||||
|
|
||||||
Generates all trees of a given category. By default,
|
Generates all trees of a given category. By default,
|
||||||
the depth is limited to 4, but this can be changed by a flag.
|
the depth is limited to 5, but this can be changed by a flag.
|
||||||
If a Tree argument is given, the command completes the Tree with values
|
If a Tree argument is given, the command completes the Tree with values
|
||||||
to all metavariables in the tree.
|
to all metavariables in the tree.
|
||||||
|
|
||||||
@@ -353,7 +354,7 @@ to all metavariables in the tree.
|
|||||||
|
|
||||||
- Examples:
|
- Examples:
|
||||||
|
|
||||||
| ``gt`` | all trees in the startcat, to depth 4
|
| ``gt`` | all trees in the startcat, to depth 5
|
||||||
| ``gt -cat=NP -number=16`` | 16 trees in the category NP
|
| ``gt -cat=NP -number=16`` | 16 trees in the category NP
|
||||||
| ``gt -cat=NP -depth=2`` | trees in the category NP to depth 2
|
| ``gt -cat=NP -depth=2`` | trees in the category NP to depth 2
|
||||||
| ``gt (AdjCN ? (UseN ?))`` | trees of form (AdjCN ? (UseN ?))
|
| ``gt (AdjCN ? (UseN ?))`` | trees of form (AdjCN ? (UseN ?))
|
||||||
|
|||||||
@@ -1188,7 +1188,7 @@ use ``generate_trees = gt``.
|
|||||||
this wine is fresh
|
this wine is fresh
|
||||||
this wine is warm
|
this wine is warm
|
||||||
```
|
```
|
||||||
The default **depth** is 3; the depth can be
|
The default **depth** is 5; the depth can be
|
||||||
set by using the ``depth`` flag:
|
set by using the ``depth`` flag:
|
||||||
```
|
```
|
||||||
> generate_trees -depth=2 | l
|
> generate_trees -depth=2 | l
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import GF.Infra.SIO
|
|||||||
import GF.Command.Abstract
|
import GF.Command.Abstract
|
||||||
import GF.Command.CommandInfo
|
import GF.Command.CommandInfo
|
||||||
import GF.Command.CommonCommands
|
import GF.Command.CommonCommands
|
||||||
|
import qualified GF.Command.CommonCommands as Common
|
||||||
import GF.Text.Clitics
|
import GF.Text.Clitics
|
||||||
import GF.Quiz
|
import GF.Quiz
|
||||||
|
|
||||||
@@ -166,14 +167,15 @@ pgfCommands = Map.fromList [
|
|||||||
synopsis = "generate random trees in the current abstract syntax",
|
synopsis = "generate random trees in the current abstract syntax",
|
||||||
syntax = "gr [-cat=CAT] [-number=INT]",
|
syntax = "gr [-cat=CAT] [-number=INT]",
|
||||||
examples = [
|
examples = [
|
||||||
mkEx "gr -- one tree in the startcat of the current grammar",
|
mkEx $ "gr -- one tree in the startcat of the current grammar, up to depth " ++ Common.default_depth_str,
|
||||||
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 -cat=NP -depth=2 -- one tree in the category NP, up to depth 2",
|
||||||
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 -probs=FILE -- generate with bias",
|
||||||
mkEx "gr (AdjCN ? (UseN ?)) -- generate trees of form (AdjCN ? (UseN ?))"
|
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 up to depth " ++ Common.default_depth_str ++ ".",
|
||||||
"If a tree argument is given, the command completes the Tree with values to",
|
"If a tree argument is given, the command completes the Tree with values to",
|
||||||
"all metavariables in the tree. The generation can be biased by probabilities,",
|
"all metavariables in the tree. The generation can be biased by probabilities,",
|
||||||
"given in a file in the -probs flag."
|
"given in a file in the -probs flag."
|
||||||
@@ -182,13 +184,13 @@ pgfCommands = Map.fromList [
|
|||||||
("cat","generation category"),
|
("cat","generation category"),
|
||||||
("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"),
|
||||||
("depth","the maximum generation depth"),
|
("depth","the maximum generation depth (default: " ++ Common.default_depth_str ++ ")"),
|
||||||
("probs", "file with biased probabilities (format 'f 0.4' one by line)")
|
("probs", "file with biased probabilities (format 'f 0.4' one by line)")
|
||||||
],
|
],
|
||||||
exec = getEnv $ \ opts arg (Env pgf mos) -> do
|
exec = getEnv $ \ opts arg (Env pgf mos) -> do
|
||||||
pgf <- optProbs opts (optRestricted opts pgf)
|
pgf <- optProbs opts (optRestricted opts pgf)
|
||||||
gen <- newStdGen
|
gen <- newStdGen
|
||||||
let dp = valIntOpts "depth" 4 opts
|
let dp = valIntOpts "depth" Common.default_depth opts
|
||||||
let ts = case mexp (toExprs arg) of
|
let ts = case mexp (toExprs arg) of
|
||||||
Just ex -> generateRandomFromDepth gen pgf ex (Just dp)
|
Just ex -> generateRandomFromDepth gen pgf ex (Just dp)
|
||||||
Nothing -> generateRandomDepth gen pgf (optType pgf opts) (Just dp)
|
Nothing -> generateRandomDepth gen pgf (optType pgf opts) (Just dp)
|
||||||
@@ -199,25 +201,25 @@ 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. By default, ",
|
"Generates all trees of a given category. By default, ",
|
||||||
"the depth is limited to 4, but this can be changed by a flag.",
|
"the depth is limited to " ++ Common.default_depth_str ++ ", but this can be changed by a flag.",
|
||||||
"If a Tree argument is given, the command completes the Tree with values",
|
"If a Tree argument is given, the command completes the Tree with values",
|
||||||
"to all metavariables in the tree."
|
"to all metavariables in the tree."
|
||||||
],
|
],
|
||||||
flags = [
|
flags = [
|
||||||
("cat","the generation category"),
|
("cat","the generation category"),
|
||||||
("depth","the maximum generation depth"),
|
("depth","the maximum generation depth (default: " ++ Common.default_depth_str ++ ")"),
|
||||||
("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, to depth 4",
|
mkEx $ "gt -- all trees in the startcat, to depth " ++ Common.default_depth_str,
|
||||||
mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP",
|
mkEx "gt -cat=NP -number=16 -- 16 trees in the category NP",
|
||||||
mkEx "gt -cat=NP -depth=2 -- trees in the category NP to depth 2",
|
mkEx "gt -cat=NP -depth=2 -- trees in the category NP to depth 2",
|
||||||
mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))"
|
mkEx "gt (AdjCN ? (UseN ?)) -- trees of form (AdjCN ? (UseN ?))"
|
||||||
],
|
],
|
||||||
exec = getEnv $ \ opts arg (Env pgf mos) -> do
|
exec = getEnv $ \ opts arg (Env pgf mos) -> do
|
||||||
let pgfr = optRestricted opts pgf
|
let pgfr = optRestricted opts pgf
|
||||||
let dp = valIntOpts "depth" 4 opts
|
let dp = valIntOpts "depth" Common.default_depth opts
|
||||||
let ts = case toExprs arg of
|
let ts = case toExprs arg of
|
||||||
[] -> generateAllDepth pgfr (optType pgf opts) (Just dp)
|
[] -> generateAllDepth pgfr (optType pgf opts) (Just dp)
|
||||||
es -> concat [generateFromDepth pgfr e (Just dp) | e <- es]
|
es -> concat [generateFromDepth pgfr e (Just dp) | e <- es]
|
||||||
@@ -760,7 +762,7 @@ pgfCommands = Map.fromList [
|
|||||||
[] -> [parse_ pgf lang (optType pgf opts) (Just dp) s | lang <- optLangs pgf opts]
|
[] -> [parse_ pgf lang (optType pgf opts) (Just dp) s | lang <- optLangs pgf opts]
|
||||||
open_typs -> [parseWithRecovery pgf lang (optType pgf opts) open_typs (Just dp) s | lang <- optLangs pgf opts]
|
open_typs -> [parseWithRecovery pgf lang (optType pgf opts) open_typs (Just dp) s | lang <- optLangs pgf opts]
|
||||||
where
|
where
|
||||||
dp = valIntOpts "depth" 4 opts
|
dp = valIntOpts "depth" Common.default_depth opts
|
||||||
|
|
||||||
fromParse opts = foldr (joinPiped . fromParse1 opts) void
|
fromParse opts = foldr (joinPiped . fromParse1 opts) void
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ import Data.Char (isSpace)
|
|||||||
|
|
||||||
import qualified PGF as H(showCId,showExpr,toATree,toTrie,Trie(..))
|
import qualified PGF as H(showCId,showExpr,toATree,toTrie,Trie(..))
|
||||||
|
|
||||||
|
-- store default generation depth in a variable and use everywhere
|
||||||
|
default_depth :: Int
|
||||||
|
default_depth = 5
|
||||||
|
default_depth_str = show default_depth
|
||||||
|
|
||||||
|
|
||||||
extend old new = Map.union (Map.fromList new) old -- Map.union is left-biased
|
extend old new = Map.union (Map.fromList new) old -- Map.union is left-biased
|
||||||
|
|
||||||
commonCommands :: (Monad m,MonadSIO m) => Map.Map String (CommandInfo m)
|
commonCommands :: (Monad m,MonadSIO m) => Map.Map String (CommandInfo m)
|
||||||
|
|||||||
@@ -571,6 +571,8 @@ limit, depth :: CGI (Maybe Int)
|
|||||||
limit = readInput "limit"
|
limit = readInput "limit"
|
||||||
depth = readInput "depth"
|
depth = readInput "depth"
|
||||||
|
|
||||||
|
default_depth_server = 4
|
||||||
|
|
||||||
start :: CGI Int
|
start :: CGI Int
|
||||||
start = maybe 0 id # readInput "start"
|
start = maybe 0 id # readInput "start"
|
||||||
|
|
||||||
@@ -781,7 +783,7 @@ doRandom pgf mcat mdepth mlimit to =
|
|||||||
| tree <- limit trees]
|
| tree <- limit trees]
|
||||||
where cat = fromMaybe (PGF.startCat pgf) mcat
|
where cat = fromMaybe (PGF.startCat pgf) mcat
|
||||||
limit = take (fromMaybe 1 mlimit)
|
limit = take (fromMaybe 1 mlimit)
|
||||||
depth = fromMaybe 4 mdepth
|
depth = fromMaybe default_depth_server mdepth
|
||||||
|
|
||||||
doGenerate :: PGF -> Maybe PGF.Type -> Maybe Int -> Maybe Int -> To -> JSValue
|
doGenerate :: PGF -> Maybe PGF.Type -> Maybe Int -> Maybe Int -> To -> JSValue
|
||||||
doGenerate pgf mcat mdepth mlimit tos =
|
doGenerate pgf mcat mdepth mlimit tos =
|
||||||
@@ -794,7 +796,7 @@ doGenerate pgf mcat mdepth mlimit tos =
|
|||||||
trees = PGF.generateAllDepth pgf cat (Just depth)
|
trees = PGF.generateAllDepth pgf cat (Just depth)
|
||||||
cat = fromMaybe (PGF.startCat pgf) mcat
|
cat = fromMaybe (PGF.startCat pgf) mcat
|
||||||
limit = take (fromMaybe 1 mlimit)
|
limit = take (fromMaybe 1 mlimit)
|
||||||
depth = fromMaybe 4 mdepth
|
depth = fromMaybe default_depth_server mdepth
|
||||||
|
|
||||||
doGrammar :: (UTCTime,PGF) -> Either IOError (UTCTime,l) -> Maybe (Accept Language) -> CGI CGIResult
|
doGrammar :: (UTCTime,PGF) -> Either IOError (UTCTime,l) -> Maybe (Accept Language) -> CGI CGIResult
|
||||||
doGrammar (t1,pgf) elbls macc = out t $ showJSON $ makeObj
|
doGrammar (t1,pgf) elbls macc = out t $ showJSON $ makeObj
|
||||||
|
|||||||
Reference in New Issue
Block a user