ENIAMplWordnet.ml
2.15 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
(*
* ENIAMlexSemantics is a library that assigns tokens with lexicosemantic information.
* Copyright (C) 2016-2017 Wojciech Jaworski <wjaworski atSPAMfree mimuw dot edu dot pl>
* Copyright (C) 2016-2017 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 Xstd
open ENIAMlexSemanticsTypes
let load_lu filename =
File.fold_tab filename IntMap.empty (fun lumap -> function
[lu_id; lemma; variant; syn_id] -> IntMap.add lumap (int_of_string lu_id) (lemma,variant,int_of_string syn_id)
| l -> failwith ("load_lu: " ^ String.concat "\t" l))
let load_syn filename =
File.fold_tab filename IntMap.empty (fun synmap -> function
syn_id :: pos :: lu_ids ->
let lu_ids = Xlist.map lu_ids int_of_string in
IntMap.add synmap (int_of_string syn_id) (pos,lu_ids)
| l -> failwith ("load_syn: " ^ String.concat "\t" l))
let load_ex_hipo filename =
File.fold_tab filename IntMap.empty (fun ex_hipo -> function
[parent; child; cost] ->
let parent = int_of_string parent in
let child = int_of_string child in
let cost = int_of_string cost in
let children = try IntMap.find ex_hipo parent with Not_found -> IntMap.empty in
let children = IntMap.add_inc children child cost (fun _ -> failwith "load_ex_hipo") in
IntMap.add ex_hipo parent children
| l -> failwith ("load_ex_hipo: " ^ String.concat "\t" l))
let lumap = load_lu lu_filename
let synmap = load_syn syn_filename
let ex_hipo = load_ex_hipo ex_hipo_filename