Blame view

walenty/ENIAMwalStringOf.ml 8.54 KB
Wojciech Jaworski authored
1
(*
Wojciech Jaworski authored
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
Wojciech Jaworski authored
5
 *
Wojciech Jaworski authored
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
Wojciech Jaworski authored
8
9
10
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
Wojciech Jaworski authored
11
 *  This library is distributed in the hope that it will be useful,
Wojciech Jaworski authored
12
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Wojciech Jaworski authored
14
 *  GNU Lesser General Public License for more details.
Wojciech Jaworski authored
15
 *
Wojciech Jaworski authored
16
 *  You should have received a copy of the GNU Lesser General Public License
Wojciech Jaworski authored
17
18
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *)
Wojciech Jaworski authored
20
open ENIAMwalTypes
Wojciech Jaworski authored
21
Wojciech Jaworski authored
22
let opinion = function
Wojciech Jaworski authored
23
24
25
26
27
28
    Pewny -> "cer"
  | Potoczny -> "col"
  | Watpliwy -> "unc"
  | Archaiczny -> "dat"
  | Zly -> "bad"
  | Wulgarny -> "vul"
Wojciech Jaworski authored
29
30
  | Dziedzinowy -> "dom"
  | Nieokreslony -> "unk"
Wojciech Jaworski authored
31
  | Metaforyczny -> "met"
Wojciech Jaworski authored
32
33
  | Sporadyczny -> "rar"
  | OpinionUndef -> failwith "ENIAMwalStringOf.opinion"
Wojciech Jaworski authored
34
Wojciech Jaworski authored
35
36
37
38
39
let negation = function
    Negation -> "neg"
  | Aff -> "aff"
  | NegationUndef -> "_"
  | NegationNA -> ""
Wojciech Jaworski authored
40
Wojciech Jaworski authored
41
let pred = function
Wojciech Jaworski authored
42
    PredNA -> ""
Wojciech Jaworski authored
43
44
45
  | PredTrue -> "pred"
  | PredFalse -> "nopred"
  | PredUndef -> "_"
Wojciech Jaworski authored
46
Wojciech Jaworski authored
47
48
49
50
let aspect = function
    Aspect s -> s
  | AspectUndef -> "_"
  | AspectNA -> ""
Wojciech Jaworski authored
51
Wojciech Jaworski authored
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 -> "_"
Wojciech Jaworski authored
64
let rec comp = function
Wojciech Jaworski authored
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 -> "_"
Wojciech Jaworski authored
74
Wojciech Jaworski authored
75
76
77
78
let number = function
    Number s -> s
  | NumberAgr -> "agr"
  | NumberUndef -> "_"
Wojciech Jaworski authored
79
Wojciech Jaworski authored
80
81
82
83
84
let gender = function
    Gender s -> s
  | GenderUndef -> "_"
  | GenderAgr -> "agr"
  | Genders l -> String.concat "." l
Wojciech Jaworski authored
85
Wojciech Jaworski authored
86
87
88
let grad = function
    Grad s -> s
  | GradUndef -> "_"
Wojciech Jaworski authored
89
Wojciech Jaworski authored
90
91
let refl = function
    ReflEmpty -> ""
Wojciech Jaworski authored
92
93
94
  | ReflTrue -> "siÄ™"
  | ReflFalse -> "nosiÄ™"
  | ReflUndef -> "_"
Wojciech Jaworski authored
95
Wojciech Jaworski authored
96
(* let acm = function
Wojciech Jaworski authored
97
    Acm s -> s
Wojciech Jaworski authored
98
  | AcmUndef -> "_" *)
Wojciech Jaworski authored
99
Wojciech Jaworski authored
100
101
102
103
let gf = function
    SUBJ -> "subj"
  | OBJ -> "obj"
  | ARG -> "arg"(*""*)
Wojciech Jaworski authored
104
Wojciech Jaworski authored
105
106
let pos = function
    SUBST(n,c) -> "SUBST(" ^ number n ^ "," ^ case c ^ ")"
Wojciech Jaworski authored
107
108
109
  | PPRON12(n,c) -> "PPRON12(" ^ number n ^ "," ^ case c ^ ")"
  | PPRON3(n,c) -> "PPRON3(" ^ number n ^ "," ^ case c ^ ")"
  | SIEBIE(c) -> "SIEBIE(" ^ case c ^ ")"
Wojciech Jaworski authored
110
  | PREP(c) -> "PREP(" ^ case c ^ ")"
Wojciech Jaworski authored
111
  | NUM(c,g) -> "NUM(" ^ case c ^ "," ^ gender g ^ (*"," ^ acm a ^*) ")"
Wojciech Jaworski authored
112
113
  | ADJ(n,c,g,gr) -> "ADJ(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ grad gr ^ ")"
  | ADV(gr) -> "ADV(" ^ grad gr ^ ")"
Wojciech Jaworski authored
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*) ^ ")"
Wojciech Jaworski authored
116
  | PPAS(n,c,g,a,neg) -> "PPAS(" ^ number n ^ "," ^ case c ^ "," ^ gender g ^ "," ^ aspect a ^ "," ^ negation neg ^ ")"
Wojciech Jaworski authored
117
  | INF(a,n) -> "INF(" ^ aspect a ^ "," ^ negation n (*^ "," ^ refl r*) ^ ")"
Wojciech Jaworski authored
118
119
120
  | QUB -> "QUB"
  | COMPAR -> "COMPAR"
  | COMP(c) -> "COMP(" ^ comp_type c ^ ")"
Wojciech Jaworski authored
121
  | PERS(n) -> "PERS(" ^ negation n ^ (*"," ^ refl r ^*) ")"
Wojciech Jaworski authored
122
  | FIXED -> "FIXED"
Wojciech Jaworski authored
123
Wojciech Jaworski authored
124
125
let phrase = function
    NP c -> "np(" ^ case c ^ ")"
Wojciech Jaworski authored
126
  | PrepNP(prep,c) -> "prepnp(" ^ prep ^ "," ^ case c ^ ")"
Wojciech Jaworski authored
127
  | AdjP c -> "adjp(" ^ case c ^ ")"
Wojciech Jaworski authored
128
  | PrepAdjP(prep,c) -> "prepadjp(" ^ prep ^ "," ^ case c ^ ")"
Wojciech Jaworski authored
129
  | NumP(c) -> "nump(" ^ case c ^ ")"
Wojciech Jaworski authored
130
131
  | PrepNumP(prep,c) -> "prepnump(" ^ prep ^ "," ^ case c ^ ")"
  | ComprepNP(prep) -> "comprepnp(" ^ prep ^ ")"
Wojciech Jaworski authored
132
  | ComparP(prep) -> "comparp(" ^ prep ^ ")"
Wojciech Jaworski authored
133
134
  | CP(ct,co) -> "cp(" ^ comp_type ct ^ "," ^ comp co ^ ")"
  | NCP(c,ct,co) -> "ncp(" ^ case c ^ "," ^ comp_type ct ^ "," ^ comp co ^ ")"
Wojciech Jaworski authored
135
136
  | PrepNCP(prep,c,ct,co) -> "prepncp(" ^ prep ^ "," ^ case c ^ "," ^ comp_type ct ^ "," ^ comp co ^ ")"
  | InfP(a) -> "infp(" ^ aspect a (*^ req r*) ^ ")"
Wojciech Jaworski authored
137
  | AdvP m -> "advp(" ^ m ^ ")"
Wojciech Jaworski authored
138
  | FixedP s -> "fixed(" ^ s ^ ")"
Wojciech Jaworski authored
139
  (* | Num(c,a) -> "num(" ^ case c ^ "," ^ acm a ^ ")" *)
Wojciech Jaworski authored
140
141
  | Or -> "or"
  | Qub -> "qub"
Wojciech Jaworski authored
142
143
  (* | Pro -> "pro"
  | ProNG -> "prong" *)
Wojciech Jaworski authored
144
  | Null -> "null"
Wojciech Jaworski authored
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 ^ ")"
Wojciech Jaworski authored
151
Wojciech Jaworski authored
152
153
154
155
156
let phrase_abbr = function
    Xp(m) -> "xp(" ^ m ^ ")"
  | Nonch -> "nonch"
  | Distrp -> "distrp"
  | Possp -> "possp"
Wojciech Jaworski authored
157
Wojciech Jaworski authored
158
159
160
161
let phrase_comp = function
    Cp -> "cp"
  | Ncp(c) -> "ncp(" ^ case c ^ ")"
  | Prepncp(prep,c) -> "prepncp(" ^ prep ^ "," ^ case c ^ ")"
Wojciech Jaworski authored
162
Wojciech Jaworski authored
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 ^ ")"
Wojciech Jaworski authored
169
170

let restr = function
Wojciech Jaworski authored
171
172
173
174
175
176
    Natr -> "natr"
  | Atr -> "atr"
  | Ratr -> "ratr"
  | Ratrs -> "ratrs"
  | Atr1 -> "atr1"
  | Ratr1 -> "ratr1"
Wojciech Jaworski authored
177
  | NoRestr -> ""
Wojciech Jaworski authored
178
Wojciech Jaworski authored
179
180
181
182
let controllers l =
  Xlist.map l (function
      "1" -> "controller"
    | n -> "controller" ^ n)
Wojciech Jaworski authored
183
Wojciech Jaworski authored
184
185
186
187
188
let controllees l =
  Xlist.map l (function
      "1" -> "controllee"
    | n -> "controllee" ^ n)
Wojciech Jaworski authored
189
190
let rec schema schema =
  String.concat "+" (Xlist.map schema (fun s ->
Wojciech Jaworski authored
191
    String.concat "," (
Wojciech Jaworski authored
192
      (if s.gf = ARG then [] else [gf s.gf])@s.mode@
Wojciech Jaworski authored
193
194
      (if s.role = "" then [] else [s.role])@
      (if s.role_attr = "" then [] else [s.role_attr])@
Wojciech Jaworski authored
195
      (*s.sel_prefs@*)(controllers s.cr)@(controllees s.ce)) ^ "{" ^  String.concat ";" (Xlist.map s.morfs morf) ^ "}"))
Wojciech Jaworski authored
196
Wojciech Jaworski authored
197
198
(*and schema_role schema =
  String.concat "+" (Xlist.map schema (fun (r,role,cr,ce,morfs) ->
Wojciech Jaworski authored
199
200
    String.concat "," ((if r = "" then [] else [r])@(if role = "" then [] else [role])@(controllers cr)@(controllees ce)) ^ "{" ^  String.concat ";" (Xlist.map morfs morf) ^ "}"))   *)
Wojciech Jaworski authored
201
and morf = function
Wojciech Jaworski authored
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) ^ "]"
Wojciech Jaworski authored
207
  | MorfId id -> Printf.sprintf "id(%d)" id
Wojciech Jaworski authored
208
209
  | SimpleLexArg(le,p) -> "lex(" ^ le ^ "," ^ pos p ^ ")"
  | LexArg(id,le,p) -> "lex(" ^ string_of_int id ^ "," ^ le ^ "," ^ pos p ^ ")"
Wojciech Jaworski authored
210
Wojciech Jaworski authored
211
212
213
let simple_morf = function
  | MorfId id -> Printf.sprintf "%d" id
  | _ -> failwith "ENIAMwalStringOf.simple_morf"
Wojciech Jaworski authored
214
Wojciech Jaworski authored
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) ^ "}"))
Wojciech Jaworski authored
221
Wojciech Jaworski authored
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
Wojciech Jaworski authored
229
Wojciech Jaworski authored
230
231
232
233

let sem_frame (s:position) =
  s.role ^
  (if s.role_attr="" then "" else "," ^ s.role_attr) ^
Wojciech Jaworski authored
234
235
  (if s.sel_prefs = [] then "" else
     "[" ^ String.concat ";" (Xlist.map s.sel_prefs sel_prefs) ^ "]")
Wojciech Jaworski authored
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 *)
Wojciech Jaworski authored
247
Wojciech Jaworski authored
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"