src/HOL/TPTP/TPTP_Parser/tptp_to_dot.ML
changeset 55587 5d3db2c626e3
parent 55586 c94f1a72d9c5
child 55590 14e8e51c7fa8
equal deleted inserted replaced
55586:c94f1a72d9c5 55587:5d3db2c626e3
    40   | Role_Assumption => "trapezium" (*NOTE this is not standard wrt IDV*)
    40   | Role_Assumption => "trapezium" (*NOTE this is not standard wrt IDV*)
    41   | Role_Lemma => "hexagon"
    41   | Role_Lemma => "hexagon"
    42   | Role_Theorem => "star" (*NOTE this is not standard wrt IDV*)
    42   | Role_Theorem => "star" (*NOTE this is not standard wrt IDV*)
    43   | Role_Conjecture => "house"
    43   | Role_Conjecture => "house"
    44   | Role_Negated_Conjecture => "invhouse"
    44   | Role_Negated_Conjecture => "invhouse"
    45   | Role_Plain => "circle"
    45   | Role_Plain => "plaintext" (* "circle" *) (*could also use none*)
    46   | Role_Fi_Domain => raise NO_ROLE_SHAPE
    46   | Role_Fi_Domain => raise NO_ROLE_SHAPE
    47   | Role_Fi_Functors => raise NO_ROLE_SHAPE
    47   | Role_Fi_Functors => raise NO_ROLE_SHAPE
    48   | Role_Fi_Predicates => raise NO_ROLE_SHAPE
    48   | Role_Fi_Predicates => raise NO_ROLE_SHAPE
    49   | Role_Type => raise NO_ROLE_SHAPE
    49   | Role_Type => raise NO_ROLE_SHAPE
    50   | Role_Unknown => raise NO_ROLE_SHAPE
    50   | Role_Unknown => raise NO_ROLE_SHAPE
    59 exception NO_LANG_STYLE
    59 exception NO_LANG_STYLE
    60 fun the_lang_style lang =
    60 fun the_lang_style lang =
    61   case lang of
    61   case lang of
    62       CNF => "dotted"
    62       CNF => "dotted"
    63     | FOF => "dashed"
    63     | FOF => "dashed"
    64     | THF => "filled"
    64     | THF => "" (* "filled" *)
    65     | _ => raise NO_LANG_STYLE
    65     | _ => raise NO_LANG_STYLE
    66 
    66 
    67 (*Does the formula just consist of "$false"?*)
    67 (*Does the formula just consist of "$false"?*)
    68 fun is_last_line CNF (Pred (Interpreted_Logic False, [])) = true
    68 fun is_last_line CNF (Pred (Interpreted_Logic False, [])) = true
    69   | is_last_line THF (Atom (THF_Atom_term
    69   | is_last_line THF (Atom (THF_Atom_term
    71   | is_last_line _ _ = false
    71   | is_last_line _ _ = false
    72 
    72 
    73 fun tptp_dot_node with_label reverse_arrows
    73 fun tptp_dot_node with_label reverse_arrows
    74  (Annotated_Formula (_, lang, n, role, fmla_tptp, annot)) =
    74  (Annotated_Formula (_, lang, n, role, fmla_tptp, annot)) =
    75  (*don't expect to find 'Include' in proofs*)
    75  (*don't expect to find 'Include' in proofs*)
    76  if have_role_shape role then
    76  if have_role_shape role andalso role <> Role_Definition then
    77    "\"" ^ n ^
    77    "\"" ^ n ^
    78    "\" [shape=\"" ^
    78    "\" [shape=\"" ^
    79       (if is_last_line lang fmla_tptp then "doublecircle"
    79       (if is_last_line lang fmla_tptp then "doublecircle"
    80        else the_role_shape role) ^
    80        else the_role_shape role) ^
    81    "\", style=\"" ^ the_lang_style lang ^
    81    "\", style=\"" ^ the_lang_style lang ^
    82    "\", label=\"" ^ n ^ "\"];\n" ^
    82    (if role = Role_Definition then "\"];\n" else
       
    83      "\", label=\"$" ^ TPTP_Syntax.latex_of_tptp_formula fmla_tptp ^ "$\"];\n") ^
    83    (case TPTP_Proof.extract_source_info annot of
    84    (case TPTP_Proof.extract_source_info annot of
    84         SOME (TPTP_Proof.Inference (rule, _, pinfos)) =>
    85         SOME (TPTP_Proof.Inference (rule, _, pinfos)) =>
    85           let
    86           let
    86             fun parent_id (TPTP_Proof.Parent n) = n
    87             fun parent_id (TPTP_Proof.Parent n) = n
    87               | parent_id (TPTP_Proof.ParentWithDetails (n, _)) = n
    88               | parent_id (TPTP_Proof.ParentWithDetails (n, _)) = n
    99 (*FIXME add opts to label arcs etc*)
   100 (*FIXME add opts to label arcs etc*)
   100 fun write_proof_dot input_file output_file =
   101 fun write_proof_dot input_file output_file =
   101   let
   102   let
   102     (*rankdir=\"LR\";\n*)
   103     (*rankdir=\"LR\";\n*)
   103     val defaults =
   104     val defaults =
       
   105       "graph[nodesep=3];\n" ^
   104       "node[fixedsize=true];\n" ^
   106       "node[fixedsize=true];\n" ^
   105       "node[width=.5];\n" ^
   107       "node[width=0.5];\n" ^
   106       "node[shape=plaintext];\n" ^
   108       "node[shape=plaintext];\n" ^
   107       "node[fillcolor=lightgray];\n" ^
   109       (* "node[fillcolor=lightgray];\n" ^ *)
   108       "node[fontsize=40];\n" ^
   110       "node[fontsize=50];\n" ^
   109       "edge[dir=none];\n"
   111       "edge[dir=none];\n"
   110   in
   112   in
   111     TPTP_Parser.parse_file input_file
   113     TPTP_Parser.parse_file input_file
   112     |> map (tptp_dot_node false true)
   114     |> map (tptp_dot_node true true)
   113     |> implode
   115     |> implode
   114     |> (fn str => "digraph ProofGraph {\n" ^ defaults ^ str ^ "}")
   116     |> (fn str => "digraph ProofGraph {\n" ^ defaults ^ str ^ "}")
   115     |> File.write (Path.explode output_file)
   117     |> File.write (Path.explode output_file)
   116   end
   118   end
   117 
   119