XmlPrinter.ml
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
open Xstd
open WalTypes
open LCGtypes
let gf_of_string = function
"subj" -> SUBJ
| "obj" -> OBJ
| "arg"(*""*) -> ARG
| "core" -> CORE
| "nosem" -> NOSEM
| "nogf" -> NOGF
| "adjunct" -> ADJUNCT
| "raised" -> RAISED
| "clause" -> CLAUSE
| "sentence" -> SENTENCE
| s -> prerr_endline s; SUBJ
(* | s -> failwith ("gf_of_string:" ^ s) *)
(*let morf_of_string s =
let s = Str.split (Str.regexp "[()]") s in
WalParser.parse_morf_single (List.hd s, List.tl s)*)
let rec lt_of_xml = function
Xml.Element("node",["pred",pred;"cat",cat;"weight",weight;"id",id],[
Xml.Element("gs",[],[gs]);
Xml.Element("agf",[],[Xml.PCData agf]);
Xml.Element("amorf",[],[amorf]);
Xml.Element("attrs",[],attrs);
Xml.Element("args",[],[args])]) ->
Node{pred=pred; cat=cat; weight=float_of_string weight; id=int_of_string id;
gs = lt_of_xml gs;
agf = gf_of_string agf; (* FIXME *)
amorf = WalTypes.Phrase(WalTypes.Null); (* FIXME *)
arole = ""; (* FIXME *)
arole_attr = ""; (* FIXME *)
meaning = ""; (* FIXME *)
hipero = StringSet.empty; (* FIXME *)
meaning_weight = -1.; (* FIXME *)
position = WalTypes.{gf = WalTypes.SUBJ; role = ""; role_attr = ""; sel_prefs = [];
cr = []; ce = []; dir = WalTypes.Both; morfs = []}; (* FIXME *)
attrs=List.map (function Xml.Element("attr",["label",e],[t]) -> e,lt_of_xml t | _ -> failwith "lt_of_xml") attrs;
args=lt_of_xml args;}
| Xml.Element("tuple",[],l) -> Tuple(List.map lt_of_xml l)
| Xml.Element("val",[],[Xml.PCData s]) -> Val s
| Xml.Element("variants",["label",e],l) -> Variant(e,List.map (function Xml.Element("variant",["id",i],[t]) -> i, lt_of_xml t | _ -> failwith "lt_of_xml") l)
| Xml.Element("dot",[],[]) -> Dot
| Xml.Element("ref",["id",i],[]) -> Ref(int_of_string i)
| xml -> print_endline (Xml.to_string_fmt xml); failwith "lt_of_xml"
let graph_of_xml = function
Xml.Element("graph",[],l) ->
List.map (function Xml.Element("graph_node",["id",i],[xml]) -> (*int_of_string i,*) lt_of_xml xml | _ -> failwith "graph_of_xml") l
| _ -> failwith "graph_of_xml"
let print_xml path name xml =
let graph = Array.of_list @@ graph_of_xml xml in
Visualization.print_graph path name graph
let load_and_print_xml path name filename =
print_xml path name @@ Xml.parse_file filename
(*let _ =
load_and_print_xml "xml_test/" "test1.0" "xml_test/sentence1.0.xml"*)