summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2006-03-31 13:20:40 +0000
committeraarne <aarne@cs.chalmers.se>2006-03-31 13:20:40 +0000
commitae30eca84446f8968341275518fe263660ec0534 (patch)
tree5a2525324fded7b07ca987817da0a73c14b77448 /src
parent0b3af5175e7cc7663a97d3453d6184ec75c264ae (diff)
gt -noexpand
Diffstat (limited to 'src')
-rw-r--r--src/GF/API.hs1
-rw-r--r--src/GF/Canon/CMacros.hs7
-rw-r--r--src/GF/Shell/HelpFile.hs28
-rw-r--r--src/GF/Shell/ShellCommands.hs6
-rw-r--r--src/GF/UseGrammar/Generate.hs10
-rw-r--r--src/HelpFile28
6 files changed, 54 insertions, 26 deletions
diff --git a/src/GF/API.hs b/src/GF/API.hs
index c15d03b6a..768fa7d6b 100644
--- a/src/GF/API.hs
+++ b/src/GF/API.hs
@@ -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
diff --git a/src/GF/Canon/CMacros.hs b/src/GF/Canon/CMacros.hs
index a61430512..572f09763 100644
--- a/src/GF/Canon/CMacros.hs
+++ b/src/GF/Canon/CMacros.hs
@@ -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
diff --git a/src/GF/Shell/HelpFile.hs b/src/GF/Shell/HelpFile.hs
index 702bba5e9..dfb01da08 100644
--- a/src/GF/Shell/HelpFile.hs
+++ b/src/GF/Shell/HelpFile.hs
@@ -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" ++
diff --git a/src/GF/Shell/ShellCommands.hs b/src/GF/Shell/ShellCommands.hs
index b62f2119d..d6209cffa 100644
--- a/src/GF/Shell/ShellCommands.hs
+++ b/src/GF/Shell/ShellCommands.hs
@@ -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"
diff --git a/src/GF/UseGrammar/Generate.hs b/src/GF/UseGrammar/Generate.hs
index f2482e8e8..c96bb5e40 100644
--- a/src/GF/UseGrammar/Generate.hs
+++ b/src/GF/UseGrammar/Generate.hs
@@ -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
diff --git a/src/HelpFile b/src/HelpFile
index 38b4fdcb2..1070a800e 100644
--- a/src/HelpFile
+++ b/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