src/Tools/isac/BridgeLibisabelle/pbl-met-hierarchy.sml
author wneuper <Walther.Neuper@jku.at>
Fri, 06 Jan 2023 08:04:36 +0100
changeset 60631 d5a69b98afc3
parent 60628 f54e20d9e6ee
child 60633 6981dcb77cdc
permissions -rw-r--r--
eliminate thy-hierarchy 1: Error_Pattern.fill_from_store independent from..
walther@60257
     1
(* ~/src/Tools/isac/BridgeLibisabelle/pbl-met-hierarchy.sml
wneuper@59250
     2
   author: Walther Neuper 2004
neuper@37906
     3
   (c) isac-team
walther@60257
     4
walther@60257
     5
Create XML for the tree structure of problem-patterns and methods.
walther@60257
     6
This is kept as a model for some browsing facility, which is required
walther@60257
     7
in parallel to PIDE, because these structures are different
walther@60257
     8
from the dependency graph of Isabelle's theories.
neuper@37906
     9
*)
walther@59918
    10
signature PROBLEM_METHOD_HIERARCHY =
walther@59918
    11
sig
walther@59918
    12
  eqtype filepath
walther@60258
    13
  eqtype filename
walther@60258
    14
  type xml
walther@60277
    15
  val pbl_hierarchy2file : filepath -> filepath * string
walther@60277
    16
  val met_hierarchy2file : filepath -> filepath * string
Walther@60628
    17
  val pbl_hierarchy2file_test : filepath -> filepath * string
Walther@60628
    18
  val met_hierarchy2file_test : filepath -> filepath * string
Walther@60631
    19
  val update_metpair: theory -> MethodC.id -> Error_Pattern.T list -> MethodC.T * MethodC.id
walther@59918
    20
end
neuper@37906
    21
walther@59918
    22
(**)
walther@60258
    23
structure Pbl_Met_Hierarchy(**): PROBLEM_METHOD_HIERARCHY(*AUTHOR*) =
walther@59918
    24
struct
walther@59918
    25
(**)
walther@59918
    26
walther@60258
    27
type filepath = string;
walther@60258
    28
type filename = string;
walther@59971
    29
walther@60258
    30
type xml = string; (* rm together with old code replaced by XML.tree *)
walther@60258
    31
val indentation = 2;
walther@60258
    32
fun hierarchy_pbl h =
walther@60258
    33
  let
walther@60258
    34
    val j = indentation
walther@60258
    35
    fun nd i p (Store.Node (id,[{guh,...} : Problem.T],ns)) = 
walther@60258
    36
        let val p' = Pos.lev_on p
walther@60258
    37
        in (indt i) ^ "<NODE>\n" ^ 
walther@60258
    38
           (indt (i+j)) ^ "<ID> " ^ id ^ " </ID>\n" ^ 
walther@60258
    39
           (indt (i+j)) ^ "<NO> " (*on this level*) ^ 
walther@60258
    40
           (string_of_int o last_elem) p' ^ " </NO>\n" ^ 
walther@60258
    41
           (indt (i+j)) ^ "<CONTENTREF> " ^ guh ^ 
walther@60258
    42
           " </CONTENTREF>\n" ^
walther@60258
    43
           (nds (i+j) (Pos.lev_dn p') ns) ^ 
walther@60258
    44
           (indt i) ^ "</NODE>\n"
walther@60258
    45
        end
walther@60258
    46
      | nd _ _ _ = raise ERROR "hierarchy_pbl"
walther@60258
    47
    and nds _ _ [] = "" 
walther@60258
    48
      | nds i p (n::ns) = (nd i p n) ^ (nds i (Pos.lev_on p) ns);
walther@60258
    49
  in nds j [0] h : xml end;
walther@59918
    50
walther@60258
    51
fun hierarchy_met h =
walther@60258
    52
  let
walther@60258
    53
    val j = indentation
walther@60258
    54
	  fun nd i p (Store.Node (id,[{guh,...} : MethodC.T],ns)) = 
walther@60258
    55
  	    let val p' = Pos.lev_on p
walther@60258
    56
  	    in (indt i) ^ "<NODE>\n" ^ 
walther@60258
    57
  	       (indt (i+j)) ^ "<ID> " ^ id ^ " </ID>\n" ^ 
walther@60258
    58
  	       (indt (i+j)) ^ "<NO> " (*on this level*) ^ 
walther@60258
    59
  	       (string_of_int o last_elem) p' ^ " </NO>\n" ^ 
walther@60258
    60
  	       (indt (i+j)) ^ "<CONTENTREF> " ^ guh ^ 
walther@60258
    61
  	       " </CONTENTREF>\n" ^
walther@60258
    62
  	       (nds (i+j) (Pos.lev_dn p') ns) ^ 
walther@60258
    63
  	       (indt i) ^ "</NODE>\n"
walther@60258
    64
  	    end
walther@60258
    65
      | nd _ _ _ = raise ERROR "hierarchy_met"
walther@60258
    66
	  and nds _ _ [] = ""
walther@60258
    67
	    | nds i p (n::ns) = (nd i p n) ^ (nds i (Pos.lev_on p) ns);
walther@60258
    68
  in nds j [0] h  : xml end;
neuper@55490
    69
walther@60277
    70
(*
walther@60258
    71
fun str2file (fnm : filename) (str : string) =
neuper@55490
    72
  let val file = TextIO.openOut fnm
neuper@55490
    73
  in 
neuper@55490
    74
    TextIO.output (file, str);
neuper@55490
    75
    TextIO.flushOut file;
neuper@55490
    76
    TextIO.closeOut file
neuper@55490
    77
  end
walther@60277
    78
*)
Walther@60628
    79
(* files *all* problems addressed by the context of the test run *)
walther@59918
    80
fun pbl_hierarchy2file path = 
walther@60277
    81
    (*str2file*) (path ^ "pbl_hierarchy.xml" : filepath,
walther@60277
    82
	      "<NODE>\n" ^
neuper@37906
    83
	      "  <ID> problem hierarchy </ID>\n" ^
neuper@37906
    84
	      "  <NO> 1 </NO>\n" ^
neuper@37906
    85
	      "  <CONTENTREF> pbl_ROOT </CONTENTREF>\n" ^
Walther@60495
    86
	     (hierarchy_pbl (get_pbls ())) ^
neuper@37906
    87
	     "</NODE>");
Walther@60628
    88
(* some tests extend the hierarchy_pbl, but these shall not be shown *)
Walther@60628
    89
fun pbl_hierarchy2file_test path = 
Walther@60628
    90
    (*str2file*) (path ^ "pbl_hierarchy.xml" : filepath,
Walther@60628
    91
	      "<NODE>\n" ^
Walther@60628
    92
	      "  <ID> problem hierarchy </ID>\n" ^
Walther@60628
    93
	      "  <NO> 1 </NO>\n" ^
Walther@60628
    94
	      "  <CONTENTREF> pbl_ROOT </CONTENTREF>\n" ^
Walther@60628
    95
	     ("Isac_Knowledge" |> Know_Store.get_via_last_thy |> Know_Store.get_pbls |> hierarchy_pbl) ^
Walther@60628
    96
	     "</NODE>");
Walther@60628
    97
(* files *all* methods addressed by the context of the test run *)
walther@59918
    98
fun met_hierarchy2file path = 
walther@60277
    99
    (*str2file*) (path ^ "met_hierarchy.xml" : filepath,
walther@60277
   100
	      "<NODE>\n" ^
neuper@37906
   101
	      "  <ID> method hierarchy </ID>\n" ^
neuper@37906
   102
	      "  <NO> 1 </NO>\n" ^
neuper@37906
   103
	      "  <CONTENTREF> met_ROOT </CONTENTREF>\n" ^
s1210629013@55372
   104
	     (hierarchy_met (get_mets ())) ^
neuper@37906
   105
	     "</NODE>");
Walther@60628
   106
(* some tests extend the hierarchy_met, but these shall not be shown *)
Walther@60628
   107
fun met_hierarchy2file_test path = 
Walther@60628
   108
    (*str2file*) (path ^ "met_hierarchy.xml" : filepath,
Walther@60628
   109
	      "<NODE>\n" ^
Walther@60628
   110
	      "  <ID> method hierarchy </ID>\n" ^
Walther@60628
   111
	      "  <NO> 1 </NO>\n" ^
Walther@60628
   112
	      "  <CONTENTREF> met_ROOT </CONTENTREF>\n" ^
Walther@60628
   113
	     ("Isac_Knowledge" |> Know_Store.get_via_last_thy |> Know_Store.get_mets |> hierarchy_met) ^
Walther@60628
   114
	     "</NODE>");
neuper@37906
   115
neuper@37906
   116
neuper@42452
   117
fun update_metdata
Walther@60631
   118
  ({guh, mathauthors, start_refine, rew_ord, asm_rls, prog_rls, where_rls, rew_rls, calc, model,
Walther@60631
   119
      where_, program, ...}: MethodC.T) errpats' =
Walther@60631
   120
  {guh = guh, mathauthors = mathauthors, start_refine = start_refine, rew_ord = rew_ord,
Walther@60631
   121
    asm_rls = asm_rls, prog_rls = prog_rls, where_rls = where_rls, rew_rls = rew_rls, calc = calc,
Walther@60586
   122
    model = model, where_ = where_, program = program, errpats = errpats'}: MethodC.T
neuper@42452
   123
neuper@55381
   124
(* interface for dialog-authoring: call in Buld_Thydata.thy only ! *)
Walther@60631
   125
fun update_metpair thy metID errpats =
Walther@60631
   126
  let
Walther@60631
   127
    val ret = (update_metdata (MethodC.from_store' thy metID) errpats, metID)
Walther@60631
   128
      handle ERROR _ => raise ERROR ("update_metpair: " ^ strs2str metID ^ " must address a method");
Walther@60631
   129
  in ret end;
walther@59918
   130
walther@59918
   131
(**)end(**)