ENIAMsubsyntaxGraphOf.ml
1.57 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
(*
* ENIAMsubsyntax: MWE, abbreviation and sentence detecion for Polish
* Copyright (C) 2016 Wojciech Jaworski <wjaworski atSPAMfree mimuw dot edu dot pl>
* Copyright (C) 2016 Institute of Computer Science Polish Academy of Sciences
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
open ENIAMsubsyntaxTypes
open ENIAMtokenizerTypes
open Printf
let token_list tokens =
"digraph G {\n" ^
String.concat "\n" (List.rev (List.flatten (Xlist.rev_map tokens (fun t ->
let lemma = ENIAMtokens.get_lemma t.token in
if lemma = "" then [] else
[sprintf " %d -> %d [label=\"%s\\n%s\\n%s\"]" t.beg t.next t.orth lemma (ENIAMtokens.get_pos t.token)]))))
^ "}"
let print_token_list path name tokens =
File.file_out (path ^ name ^ ".gv") (fun file ->
fprintf file "%s\n" (token_list tokens));
Sys.chdir path;
ignore (Sys.command ("dot -Tpng " ^ name ^ ".gv -o " ^ name ^ ".png"));
String.iter (function '/' -> Sys.chdir ".." | _ -> ()) path