2:- ['ext/PrologWordNet/wn_s.pl']. 3:- ['ext/PrologWordNet/wn_hyp.pl']. 4:- ['ext/PrologWordNet/wn_ins.pl']. 5:- ['ext/PrologWordNet/wn_ant.pl']. 6
7:- use_module(library(lists),[member/2]). 8
12
13main:-
14 open('working/wordnet/isa.pl',write,Stream),
15 gen(Stream),
16 close(Stream).
17
18
22
23gen(Stream):-
24 member(POS,[n,v,a,r]), 25 s(ID,_,Token,POS,Sense,_),
26 synonyms(ID,POS,[]-Syn),
27 hypero(ID,POS,Hyp,Type),
28 antonyms(ID,POS,Ant),
29 print_rel(Stream,Token:Sense,Syn,Hyp,Ant,Type),
30 fail.
31
32gen(_).
33
34
38
39hypero(ID1,n,S,p):-
40 ins(ID1,ID2), !,
41 synonyms(ID2,n,[]-S).
42
43hypero(ID1,Pos,S,Pos):-
44 hyp(ID1,ID2), !,
45 synonyms(ID2,Pos,[]-S).
46
47hypero(_,Pos,[],Pos).
48
49
53
54antonyms(ID1,a,S):-
55 ant(ID1,1,ID2,1), !,
56 synonyms(ID2,a,[]-S).
57
58antonyms(_,_,[]).
59
60
64
65synonyms(ID,POS,L1-L2):-
66 synonyms(ID,1,POS,L1-L2).
67
68synonyms(ID,N,POS,L1-[Word1:Sense|L2]):-
69 s(ID,N,Word,POS,Sense,_), !,
70 symbol(Word,Word1),
71 M is N + 1,
72 synonyms(ID,M,POS,L1-L2).
73
74synonyms(_,_,_,L-L).
75
76
80
81print_rel(Stream,Concept,Syn,Hyp,Ant,Type):-
82 print_syn(Syn,Concept,Type,Stream),
83 print_hyp(Hyp,Concept,Type,Stream),
84 print_ant(Ant,Concept,Type,Stream).
85
86
90
91print_syn([],_,_,_).
92
93print_syn([Sym:Sense|L],Tok:Sense,Type,Stream):-
94 symbol(Tok,Sym), !,
95 print_syn(L,Tok:Sense,Type,Stream).
96
97print_syn([X:XS|L],Tok:Sense,Type,Stream):-
98 symbol(Tok,Sym),
99 format(Stream,'syn~p(~q,~q,~q,~q).~n',[Type,Sym,Sense,X,XS]),
100 print_syn(L,Tok:Sense,Type,Stream).
101
102
106
107print_hyp([],_,_,_).
108
109print_hyp([Sym:Sense|L],Tok:Sense,Type,Stream):-
110 symbol(Tok,Sym), !,
111 print_hyp(L,Tok:Sense,Type,Stream).
112
113print_hyp([X:XS|L],Tok:Sense,Type,Stream):-
114 symbol(Tok,Sym),
115 format(Stream,'isa~p(~q,~q,~q,~q).~n',[Type,Sym,Sense,X,XS]),
116 print_hyp(L,Tok:Sense,Type,Stream).
117
118
122
123print_ant([],_,_,_).
124
125print_ant([Sym:Sense|L],Tok:Sense,Type,Stream):-
126 symbol(Tok,Sym), !,
127 print_ant(L,Tok:Sense,Type,Stream).
128
129print_ant([X:XS|L],Tok:Sense,Type,Stream):-
130 symbol(Tok,Sym),
131 format(Stream,'isnota~p(~q,~q,~q,~q).~n',[Type,Sym,Sense,X,XS]),
132 print_ant(L,Tok:Sense,Type,Stream).
133
134
138
139symbol(F1,F2):-
140 name(F1,A1),
141 sym(A1,[A|A2]),
142 name(F2,[A|A2]), !.
143
144symbol(F,F).
145
146
150
151sym([],[]).
152
155sym([32|L1],[95|L2]):- !,
156 sym(L1,L2).
157
160sym([46|L1],L2):- !,
161 sym(L1,L2).
162
165sym([X|L1],[Y|L2]):-
166 X > 64, X < 91, !,
167 Y is X + 32,
168 sym(L1,L2).
169
170sym([X|L1],[X|L2]):-
171 sym(L1,L2).
172
173
177
178:- main, halt.