src/HOL/TPTP/TPTP_Parser/tptp_to_dot.ML
author haftmann
Thu, 01 May 2014 09:30:36 +0200
changeset 56812 baef1c110f12
parent 55594 eb291b215c73
child 57280 6907432c47b9
permissions -rw-r--r--
centralized upper/lowercase name mangling
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     1
(*  Title:      HOL/TPTP/TPTP_Parser/tptp_to_dot.ML
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     2
    Author:     Nik Sultana, Cambridge University Computer Laboratory
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     3
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     4
Translates parsed TPTP proofs into DOT format. This can then be processed
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     5
by an accompanying script to translate the proofs into other formats.
55586
c94f1a72d9c5 added more node shapes (matched with roles);
sultana
parents: 53389
diff changeset
     6
c94f1a72d9c5 added more node shapes (matched with roles);
sultana
parents: 53389
diff changeset
     7
It tries to adhere to the symbols used in IDV, as described in
c94f1a72d9c5 added more node shapes (matched with roles);
sultana
parents: 53389
diff changeset
     8
"An Interactive Derivation Viewer" by Trac & Puzis & Sutcliffe, UITP 2006.
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
     9
*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    10
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    11
signature TPTP_TO_DOT =
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    12
sig
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    13
  (*DOT-drawing function, works directly on parsed TPTP*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    14
  val tptp_dot_node : bool -> bool -> TPTP_Syntax.tptp_line -> string
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    15
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    16
  (*Parse a (LEO-II+E) proof and produce a DOT file*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    17
  val write_proof_dot : string -> string -> unit
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    18
end
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    19
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    20
structure TPTP_To_Dot : TPTP_TO_DOT =
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    21
struct
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    22
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    23
open TPTP_Syntax
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    24
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    25
datatype style =
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    26
    (*Only draw shapes. No formulas or edge labels.*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    27
    Shapes
55593
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    28
    (*Don't draw shapes. Only write formulas (as nodes) and inference names (as edge labels).*)
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    29
  | Formulas
55593
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    30
    (*Draw shapes and write the AF ID inside.*)
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    31
  | IDs
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    32
55594
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
    33
(*FIXME this kind of configurability isn't very user-friendly.
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
    34
  Ideally we'd accept a parameter from the tptp_graph script.*)
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    35
(*Determine the require output style form the TPTP_GRAPH environment variable.
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    36
  Shapes is the default style.*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    37
val required_style =
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    38
  if getenv "TPTP_GRAPH" = "formulas" then
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    39
    Formulas
55593
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    40
  else if getenv "TPTP_GRAPH" = "IDs" then
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    41
    IDs
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    42
  else Shapes
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    43
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    44
(*Draw an arc between two nodes*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    45
fun dot_arc reverse (src, label) target =
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    46
  let
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    47
    val edge_label =
55593
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
    48
      if required_style = Shapes orelse required_style = IDs then ""
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    49
      else
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    50
        case label of
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    51
                NONE => ""
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    52
              | SOME label => "[label=\"" ^ label ^ "\"];"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    53
  in
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    54
    "\"" ^ (if reverse then target else src) ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    55
    "\" -> \"" ^ (if reverse then src else target) ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    56
    "\" " ^ edge_label ^ "\n"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    57
  end
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    58
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    59
(*Node shapes indicate the role of the related clauses.*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    60
exception NO_ROLE_SHAPE
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    61
fun the_role_shape role =
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    62
  if role = Role_Fi_Domain orelse
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    63
     role = Role_Fi_Functors orelse
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    64
     role = Role_Fi_Predicates orelse
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    65
     role = Role_Type orelse
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    66
     role = Role_Unknown then
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    67
    raise NO_ROLE_SHAPE
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    68
  else if required_style = Formulas then "plaintext"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    69
  else
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    70
    case role of
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    71
      Role_Axiom => "triangle"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    72
    | Role_Hypothesis => "invtrapezium"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    73
    | Role_Definition => "invtriangle" (*NOTE this is not standard wrt IDV*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    74
    | Role_Assumption => "trapezium" (*NOTE this is not standard wrt IDV*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    75
    | Role_Lemma => "hexagon"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    76
    | Role_Theorem => "star" (*NOTE this is not standard wrt IDV*)
55590
14e8e51c7fa8 edges are now being shown in the proof graph;
sultana
parents: 55587
diff changeset
    77
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    78
    | Role_Conjecture => "house"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    79
    | Role_Negated_Conjecture => "invhouse"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
    80
    | Role_Plain => "circle"
55590
14e8e51c7fa8 edges are now being shown in the proof graph;
sultana
parents: 55587
diff changeset
    81
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    82
fun have_role_shape role =
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    83
  (the_role_shape role; true)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    84
  handle NO_ROLE_SHAPE => false
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    85
       | exc => raise exc
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    86
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    87
(*Different styles are applied to nodes relating to clauses written in
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    88
  difference languages.*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    89
exception NO_LANG_STYLE
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    90
fun the_lang_style lang =
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    91
  case lang of
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    92
      CNF => "dotted"
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    93
    | FOF => "dashed"
55594
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
    94
    | THF => "" (*NOTE could use "filled" to contrast with first-order languages*)
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    95
    | _ => raise NO_LANG_STYLE
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    96
55594
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
    97
(*Check if the formula just consists of "$false"?
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
    98
  which we interpret to be the last line of the proof.*)
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
    99
fun is_last_line CNF (Pred (Interpreted_Logic False, [])) = true
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   100
  | is_last_line THF (Atom (THF_Atom_term
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   101
      (Term_Func (Interpreted_Logic False, [])))) = true
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   102
  | is_last_line _ _ = false
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   103
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   104
fun tptp_dot_node with_label reverse_arrows
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   105
   (Annotated_Formula (_, lang, n, role, fmla_tptp, annot)) =
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   106
  let
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   107
    val node_label =
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   108
      if required_style = Formulas then
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   109
        "\", label=\"$" ^ TPTP_Syntax.latex_of_tptp_formula fmla_tptp ^ "$\"];\n"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   110
   (*FIXME  add a parameter to switch to using the following code, which lowers, centers, and horizontally-bounds the label.
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   111
           (this is useful if you want to keep the shapes but also show formulas)*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   112
   (*    "\", label=\"\\\\begin{minipage}{10cm}\\\\vspace{21mm}\\\\centering$" ^ TPTP_Syntax.latex_of_tptp_formula fmla_tptp ^ "$\\\\end{minipage}\"];\n") ^*)
55593
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
   113
      else if required_style = IDs then
c67c27f0ea94 improved configurability of DOT exporter;
sultana
parents: 55592
diff changeset
   114
        "\", label=\"" ^ n ^ "\"];\n"
55592
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   115
      else
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   116
        "\", label=\"\"];\n"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   117
 in
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   118
   (*don't expect to find 'Include' in proofs*)
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   119
   if have_role_shape role andalso role <> Role_Definition then
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   120
     "\"" ^ n ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   121
     "\" [shape=\"" ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   122
        (if is_last_line lang fmla_tptp then "doublecircle"
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   123
         else the_role_shape role) ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   124
     "\", style=\"" ^ the_lang_style lang ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   125
     node_label ^
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   126
     (case TPTP_Proof.extract_source_info annot of
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   127
          SOME (TPTP_Proof.Inference (rule, _, pinfos)) =>
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   128
            let
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   129
              fun parent_id (TPTP_Proof.Parent n) = n
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   130
                | parent_id (TPTP_Proof.ParentWithDetails (n, _)) = n
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   131
              val parent_ids = map parent_id pinfos
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   132
            in
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   133
              map
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   134
                (dot_arc reverse_arrows
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   135
                 (n, if with_label then SOME rule else NONE))
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   136
                parent_ids
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   137
              |> implode
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   138
            end
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   139
        | _ => "")
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   140
   else ""
37c1abaf4876 behaviour of tptp_graph now depends on an envir variable to indicate whether to produce proof graph containing formulas or not;
sultana
parents: 55591
diff changeset
   141
 end
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   142
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   143
(*FIXME add opts to label arcs etc*)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   144
fun write_proof_dot input_file output_file =
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   145
  let
55594
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
   146
    (*NOTE sometimes useful to include: rankdir=\"LR\";\n*)
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   147
    val defaults =
55587
5d3db2c626e3 experimenting with improving DOT output, and embedding LaTeX code for formulas (rather than only giving the clause number);
sultana
parents: 55586
diff changeset
   148
      "graph[nodesep=3];\n" ^
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   149
      "node[fixedsize=true];\n" ^
55587
5d3db2c626e3 experimenting with improving DOT output, and embedding LaTeX code for formulas (rather than only giving the clause number);
sultana
parents: 55586
diff changeset
   150
      "node[width=0.5];\n" ^
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   151
      "node[shape=plaintext];\n" ^
55594
eb291b215c73 cleaned code used to produce a proof-graph;
sultana
parents: 55593
diff changeset
   152
      (*NOTE sometimes useful to include: "node[fillcolor=lightgray];\n" ^ *)
55590
14e8e51c7fa8 edges are now being shown in the proof graph;
sultana
parents: 55587
diff changeset
   153
      "node[fontsize=50];\n"
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   154
  in
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   155
    TPTP_Parser.parse_file input_file
55587
5d3db2c626e3 experimenting with improving DOT output, and embedding LaTeX code for formulas (rather than only giving the clause number);
sultana
parents: 55586
diff changeset
   156
    |> map (tptp_dot_node true true)
47426
26c1a97c7784 standardized ML aliases;
wenzelm
parents: 47412
diff changeset
   157
    |> implode
47412
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   158
    |> (fn str => "digraph ProofGraph {\n" ^ defaults ^ str ^ "}")
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   159
    |> File.write (Path.explode output_file)
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   160
  end
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   161
aac1aa93f1ea added graph-conversion utility for TPTP files
sultana
parents:
diff changeset
   162
end