summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2015-11-17 09:11:10 +0000
committeraarne <aarne@chalmers.se>2015-11-17 09:11:10 +0000
commitd6a505169a06f89375dbb0d1ffc7f454f4b0aa9d (patch)
tree5d7adb6f467c1e4d01fbdd32a1813ea21955d013 /src/compiler
parent8a7254e4f9108593063c24b79d41726246eb4d6d (diff)
added -output=latex to visialize_dependencies. This generates more familiar-looking output than the default graphviz, which can moreover be pasted into LaTeX documents. Some more work is needed to make long sentences look nice and fit on a page; a constant word length is now used to simplify computing the coordinates.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/GF/Command/Commands.hs39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/compiler/GF/Command/Commands.hs b/src/compiler/GF/Command/Commands.hs
index bb696c135..6c843bb1b 100644
--- a/src/compiler/GF/Command/Commands.hs
+++ b/src/compiler/GF/Command/Commands.hs
@@ -530,6 +530,7 @@ pgfCommands = Map.fromList [
synopsis = "show word dependency tree graphically",
explanation = unlines [
"Prints a dependency tree in the .dot format (the graphviz format, default)",
+ "or LaTeX (flag -output=latex)",
"or the CoNLL/MaltParser format (flag -output=conll for training, malt_input",
"for unanalysed input).",
"By default, the last argument is the head of every abstract syntax",
@@ -550,15 +551,20 @@ pgfCommands = Map.fromList [
_ -> (Just . getDepLabels . lines) `fmap` restricted (readFile file)
let lang = optLang pgf opts
let grphs = map (graphvizDependencyTree outp debug mlab Nothing pgf lang) es
- if isFlag "view" opts || isFlag "format" opts
+ if isFlag "view" opts && valStrOpts "output" "" opts == "latex"
then do
- let view = optViewGraph opts
- let format = optViewFormat opts
- viewGraphviz view format "_grphd_" grphs
- else return $ fromString $ unlines grphs,
+ let view = optViewGraph opts
+ viewLatex view "_grphd_" grphs
+ else if isFlag "view" opts || isFlag "format" opts
+ then do
+ let view = optViewGraph opts
+ let format = optViewFormat opts
+ viewGraphviz view format "_grphd_" grphs
+ else return $ fromString $ unlines grphs,
examples = [
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 -output=latex -- generate a tree and display latex dependency tree on a Mac",
mkEx "gr -number=1000 | vd -file=dep.labels -output=conll -- generate training treebank",
mkEx "gr -number=100 | vd -file=dep.labels -output=malt_input -- generate test sentences"
],
@@ -961,3 +967,26 @@ viewGraphviz view format name grphs = do
--- restrictedSystem $ "rm " ++ file "*" "dot"
--- restrictedSystem $ "rm " ++ file "all" "pdf"
return void
+
+viewLatex :: String -> String -> [String] -> SIO CommandOutput
+viewLatex view name grphs = do
+ let texfile = name ++ ".tex"
+ let pdffile = name ++ ".pdf"
+ restricted $ writeUTF8File texfile (latexDoc grphs)
+ restrictedSystem $ "pdflatex " ++ texfile
+ restrictedSystem $ view ++ " " ++ pdffile
+ return void
+
+---- copied from VisualizeTree ; not sure about proper place AR Nov 2015
+latexDoc :: [String] -> String
+latexDoc body = unlines $
+ "\\batchmode"
+ : "\\documentclass{article}"
+ : "\\usepackage[utf8]{inputenc}"
+ : "\\begin{document}"
+ : spaces body
+ ++ ["\\end{document}"]
+ where
+ spaces = intersperse "\\vspace{6mm}"
+ ---- also reduce the size for long sentences
+ \ No newline at end of file