the visualization commands (aw,vd,vp,vt) can now show multiple trees. Previously they only showed one tree even if there were for instance after ambiguous parsing. The reason was that dot (graphviz) ignored all graphs but the first one. Now the graphs are put into separate files. The 'convert' command from ImageMagick package is used to combine them to one pdf. If this is a problem, the old behaviour can be restored by the -number=1 option to the tree-generating command, which cuts away all trees but the one and doesn't require ImageMagick.

This commit is contained in:
aarne
2015-11-05 16:47:41 +00:00
parent 456119e7e2
commit e1ca534f70

View File

@@ -57,9 +57,9 @@ pgfCommands = Map.fromList [
"Prints a set of strings in the .dot format (the graphviz format).", "Prints a set of strings in the .dot format (the graphviz format).",
"The graph can be saved in a file by the wf command as usual.", "The graph can be saved in a file by the wf command as usual.",
"If the -view flag is defined, the graph is saved in a temporary file", "If the -view flag is defined, the graph is saved in a temporary file",
"which is processed by graphviz and displayed by the program indicated", "which is processed by 'dot' (graphviz) and displayed by the program indicated",
"by the flag. The target format is postscript, unless overridden by the", "by the view flag. The target format is png, unless overridden by the",
"flag -format." "flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick)."
], ],
exec = getEnv $ \ opts es (Env pgf mos) -> do exec = getEnv $ \ opts es (Env pgf mos) -> do
let langs = optLangs pgf opts let langs = optLangs pgf opts
@@ -72,17 +72,13 @@ pgfCommands = Map.fromList [
let grph = if null es then [] else lsrc ++ "\n--end_source--\n\n"++ltrg++"\n-end_target--\n\n"++align let grph = if null es then [] else lsrc ++ "\n--end_source--\n\n"++ltrg++"\n-end_target--\n\n"++align
return $ fromString grph return $ fromString grph
else do else do
let grph = if null es then [] else graphvizAlignment pgf langs (head es) let grphs = map (graphvizAlignment pgf langs) es
if isFlag "view" opts || isFlag "format" opts if isFlag "view" opts || isFlag "format" opts
then do then do
let file s = "_grph." ++ s
let view = optViewGraph opts let view = optViewGraph opts
let format = optViewFormat opts let format = optViewFormat opts
restricted $ writeUTF8File (file "dot") grph viewGraphviz view format "_grpha_" grphs
restrictedSystem $ "dot -T" ++ format ++ " " ++ file "dot" ++ " > " ++ file format else return $ fromString $ unlines grphs,
restrictedSystem $ view ++ " " ++ file format
return void
else return $ fromString grph,
examples = [ examples = [
("gr | aw" , "generate a tree and show word alignment as graph script"), ("gr | aw" , "generate a tree and show word alignment as graph script"),
("gr | aw -view=\"open\"" , "generate a tree and display alignment on Mac"), ("gr | aw -view=\"open\"" , "generate a tree and display alignment on Mac"),
@@ -540,9 +536,9 @@ pgfCommands = Map.fromList [
"function; moreover, the head depends on the head of the function above.", "function; moreover, the head depends on the head of the function above.",
"The graph can be saved in a file by the wf command as usual.", "The graph can be saved in a file by the wf command as usual.",
"If the -view flag is defined, the graph is saved in a temporary file", "If the -view flag is defined, the graph is saved in a temporary file",
"which is processed by graphviz and displayed by the program indicated", "which is processed by dot (graphviz) and displayed by the program indicated",
"by the flag. The target format is png, unless overridden by the", "by the view flag. The target format is png, unless overridden by the",
"flag -format.", "flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).",
"See also 'vp -showdep' for another visualization of dependencies." "See also 'vp -showdep' for another visualization of dependencies."
], ],
exec = getEnv $ \ opts es (Env pgf mos) -> do exec = getEnv $ \ opts es (Env pgf mos) -> do
@@ -553,16 +549,13 @@ pgfCommands = Map.fromList [
"" -> return Nothing "" -> return Nothing
_ -> (Just . getDepLabels . lines) `fmap` restricted (readFile file) _ -> (Just . getDepLabels . lines) `fmap` restricted (readFile file)
let lang = optLang pgf opts let lang = optLang pgf opts
let grphs = unlines $ map (graphvizDependencyTree outp debug mlab Nothing pgf lang) es let grphs = map (graphvizDependencyTree outp debug mlab Nothing pgf lang) es
if isFlag "view" opts || isFlag "format" opts then do if isFlag "view" opts || isFlag "format" opts
let file s = "_grphd." ++ s then do
let view = optViewGraph opts let view = optViewGraph opts
let format = optViewFormat opts let format = optViewFormat opts
restricted $ writeUTF8File (file "dot") grphs viewGraphviz view format "_grphd_" grphs
restrictedSystem $ "dot -T" ++ format ++ " " ++ file "dot" ++ " > " ++ file format else return $ fromString $ unlines grphs,
restrictedSystem $ view ++ " " ++ file format
return void
else return $ fromString grphs,
examples = [ examples = [
mkEx "gr | vd -- generate a tree and show dependency tree in .dot", mkEx "gr | vd -- generate a tree and show dependency tree in .dot",
mkEx "gr | vd -view=open -- generate a tree and display dependency tree on a Mac", mkEx "gr | vd -view=open -- generate a tree and display dependency tree on a Mac",
@@ -589,9 +582,9 @@ pgfCommands = Map.fromList [
"Prints a parse tree in the .dot format (the graphviz format).", "Prints a parse tree in the .dot format (the graphviz format).",
"The graph can be saved in a file by the wf command as usual.", "The graph can be saved in a file by the wf command as usual.",
"If the -view flag is defined, the graph is saved in a temporary file", "If the -view flag is defined, the graph is saved in a temporary file",
"which is processed by graphviz and displayed by the program indicated", "which is processed by dot (graphviz) and displayed by the program indicated",
"by the flag. The target format is png, unless overridden by the", "by the view flag. The target format is png, unless overridden by the",
"flag -format." "flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick)."
], ],
exec = getEnv $ \ opts es (Env pgf mos) -> do exec = getEnv $ \ opts es (Env pgf mos) -> do
let lang = optLang pgf opts let lang = optLang pgf opts
@@ -610,19 +603,13 @@ pgfCommands = Map.fromList [
mlab <- case depfile of mlab <- case depfile of
"" -> return Nothing "" -> return Nothing
_ -> (Just . getDepLabels . lines) `fmap` restricted (readFile depfile) _ -> (Just . getDepLabels . lines) `fmap` restricted (readFile depfile)
let grphs = map (graphvizParseTreeDep mlab pgf lang gvOptions) es
let grph = if null es if isFlag "view" opts || isFlag "format" opts
then [] then do
else graphvizParseTreeDep mlab pgf lang gvOptions (head es) let view = optViewGraph opts
if isFlag "view" opts || isFlag "format" opts then do let format = optViewFormat opts
let file s = "_grph." ++ s viewGraphviz view format "_grphp_" grphs
let view = optViewGraph opts else return $ fromString $ unlines grphs,
let format = optViewFormat opts
restricted $ writeUTF8File (file "dot") grph
restrictedSystem $ "dot -T" ++ format ++ " " ++ file "dot" ++ " > " ++ file format
restrictedSystem $ view ++ " " ++ file format
return void
else return $ fromString grph,
examples = [ examples = [
mkEx "p \"John walks\" | vp -- generate a tree and show parse tree as .dot script", mkEx "p \"John walks\" | vp -- generate a tree and show parse tree as .dot script",
mkEx "gr | vp -view=open -- generate a tree and display parse tree on a Mac", mkEx "gr | vp -view=open -- generate a tree and display parse tree on a Mac",
@@ -659,9 +646,9 @@ pgfCommands = Map.fromList [
"Prints a set of trees in the .dot format (the graphviz format).", "Prints a set of trees in the .dot format (the graphviz format).",
"The graph can be saved in a file by the wf command as usual.", "The graph can be saved in a file by the wf command as usual.",
"If the -view flag is defined, the graph is saved in a temporary file", "If the -view flag is defined, the graph is saved in a temporary file",
"which is processed by graphviz and displayed by the program indicated", "which is processed by dot (graphviz) and displayed by the command indicated",
"by the flag. The target format is postscript, unless overridden by the", "by the view flag. The target format is postscript, unless overridden by the",
"flag -format.", "flag -format. Results from multiple trees are combined to pdf with convert (ImageMagick).",
"With option -mk, use for showing library style function names of form 'mkC'." "With option -mk, use for showing library style function names of form 'mkC'."
], ],
exec = getEnv $ \ opts es (Env pgf mos) -> exec = getEnv $ \ opts es (Env pgf mos) ->
@@ -675,16 +662,13 @@ pgfCommands = Map.fromList [
else do else do
let funs = not (isOpt "nofun" opts) let funs = not (isOpt "nofun" opts)
let cats = not (isOpt "nocat" opts) let cats = not (isOpt "nocat" opts)
let grph = unlines (map (graphvizAbstractTree pgf (funs,cats)) es) -- True=digraph let grphs = map (graphvizAbstractTree pgf (funs,cats)) es
if isFlag "view" opts || isFlag "format" opts then do if isFlag "view" opts || isFlag "format" opts
let file s = "_grph." ++ s then do
let view = optViewGraph opts let view = optViewGraph opts
let format = optViewFormat opts let format = optViewFormat opts
restricted $ writeUTF8File (file "dot") grph viewGraphviz view format "_grpht_" grphs
restrictedSystem $ "dot -T" ++ format ++ " " ++ file "dot" ++ " > " ++ file format else return $ fromString $ unlines grphs,
restrictedSystem $ view ++ " " ++ file format
return void
else return $ fromString grph,
examples = [ examples = [
mkEx "p \"hello\" | vt -- parse a string and show trees as graph script", mkEx "p \"hello\" | vt -- parse a string and show trees as graph script",
mkEx "p \"hello\" | vt -view=\"open\" -- parse a string and display trees on a Mac" mkEx "p \"hello\" | vt -view=\"open\" -- parse a string and display trees on a Mac"
@@ -961,3 +945,19 @@ prAllWords mo =
prMorphoAnalysis :: (String,[(Lemma,Analysis)]) -> String prMorphoAnalysis :: (String,[(Lemma,Analysis)]) -> String
prMorphoAnalysis (w,lps) = prMorphoAnalysis (w,lps) =
unlines (w:[showCId l ++ " : " ++ p | (l,p) <- lps]) unlines (w:[showCId l ++ " : " ++ p | (l,p) <- lps])
viewGraphviz :: String -> String -> String -> [String] -> SIO CommandOutput
viewGraphviz view format name grphs = do
let file i s = name ++ i ++ "." ++ s
mapM_ (\ (grph,i) -> restricted $ writeUTF8File (file (show i) "dot") grph) (zip grphs [1..])
mapM_ (\i -> restrictedSystem $ "dot -T" ++ format ++ " " ++ file (show i) "dot" ++ " > " ++ file (show i) format) [1..length grphs]
if length grphs > 1
then do
let files = unwords [file (show i) format | i <- [1..length grphs]]
restrictedSystem $ "convert " ++ files ++ " " ++ file "all" "pdf"
restrictedSystem $ view ++ " " ++ file "all" "pdf"
else restrictedSystem $ view ++ " " ++ file "1" format
--- restrictedSystem $ "rm " ++ file "*" format --- removing temporary files
--- restrictedSystem $ "rm " ++ file "*" "dot"
--- restrictedSystem $ "rm " ++ file "all" "pdf"
return void