mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
gt -noexpand
This commit is contained in:
@@ -234,6 +234,7 @@ optLinearizeTree opts0 gr t = case getOptVal opts transferFun of
|
||||
| mk == markOptJava -> lin markXMLjgf
|
||||
| mk == markOptStruct -> lin markBracket
|
||||
| mk == markOptFocus -> lin markFocus
|
||||
| mk == "metacat" -> lin metaCatMark
|
||||
| otherwise -> lin noMark
|
||||
_ -> lin noMark
|
||||
|
||||
|
||||
@@ -50,6 +50,13 @@ noMark :: Marker
|
||||
noMark = defTMarker mk where
|
||||
mk _ _ _ = ("","")
|
||||
|
||||
-- | mark metas with their categories
|
||||
metaCatMark :: Marker
|
||||
metaCatMark = defTMarker mk where
|
||||
mk nod _ _ = case nod of
|
||||
V.N (_,V.AtM _,val,_,_) -> ("", '+':prt val)
|
||||
_ -> ("","")
|
||||
|
||||
-- | for vanilla brackets, focus, and position, use
|
||||
markBracket :: Marker
|
||||
markBracket = defTMarker mk where
|
||||
|
||||
@@ -335,18 +335,20 @@ txtHelpFile =
|
||||
"\n command completes the Tree with values to the metavariables in" ++
|
||||
"\n the tree." ++
|
||||
"\n options:" ++
|
||||
"\n -metas also return trees that include metavariables" ++
|
||||
"\n -metas also return trees that include metavariables" ++
|
||||
"\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 -lang use the abstract syntax of this grammar" ++
|
||||
"\n -number generate (at most) this number of trees" ++
|
||||
"\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 -lang use the abstract syntax of this grammar" ++
|
||||
"\n -number generate (at most) this number of trees" ++
|
||||
"\n -noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)" ++
|
||||
"\n examples:" ++
|
||||
"\n gt -depth=10 -cat=NP -- generate all NP's to depth 10 " ++
|
||||
"\n gt (PredVP ? (NegVG ?)) -- generate all trees of this form" ++
|
||||
"\n gt -cat=S -tr | l -- gererate and linearize" ++
|
||||
"\n gt -depth=10 -cat=NP -- generate all NP's to depth 10 " ++
|
||||
"\n gt (PredVP ? (NegVG ?)) -- generate all trees of this form" ++
|
||||
"\n gt -cat=S -tr | l -- generate and linearize" ++
|
||||
"\n gt -noexpand=NP | l -mark=metacat -- the only NP is meta, linearized \"?0 +NP\"" ++
|
||||
"\n" ++
|
||||
"\nma, morphologically_analyse: ma String" ++
|
||||
"\n Runs morphological analysis on each word in String and displays" ++
|
||||
@@ -525,6 +527,7 @@ txtHelpFile =
|
||||
"\n options" ++
|
||||
"\n -all show the whole help file" ++
|
||||
"\n -defs show user-defined commands and terms" ++
|
||||
"\n -FLAG show the values of FLAG (works for grammar-independent flags)" ++
|
||||
"\n examples:" ++
|
||||
"\n h print_grammar -- show all information on the pg command" ++
|
||||
"\n" ++
|
||||
@@ -674,6 +677,11 @@ txtHelpFile =
|
||||
"\n -unlexer=concat remove all spaces" ++
|
||||
"\n -unlexer=bind like identity, but bind at \"&+\"" ++
|
||||
"\n" ++
|
||||
"\n-mark, marking of parts of tree in linearization. The default is none." ++
|
||||
"\n -mark=metacat append \"+CAT\" to every metavariable, showing its category" ++
|
||||
"\n -mark=struct show tree structure with brackets" ++
|
||||
"\n -mark=java show tree structure with XML tags (used in gfeditor)" ++
|
||||
"\n" ++
|
||||
"\n-coding, Some grammars are in UTF-8, some in isolatin-1." ++
|
||||
"\n If the letters ä (a-umlaut) and ö (u-umlaut) look strange, either" ++
|
||||
"\n change your terminal to isolatin-1, or rewrite the grammar with" ++
|
||||
|
||||
@@ -179,12 +179,12 @@ optionsOfCommand co = case co of
|
||||
CStripState -> none
|
||||
CTransformGrammar _ -> flags "printer"
|
||||
CConvertLatex _ -> none
|
||||
CLinearize _ -> both "utf8 table struct record all multi" "lang number unlexer"
|
||||
CLinearize _ -> both "utf8 table struct record all multi" "lang number unlexer mark"
|
||||
CParse -> both "cut new newer cfg mcfg n ign raw v lines all prob"
|
||||
"cat lang lexer parser number rawtrees"
|
||||
CTranslate _ _ -> opts "cat lexer parser"
|
||||
CGenerateRandom -> both "cf prob" "cat lang number depth"
|
||||
CGenerateTrees -> both "metas" "atoms depth alts cat lang number"
|
||||
CGenerateTrees -> both "metas" "atoms depth alts cat lang number noexpand"
|
||||
CPutTerm -> flags "transform number"
|
||||
CTreeBank -> opts "c xml trees"
|
||||
CLookupTreebank -> both "assocs raw strings trees" "treebank"
|
||||
@@ -216,7 +216,7 @@ optionsOfCommand co = case co of
|
||||
CPrintMultiGrammar -> both "utf8 utf8id" "printer"
|
||||
CPrintSourceGrammar -> both "utf8" "printer"
|
||||
|
||||
CHelp _ -> opts "all alts atoms coding defs filter length lexer unlexer printer probs transform depth number"
|
||||
CHelp _ -> opts "all alts atoms coding defs filter length lexer unlexer printer probs transform depth number cat"
|
||||
|
||||
CImpure ICEditSession -> both "f" "file"
|
||||
CImpure ICTranslateSession -> both "f langs" "cat"
|
||||
|
||||
@@ -43,17 +43,18 @@ import Data.List
|
||||
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'
|
||||
where
|
||||
gr' = gr2sgr ats gr
|
||||
gr' = gr2sgr noe ats gr
|
||||
cat' = prt $ snd cat
|
||||
mt' = maybe Nothing (return . tr2str) mt
|
||||
ifm = oElem withMetas opts
|
||||
ats = getOptInt opts (aOpt "atoms")
|
||||
noe = maybe [] (chunks ',') $ getOptVal opts (aOpt "noexpand")
|
||||
|
||||
------------------------------------------
|
||||
-- translate grammar to simpler form and generated trees back
|
||||
|
||||
gr2sgr :: Maybe Int -> GFCGrammar -> SGrammar
|
||||
gr2sgr un gr = buildTree [(c,rs) | rs@((_,(_,c)):_) <- prune rules] where
|
||||
gr2sgr :: [SIdent] -> Maybe Int -> GFCGrammar -> SGrammar
|
||||
gr2sgr noe un gr = buildTree [(c,noexp c rs) | rs@((_,(_,c)):_) <- prune rules] where
|
||||
rules =
|
||||
groupBy (\x y -> scat x == scat y) $
|
||||
sortBy (\x y -> compare (scat x) (scat y))
|
||||
@@ -71,8 +72,11 @@ gr2sgr un gr = buildTree [(c,rs) | rs@((_,(_,c)):_) <- prune rules] where
|
||||
in take n rs1 ++ rs2
|
||||
atom = null . fst . snd
|
||||
|
||||
noexp c rs = if elem c noe then [('?':c,([],c))] else rs
|
||||
|
||||
-- str2tr :: STree -> Exp
|
||||
str2tr t = case t of
|
||||
SApp ('?':c,[]) -> mkMeta 0 -- from noexpand=c
|
||||
SApp (f,ts) -> mkApp (trId f) (map str2tr ts)
|
||||
SMeta _ -> mkMeta 0
|
||||
---- SString s -> K s
|
||||
|
||||
28
src/HelpFile
28
src/HelpFile
@@ -306,18 +306,20 @@ gt, generate_trees: gt Tree?
|
||||
command completes the Tree with values to the metavariables in
|
||||
the tree.
|
||||
options:
|
||||
-metas also return trees that include metavariables
|
||||
-metas also return trees that include metavariables
|
||||
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
|
||||
-lang use the abstract syntax of this grammar
|
||||
-number generate (at most) this number of trees
|
||||
-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
|
||||
-lang use the abstract syntax of this grammar
|
||||
-number generate (at most) this number of trees
|
||||
-noexpand don't expand these categories (comma-separated, e.g. -noexpand=V,CN)
|
||||
examples:
|
||||
gt -depth=10 -cat=NP -- generate all NP's to depth 10
|
||||
gt (PredVP ? (NegVG ?)) -- generate all trees of this form
|
||||
gt -cat=S -tr | l -- gererate and linearize
|
||||
gt -depth=10 -cat=NP -- generate all NP's to depth 10
|
||||
gt (PredVP ? (NegVG ?)) -- generate all trees of this form
|
||||
gt -cat=S -tr | l -- generate and linearize
|
||||
gt -noexpand=NP | l -mark=metacat -- the only NP is meta, linearized "?0 +NP"
|
||||
|
||||
ma, morphologically_analyse: ma String
|
||||
Runs morphological analysis on each word in String and displays
|
||||
@@ -496,6 +498,7 @@ h, help: h Command?
|
||||
options
|
||||
-all show the whole help file
|
||||
-defs show user-defined commands and terms
|
||||
-FLAG show the values of FLAG (works for grammar-independent flags)
|
||||
examples:
|
||||
h print_grammar -- show all information on the pg command
|
||||
|
||||
@@ -645,6 +648,11 @@ q, quit: q
|
||||
-unlexer=concat remove all spaces
|
||||
-unlexer=bind like identity, but bind at "&+"
|
||||
|
||||
-mark, marking of parts of tree in linearization. The default is none.
|
||||
-mark=metacat append "+CAT" to every metavariable, showing its category
|
||||
-mark=struct show tree structure with brackets
|
||||
-mark=java show tree structure with XML tags (used in gfeditor)
|
||||
|
||||
-coding, Some grammars are in UTF-8, some in isolatin-1.
|
||||
If the letters ä (a-umlaut) and ö (u-umlaut) look strange, either
|
||||
change your terminal to isolatin-1, or rewrite the grammar with
|
||||
|
||||
Reference in New Issue
Block a user