-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwn2csv.pl
More file actions
92 lines (77 loc) · 2.15 KB
/
wn2csv.pl
File metadata and controls
92 lines (77 loc) · 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/* -----------------------------------------------------------------
wn2csv.pl
Convert all WordNet databases to comma-separated CSV files
SPDX-FileCopyrightText: 2017-26 Eric Kafe <kafe@megadoc.net>
SPDX-License-Identifier: Apache-2.0
Licensed under the Apache License, Version 2.0
----------------------------------------------------------------- */
:- include(loader).
escape_codes([], []).
escape_codes([H|T], O):-
(
H = 34 % repeat double quote (RFC 4180)
-> O = [34,34|R]
; O = [H|R]
),
escape_codes(T, R).
escape_double_quotes(S, Escaped):-
atom_codes(S, Codes),
escape_codes(Codes, EscapedCodes),
atom_codes(Escaped, EscapedCodes).
escape_index(exc, 2). % Word form
escape_index(exc, 3). % Lemma
escape_index(g, 2). % Gloss
escape_index(s, 3). % Lemma
escape_index(sk, 3). % Sense key
handle_index(P, N, S):-
escape_index(P,N)
-> escape_double_quotes(S, S1),
format('"~w"', [S1]) % double quote string
; format('~w', [S]).
args2csv([H|T], P, N) :-
handle_index(P, N, H),
(
T \= []
-> write(','),
N1 is N+1,
args2csv(T, P, N1)
; write('\r\n') % The CSV standard requires CRLF
).
%---------------------------------------------------------
spdx:-
write('# SPDX-License-Identifier: WordNet'),
wn_version(V),
atom_chars(V, [H,_,N|_]),
( H=='O' -> write(' AND CC-BY-4.0'); true ), nl,
write('# SPDX-FileCopyrightText: '),
( N=='0' -> write('2006'); write('2011') ),
format(' Princeton University~n'),
( H=='O' -> format('# SPDX-FileCopyrightText: 2025 Open English Wordnet Community~n'); true ),
write('# -----------------------------------------------------------'), nl.
pred2file(P):-
atom_concat('csv/wn_',P,C1),
atom_concat(C1,'.csv',C),
format('Writing ~w~n',[C]),
tell(C),
spdx.
out2csv(P):-
pred2file(P),
current_predicate(P/A),
dispatch_call(A,P,L),
args2csv(L,P,1),
false.
out2csv(_):-
told.
convert_wn:-
allwn(L),
member(P,L),
ensure_pred(P),
out2csv(P),
false.
convert_wn.
inicsv:-
safe_consult(wn_load),
load_wn,
% loaded all dbs first, to time the conversion independently of consulting:
time_call(convert_wn).
:- initialization(inicsv).