|
1
|
(*
|
|
2
3
4
|
* ENIAMwalenty, a converter for Polish Valence Dictionary "Walenty".
* 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
|
|
5
|
*
|
|
6
7
|
* 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
|
|
8
9
10
|
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
|
|
11
|
* This library is distributed in the hope that it will be useful,
|
|
12
13
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
* GNU Lesser General Public License for more details.
|
|
15
|
*
|
|
16
|
* You should have received a copy of the GNU Lesser General Public License
|
|
17
18
19
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*)
|
|
20
|
open ENIAMwalTypes
|
|
21
|
|
|
22
|
let opinion = function
|
|
23
24
25
26
27
28
|
Pewny -> "cer"
| Potoczny -> "col"
| Watpliwy -> "unc"
| Archaiczny -> "dat"
| Zly -> "bad"
| Wulgarny -> "vul"
|
|
29
30
|
| Dziedzinowy -> "dom"
| Nieokreslony -> "unk"
|
|
31
|
| Metaforyczny -> "met"
|
|
32
33
|
| Sporadyczny -> "rar"
| OpinionUndef -> failwith "ENIAMwalStringOf.opinion"
|
|
34
|
|
|
35
36
37
38
39
|
let negation = function
Negation -> "neg"
| Aff -> "aff"
| NegationUndef -> "_"
| NegationNA -> ""
|
|
40
|
|
|
41
|
let pred = function
|
|
42
|
PredNA -> ""
|
|
43
44
45
|
| PredTrue -> "pred"
| PredFalse -> "nopred"
| PredUndef -> "_"
|
|
46
|
|
|
47
48
49
50
|
let aspect = function
Aspect s -> s
| AspectUndef -> "_"
| AspectNA -> ""
|
|
51
|
|
|
52
53
54
55
56
57
58
59
60
61
62
63
|
let case = function
Case s -> s
| Str -> "str"
| Part -> "part"
| CaseAgr -> "agr"
| CaseUAgr -> "uagr"
| NomAgr -> "nomagr"
| GenAgr -> "genagr"
| AllAgr -> "allagr"
| AllUAgr -> "alluagr"
| CaseUndef -> "_"
|
|
64
|
let rec comp = function
|
|
65
66
67
68
69
70
71
72
73
|
Comp s -> s
| Zeby -> "ĹĽeby2"
| Gdy -> "gdy"
| CompUndef -> "_"
let rec comp_type = function
Int -> "int"
| Rel -> "rel"
| CompTypeUndef -> "_"
|
|
74
|
|
|
75
76
77
78
|
let number = function
Number s -> s
| NumberAgr -> "agr"
| NumberUndef -> "_"
|
|
79
|
|
|
80
81
82
83
84
|
let gender = function
Gender s -> s
| GenderUndef -> "_"
| GenderAgr -> "agr"
| Genders l -> String.concat "." l
|
|
85
|
|
|
86
87
88
|
let grad = function
Grad s -> s
| GradUndef -> "_"
|
|
89
|
|
|
90
91
|
let refl = function
ReflEmpty -> ""
|
|
92
93
94
|
| ReflTrue -> "siÄ™"
| ReflFalse -> "nosiÄ™"
| ReflUndef -> "_"
|
|
95
|
|
|
96
|
(* let acm = function
|
|
97
|
Acm s -> s
|
|
98
|
| AcmUndef -> "_" *)
|
|
99
|
|
|
100
101
102
103
|
let gf = function
SUBJ -> "subj"
| OBJ -> "obj"
| ARG -> "arg"(*""*)
|
|
104
|
|
|
105
106
|
let pos = function
SUBST(n,c) -> "SUBST(" ^ number n ^ "," ^ case c ^ ")"
|
|
107
108
109
|
| PPRON12(n,c) -> "PPRON12(" ^ number n ^ "," ^ case c ^ ")"
| PPRON3(n,c) -> "PPRON3(" ^ number n ^ "," ^ case c ^ ")"
| SIEBIE(c) -> "SIEBIE(" ^ case c ^ ")"
|
|
110
|
| PREP(c) -> "PREP(" ^ case c ^ ")"
|
|
111
|
| NUM(c,g) -> "NUM(" ^ case c ^ "," ^ gender g ^ (*"," ^ acm a ^*) ")"
|
|
112
113
|
| ADJ(n,c,g,gr) -> "ADJ(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ grad gr ^ ")"
| ADV(gr) -> "ADV(" ^ grad gr ^ ")"
|
|
114
115
|
| GER(n,c,g,a,neg) -> "GER(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ aspect a ^ "," ^ negation neg (*^ "," ^ refl r*) ^ ")"
| PACT(n,c,g,a,neg) -> "PACT(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ aspect a ^ "," ^ negation neg (*^ "," ^ refl r*) ^ ")"
|
|
116
|
| PPAS(n,c,g,a,neg) -> "PPAS(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ aspect a ^ "," ^ negation neg ^ ")"
|
|
117
|
| INF(a,n) -> "INF(" ^ aspect a ^ "," ^ negation n (*^ "," ^ refl r*) ^ ")"
|
|
118
119
120
|
| QUB -> "QUB"
| COMPAR -> "COMPAR"
| COMP(c) -> "COMP(" ^ comp_type c ^ ")"
|
|
121
|
| PERS(n) -> "PERS(" ^ negation n ^ (*"," ^ refl r ^*) ")"
|
|
122
|
| FIXED -> "FIXED"
|
|
123
|
|
|
124
125
|
let phrase = function
NP c -> "np(" ^ case c ^ ")"
|
|
126
|
| PrepNP(prep,c) -> "prepnp(" ^ prep ^ "," ^ case c ^ ")"
|
|
127
|
| AdjP c -> "adjp(" ^ case c ^ ")"
|
|
128
|
| PrepAdjP(prep,c) -> "prepadjp(" ^ prep ^ "," ^ case c ^ ")"
|
|
129
|
| NumP(c) -> "nump(" ^ case c ^ ")"
|
|
130
131
|
| PrepNumP(prep,c) -> "prepnump(" ^ prep ^ "," ^ case c ^ ")"
| ComprepNP(prep) -> "comprepnp(" ^ prep ^ ")"
|
|
132
|
| ComparP(prep) -> "comparp(" ^ prep ^ ")"
|
|
133
134
|
| CP(ct,co) -> "cp(" ^ comp_type ct ^ "," ^ comp co ^ ")"
| NCP(c,ct,co) -> "ncp(" ^ case c ^ "," ^ comp_type ct ^ "," ^ comp co ^ ")"
|
|
135
136
|
| PrepNCP(prep,c,ct,co) -> "prepncp(" ^ prep ^ "," ^ case c ^ "," ^ comp_type ct ^ "," ^ comp co ^ ")"
| InfP(a) -> "infp(" ^ aspect a (*^ req r*) ^ ")"
|
|
137
|
| AdvP m -> "advp(" ^ m ^ ")"
|
|
138
|
| FixedP s -> "fixed(" ^ s ^ ")"
|
|
139
|
(* | Num(c,a) -> "num(" ^ case c ^ "," ^ acm a ^ ")" *)
|
|
140
141
|
| Or -> "or"
| Qub -> "qub"
|
|
142
143
|
(* | Pro -> "pro"
| ProNG -> "prong" *)
|
|
144
|
| Null -> "null"
|
|
145
146
147
148
149
150
|
| GerP c -> "gerp(" ^ case c ^ ")"
| PrepGerP(prep,c) -> "prepgerp(" ^ prep ^ "," ^ case c ^ ")"
| PpasP c -> "ppasp(" ^ case c ^ ")"
| PrepPpasP(prep,c) -> "prepppasp(" ^ prep ^ "," ^ case c ^ ")"
| PactP c -> "pactp(" ^ case c ^ ")"
|
|
151
|
|
|
152
153
154
155
156
|
let phrase_abbr = function
Xp(m) -> "xp(" ^ m ^ ")"
| Nonch -> "nonch"
| Distrp -> "distrp"
| Possp -> "possp"
|
|
157
|
|
|
158
159
160
161
|
let phrase_comp = function
Cp -> "cp"
| Ncp(c) -> "ncp(" ^ case c ^ ")"
| Prepncp(prep,c) -> "prepncp(" ^ prep ^ "," ^ case c ^ ")"
|
|
162
|
|
|
163
164
165
166
167
168
|
let rec lex = function
Lexeme s -> "'" ^ s ^ "'"
| ORconcat l -> "OR(" ^ String.concat "," (Xlist.map l lex) ^ ")"
| ORcoord l -> "OR(" ^ String.concat ";" (Xlist.map l lex) ^ ")"
| XOR l -> "XOR(" ^ String.concat "," (Xlist.map l lex) ^ ")"
| Elexeme g -> "'E(" ^ gender g ^ ")"
|
|
169
170
|
let restr = function
|
|
171
172
173
174
175
176
|
Natr -> "natr"
| Atr -> "atr"
| Ratr -> "ratr"
| Ratrs -> "ratrs"
| Atr1 -> "atr1"
| Ratr1 -> "ratr1"
|
|
177
|
| NoRestr -> ""
|
|
178
|
|
|
179
180
181
182
|
let controllers l =
Xlist.map l (function
"1" -> "controller"
| n -> "controller" ^ n)
|
|
183
|
|
|
184
185
186
187
188
|
let controllees l =
Xlist.map l (function
"1" -> "controllee"
| n -> "controllee" ^ n)
|
|
189
190
|
let rec schema schema =
String.concat "+" (Xlist.map schema (fun s ->
|
|
191
|
String.concat "," (
|
|
192
|
(if s.gf = ARG then [] else [gf s.gf])@s.mode@
|
|
193
194
|
(if s.role = "" then [] else [s.role])@
(if s.role_attr = "" then [] else [s.role_attr])@
|
|
195
|
(*s.sel_prefs@*)(controllers s.cr)@(controllees s.ce)) ^ "{" ^ String.concat ";" (Xlist.map s.morfs morf) ^ "}"))
|
|
196
|
|
|
197
198
|
(*and schema_role schema =
String.concat "+" (Xlist.map schema (fun (r,role,cr,ce,morfs) ->
|
|
199
200
|
String.concat "," ((if r = "" then [] else [r])@(if role = "" then [] else [role])@(controllers cr)@(controllees ce)) ^ "{" ^ String.concat ";" (Xlist.map morfs morf) ^ "}")) *)
|
|
201
|
and morf = function
|
|
202
203
204
205
206
|
Phrase p -> phrase p
| E p -> "E(" ^ phrase p ^ ")"
| LexPhrase(pos_lex,(r,s)) -> "lex([" ^ String.concat ";" (Xlist.map pos_lex (fun (p,le) -> pos p ^ "," ^ lex le)) ^ "]," ^ restr r ^ "[" ^ schema s ^ "])"
| PhraseAbbr(p,ml) -> phrase_abbr p ^ "[" ^ String.concat ";" (Xlist.map ml morf) ^ "]"
| PhraseComp(p,(ct,l)) -> phrase_comp p ^ "," ^ comp_type ct ^ "[" ^ String.concat ";" (Xlist.map l comp) ^ "]"
|
|
207
|
| MorfId id -> Printf.sprintf "id(%d)" id
|
|
208
209
|
| SimpleLexArg(le,p) -> "lex(" ^ le ^ "," ^ pos p ^ ")"
| LexArg(id,le,p) -> "lex(" ^ string_of_int id ^ "," ^ le ^ "," ^ pos p ^ ")"
|
|
210
|
|
|
211
212
213
|
let simple_morf = function
| MorfId id -> Printf.sprintf "%d" id
| _ -> failwith "ENIAMwalStringOf.simple_morf"
|
|
214
|
|
|
215
216
217
218
219
220
|
let rec simple_schema schema =
String.concat "+" (Xlist.map schema (fun s ->
String.concat "," (
(if s.gf = ARG then [] else [gf s.gf])@
s.mode@(controllers s.cr)@(controllees s.ce)) ^
"{" ^ String.concat ";" (Xlist.map s.morfs simple_morf) ^ "}"))
|
|
221
|
|
|
222
223
224
225
226
227
228
|
let sel_prefs = function
SynsetId id -> Printf.sprintf "synset(%d)" id
| Predef id -> id
| RelationArgId _ -> failwith "sel_prefs"
| RelationRole(rel,role,role_attr) ->
if role_attr = "" then Printf.sprintf "relation(%s,%s)" rel role
else Printf.sprintf "relation(%s,%s,%s)" rel role role_attr
|
|
229
|
|
|
230
231
232
233
|
let sem_frame (s:position) =
s.role ^
(if s.role_attr="" then "" else "," ^ s.role_attr) ^
|
|
234
235
|
(if s.sel_prefs = [] then "" else
"[" ^ String.concat ";" (Xlist.map s.sel_prefs sel_prefs) ^ "]")
|
|
236
237
238
239
240
241
242
243
244
245
246
|
let rec connected_schema schema =
String.concat "+" (Xlist.map schema (fun s ->
String.concat "," (
(if s.gf = ARG then [] else [gf s.gf])@
s.mode@(controllers s.cr)@(controllees s.ce)) ^
"{" ^ String.concat ";" (Xlist.map s.morfs simple_morf) ^ "}:" ^ sem_frame s))
(* let meaning m =
m.name ^ "-" ^ m.variant *)
|
|
247
|
|
|
248
249
250
251
252
253
254
255
256
257
258
259
|
let lex_entry = function
SimpleLexEntry(le,p) ->
Printf.sprintf "lex(%s,%s)" le p
| LexEntry(id,le,p,NoRestr,s) ->
Printf.sprintf "lex(%d,%s,%s)\t%s" id le p (schema s)
| LexEntry(id,le,p,r,[]) ->
Printf.sprintf "lex(%d,%s,%s)\t%s" id le p (restr r)
| ComprepNPEntry(le,NoRestr,s) ->
Printf.sprintf "comprepnp(%s)\t%s" le (schema s)
| ComprepNPEntry(le,r,[]) ->
Printf.sprintf "comprepnp(%s)\t%s" le (restr r)
| _ -> failwith "ENIAMwalStringOf.lex_entry"
|