1
0
forked from GitHub/gf-core

moved commands pf and af to options of pg and wf, respectively

This commit is contained in:
aarne
2008-06-16 20:36:10 +00:00
parent 012e07cded
commit 937df7382a
2 changed files with 28 additions and 34 deletions

View File

@@ -76,7 +76,7 @@ gf comm file = do
putStrLn $ "reading " ++ file putStrLn $ "reading " ++ file
system $ "echo \"" ++ comm ++ "\" | gf3 -s " ++ file system $ "echo \"" ++ comm ++ "\" | gf3 -s " ++ file
treeb = "rf -lines -term -file=" ++ treebankExx ++ treeb = "rf -lines -tree -file=" ++ treebankExx ++
" | l -treebank | wf -file=" ++ treebankResults " | l -treebank | wf -file=" ++ treebankResults
lang (lla,la) = lla ++ "/Lang" ++ la ++ ".gf" lang (lla,la) = lla ++ "/Lang" ++ la ++ ".gf"

View File

@@ -79,15 +79,6 @@ commandHelp full (co,info) = unlines $ [
-- this list must no more be kept sorted by the command name -- this list must no more be kept sorted by the command name
allCommands :: PGF -> Map.Map String CommandInfo allCommands :: PGF -> Map.Map String CommandInfo
allCommands pgf = Map.fromList [ allCommands pgf = Map.fromList [
("af", emptyCommandInfo {
longname = "append_file",
synopsis = "append string or tree to a file",
exec = \opts arg -> do
let file = valIdOpts "file" "_gftmp" opts
appendFile file (toString arg)
return void,
flags = [("file","name of the file")]
}),
("cc", emptyCommandInfo { ("cc", emptyCommandInfo {
longname = "compute_concrete", longname = "compute_concrete",
syntax = "cc (-all | -table | -unqual)? TERM", syntax = "cc (-all | -table | -unqual)? TERM",
@@ -196,9 +187,12 @@ allCommands pgf = Map.fromList [
synopsis = "convert an abstract syntax expression to string", synopsis = "convert an abstract syntax expression to string",
explanation = unlines [ explanation = unlines [
"Shows the linearization of a Tree by the grammars in scope.", "Shows the linearization of a Tree by the grammars in scope.",
"The -lang flag can be used to restrict this to one language.", "The -lang flag can be used to restrict this to fewer languages.",
"See also the ps command for unlexing and character encoding." "See also the ps command for unlexing and character encoding."
], ],
examples = [
"l -langs=LangSwe,LangNor no_Utt -- linearize to LangSwe and LangNor"
],
exec = \opts -> return . fromStrings . map (optLin opts), exec = \opts -> return . fromStrings . map (optLin opts),
options = [ options = [
("all","show all forms and variants"), ("all","show all forms and variants"),
@@ -208,7 +202,7 @@ allCommands pgf = Map.fromList [
("treebank","show the tree and tag linearizations with language names") ("treebank","show the tree and tag linearizations with language names")
], ],
flags = [ flags = [
("lang","the language of linearization") ("lang","the languages of linearization (comma-separated, no spaces)")
] ]
}), }),
("ma", emptyCommandInfo { ("ma", emptyCommandInfo {
@@ -244,32 +238,24 @@ allCommands pgf = Map.fromList [
synopsis = "parse a string to abstract syntax expression", synopsis = "parse a string to abstract syntax expression",
explanation = unlines [ explanation = unlines [
"Shows all trees returned by parsing a string in the grammars in scope.", "Shows all trees returned by parsing a string in the grammars in scope.",
"The -lang flag can be used to restrict this to one language.", "The -lang flag can be used to restrict this to fewer languages.",
"The default start category can be overridden by the -cat flag.", "The default start category can be overridden by the -cat flag.",
"See also the ps command for lexing and character encoding." "See also the ps command for lexing and character encoding."
], ],
exec = \opts -> return . fromTrees . concatMap (par opts) . toStrings, exec = \opts -> return . fromTrees . concatMap (par opts) . toStrings,
flags = [ flags = [
("cat","target category of parsing"), ("cat","target category of parsing"),
("lang","parsing language") ("lang","the languages of parsing (comma-separated, no spaces)")
] ]
}), }),
("pf", emptyCommandInfo {
longname = "print_fullform",
synopsis = "print the full-form lexicon of the actual grammar",
explanation = unlines [
"Prints all the strings in the actual grammar with their possible analyses"
],
exec = \opts _ ->
return $ fromString $ concatMap
(prFullFormLexicon . buildMorpho pgf . mkCId) $ optLangs opts
}),
("pg", emptyCommandInfo { ----- ("pg", emptyCommandInfo { -----
longname = "print_grammar", longname = "print_grammar",
synopsis = "print the actual grammar with the given printer", synopsis = "print the actual grammar with the given printer",
explanation = unlines [ explanation = unlines [
"Prints the actual grammar (overridden by the -lang=X flag).", "Prints the actual grammar, with all involved languages.",
"The -printer=X flag sets the format in which the grammar is printed.", "In some printers, this can be restricted to a subset of languages",
"with the -lang=X,Y flag (comma-separated, no spaces).",
"The -printer=P flag sets the format in which the grammar is printed.",
"N.B.1 Since grammars are compiled when imported, this command", "N.B.1 Since grammars are compiled when imported, this command",
"generally shows a grammar that looks rather different from the source.", "generally shows a grammar that looks rather different from the source.",
"N.B.2 This command is slightly obsolete: to produce different formats", "N.B.2 This command is slightly obsolete: to produce different formats",
@@ -278,11 +264,12 @@ allCommands pgf = Map.fromList [
exec = \opts _ -> return $ fromString $ prGrammar opts, exec = \opts _ -> return $ fromString $ prGrammar opts,
flags = [ flags = [
--"cat", --"cat",
("lang", "select language for the -missing option (default all languages)"), ("lang", "select languages for the some options (default all languages)"),
("printer","select the printing format (see gfc --help)") ("printer","select the printing format (see gfc --help)")
], ],
options = [ options = [
("cats", "show just the names of abstract syntax categories"), ("cats", "show just the names of abstract syntax categories"),
("fullform", "print the fullform lexicon"),
("missing","show just the names of functions that have no linearization") ("missing","show just the names of functions that have no linearization")
] ]
}), }),
@@ -346,21 +333,21 @@ allCommands pgf = Map.fromList [
explanation = unlines [ explanation = unlines [
"Reads input from file. The filename must be in double quotes.", "Reads input from file. The filename must be in double quotes.",
"The input is interpreted as a string by default, and can hence be", "The input is interpreted as a string by default, and can hence be",
"piped e.g. to the parse command. The option -term interprets the", "piped e.g. to the parse command. The option -tree interprets the",
"input as a term, which can be given e.g. to the linearize command.", "input as a tree, which can be given e.g. to the linearize command.",
"The option -lines will result in a list of strings or trees, one by line." "The option -lines will result in a list of strings or trees, one by line."
], ],
options = [ options = [
("lines","return the list of lines, instead of the singleton of all contents"), ("lines","return the list of lines, instead of the singleton of all contents"),
("term","convert strings into terms") ("tree","convert strings into trees")
], ],
exec = \opts arg -> do exec = \opts arg -> do
let file = valIdOpts "file" "_gftmp" opts let file = valIdOpts "file" "_gftmp" opts
s <- readFile file s <- readFile file
return $ case opts of return $ case opts of
_ | isOpt "lines" opts && isOpt "term" opts -> _ | isOpt "lines" opts && isOpt "tree" opts ->
fromTrees [t | l <- lines s, Just t <- [readExp l]] fromTrees [t | l <- lines s, Just t <- [readExp l]]
_ | isOpt "term" opts -> _ | isOpt "tree" opts ->
fromTrees [t | Just t <- [readExp s]] fromTrees [t | Just t <- [readExp s]]
_ | isOpt "lines" opts -> fromStrings $ lines s _ | isOpt "lines" opts -> fromStrings $ lines s
_ -> fromString s, _ -> fromString s,
@@ -399,8 +386,13 @@ allCommands pgf = Map.fromList [
synopsis = "send string or tree to a file", synopsis = "send string or tree to a file",
exec = \opts arg -> do exec = \opts arg -> do
let file = valIdOpts "file" "_gftmp" opts let file = valIdOpts "file" "_gftmp" opts
writeFile file (toString arg) if isOpt "append" opts
then appendFile file (toString arg)
else writeFile file (toString arg)
return void, return void,
options = [
("append","append to file, instead of overwriting it")
],
flags = [("file","the output filename")] flags = [("file","the output filename")]
}) })
] ]
@@ -429,7 +421,7 @@ allCommands pgf = Map.fromList [
optLangs opts = case valIdOpts "lang" "" opts of optLangs opts = case valIdOpts "lang" "" opts of
"" -> languages pgf "" -> languages pgf
lang -> [lang] lang -> chunks ',' lang
optLang opts = head $ optLangs opts ++ ["#NOLANG"] optLang opts = head $ optLangs opts ++ ["#NOLANG"]
optCat opts = valIdOpts "cat" (lookStartCat pgf) opts optCat opts = valIdOpts "cat" (lookStartCat pgf) opts
optNum opts = valIntOpts "number" 1 opts optNum opts = valIntOpts "number" 1 opts
@@ -443,6 +435,8 @@ allCommands pgf = Map.fromList [
prGrammar opts = case opts of prGrammar opts = case opts of
_ | isOpt "cats" opts -> unwords $ categories pgf _ | isOpt "cats" opts -> unwords $ categories pgf
_ | isOpt "fullform" opts -> concatMap
(prFullFormLexicon . buildMorpho pgf . mkCId) $ optLangs opts
_ | isOpt "missing" opts -> _ | isOpt "missing" opts ->
unlines $ [unwords (la:":": map prCId cs) | unlines $ [unwords (la:":": map prCId cs) |
la <- optLangs opts, let cs = missingLins pgf (mkCId la)] la <- optLangs opts, let cs = missingLins pgf (mkCId la)]