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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
#! /usr/bin/perl -w
#
# Perl script to process OALD machine-readable ASCII file
# into a GF lexicon
#
# Usage: ./asc2gf < ascii_0710-1.txt
#
# Bjorn Bringert 2008,
# based on asc2lex by
# Matthew Purver, 11/2001
use strict;
my %irregular_verbs = ();
my %words = ();
my $irreg_eng = "../../english/IrregEng.gf";
open(IRREG_ENG,"$irreg_eng") or die "Could not open $irreg_eng\n";
while (<IRREG_ENG>) {
if (s/\s*([a-z\d]+)_V\s*=.*/$1/) {
chomp;
$irregular_verbs{$_} = 1;
}
}
close IRREG_ENG;
print "Known irregular verbs from $irreg_eng:\n";
print join(",", keys %irregular_verbs) . "\n";
# skip header section
while ( <STDIN> ) {
last if /<\/TEIHEADER>/;
}
# read a line from stdin
while ( my $line = <STDIN> ) {
# remove SGML tags
$line =~ s/<[^<>]+>//g;
# split line into fields according to spec (line may be empty now)
if ( $line =~ /^(.{23}).{23}(.{23}).{1}(.{58})$/ ) {
my ( $word, $pos, $cat ) = ( $1, $2, $3 );
# trim white space
for ( ( $word, $pos, $cat ) ) {
s/\s*$//;
}
# make word lower-case
$word =~ tr/A-Z/a-z/; # lower case
# translate OALD diacritics
$word =~ s/~n/ñ/g;
$word =~ s/<c/ç/g;
$word =~ s/"a/ä/g;
$word =~ s/"o/ö/g;
$word =~ s/"u/ü/g;
$word =~ s/"i/ï/g;
$word =~ s/\^a/â/g;
$word =~ s/\^e/ê/g;
$word =~ s/\^o/ô/g;
$word =~ s/`a/à/g;
$word =~ s/`e/è/g;
$word =~ s/_e/é/g;
# make legal identifier
# Note: in theory this could cause clashes, but I don't think it does
# with the OALD.
my $name = $word;
$name =~ s/ /_/g; # space -> _
$name =~ s/-/_/g; # - -> _
$name =~ s/\./_/g; # . -> _
$name =~ s/^'//; # drop initial '
# get PoS & subcat info
my @pos = split( /,/, $pos );
$cat =~ s/,/\',\'/g;
( $cat = "\'$cat\'" ) unless ( $cat eq '' );
foreach ( @pos ) {
my ( $pcode, $infl, $freq )=split(//);
# for verbs, get inflected forms
if ( $pcode =~ /^[GHIJ]/ ) {
$pos = 'verb';
my ($vbz, $vbg, $vbd);
# if this is a root form, work out the inflected forms
if ( $infl =~ /^\d/ ) {
if ( $infl == 0 ) {
( $vbz = $word ) =~ s/$/s/;
( $vbg = $word ) =~ s/$/ing/;
( $vbd = $word ) =~ s/$/ed/;
}
elsif ( $infl == 1 ) {
( $vbz = $word ) =~ s/$/es/;
( $vbg = $word ) =~ s/$/ing/;
( $vbd = $word ) =~ s/$/ed/;
}
elsif ( $infl == 2 ) {
( $vbz = $word ) =~ s/e$/es/;
( $vbg = $word ) =~ s/e$/ing/;
( $vbd = $word ) =~ s/e$/ed/;
}
elsif ( $infl == 3 ) {
( $vbz = $word ) =~ s/y$/ies/;
( $vbg = $word ) =~ s/y$/ying/;
( $vbd = $word ) =~ s/y$/ied/;
}
elsif ( $infl == 4 ) {
( $vbz = $word ) =~ s/$/s/;
( $vbg = $word ) =~ s/(\w)$/$1$1ing/;
( $vbd = $word ) =~ s/(\w)$/$1$1ed/;
}
elsif ( $infl == 5 ) {
# for irregulars, just mark as such for now, we'll guess later
$vbz = 'IRREG';
$vbg = 'IRREG';
$vbd = 'IRREG';
}
my $lin = "mkV \"$word\" \"$vbz\" \"$vbd\" \"$vbd\" \"$vbg\"";
# try to use a verb from IrregEng
if ( $infl == 5 ) {
for (my $i = 0; $i < length($word) - 1; $i++) {
my $suffix = substr($word, $i);
if ($irregular_verbs{$suffix}) {
if ($i == 0) {
$lin = "IrregEng.${name}_V";
} else {
my $prefix = substr($word, 0, $i);
$lin = "mkV \"$prefix\" IrregEng.${suffix}_V";
}
last;
}
}
}
if ($pcode eq 'G') {
#add_word("${name}_VX", "mkVX ($lin)");
print STDERR "Ignoring anomalous verb: $name\n";
}
if ($pcode eq 'I' || $pcode eq 'J') {
add_word("${name}_V", "$lin");
}
if ($pcode eq 'H' || $pcode eq 'J') {
add_word("${name}_V2", "mkV2 ($lin)");
}
}
# if this is an inflected form, save for guessing irregulars later
elsif ( $infl =~ /^a/ ) {
#push( @vbz, $word );
}
elsif ( $infl =~ /^b/ ) {
#push( @vbg, $word );
}
elsif ( $infl =~ /^c/ ) {
#push( @vbd, $word );
}
elsif ( $infl =~ /^d/ ) {
#push( @vbn, $word );
}
}
# for nouns, get plural form
elsif( $pcode =~ /^[KLMNY]/ ) {
$pos = 'noun';
$pcode =~ s/^K/count/;
$pcode =~ s/^L/mass/;
$pcode =~ s/^M/both/;
$pcode =~ s/^N/proper/;
if ( $pcode =~ /^Y/ ) {
$pcode = 'count' if $infl =~ /^[>\)\]]/;
$pcode = 'mass' if $infl =~ /^\}/;
$pcode = 'proper' if $infl =~ /^[:=~]/;
}
# if this is a singular form, work out plural form
unless ( $infl =~ /^j/ ) {
my $pl = '-';
if ( $infl eq '6' ) {
( $pl = $word ) =~ s/$/s/;
}
elsif ( $infl eq '7' ) {
( $pl = $word ) =~ s/$/es/;
}
elsif ( $infl eq '8' ) {
( $pl = $word ) =~ s/y$/ies/;
}
elsif ( $infl =~ /^[9k\]]/ ) {
$pl = $word;
}
elsif ( $infl =~ /^i/ ) {
# for irregulars, let's just make a guess and mark with '*'
# this could be done better, as for verbs, but I can't be bothered now
$pl = $word;
( $pl =~ s/^((wo)?m)an/$1en\*/ ) or
( $pl =~ s/man(-|$)/men$1\*/ ) or
( $pl =~ s/-in-law/s-in-law\*/ ) or
( $pl =~ s/um$/a\*/ ) or
( $pl =~ s/us$/i\*/ ) or
( $pl =~ s/a$/ae\*/ ) or
( $pl =~ s/on$/a\*/ ) or
( $pl =~ s/is$/es\*/ ) or
( $pl =~ s/o$/i\*/ ) or
( $pl =~ s/child$/children\*/ ) or
( $pl =~ s/oot$/eet\*/ ) or
( $pl =~ s/ooth$/eeth\*/ ) or
( $pl =~ s/([lm])ouse$/$1ice\*/ ) or
( $pl =~ s/f(e)?$/ves\*/ ) or
( $pl =~ s/[ei]x$/ices\*/ ) or
( $pl =~ s/eau$/eaux\*/ ) or
( $pl = 'IRREG' );
}
# if plural-only, swap root form & plural
elsif ( $infl =~ /^\)/ ) {
$pl = $word;
$word = '-';
}
( $infl =~ s/^[:l]/per/ ) or ( $infl =~ s/^[mn]/loc/ ) or ( $infl = '_' );
my $comment = "";
if ( $word eq '-' ) {
$comment .= " {- FIXME: no singular form -}";
}
if ( $pl eq '-' ) {
$comment .= " {- FIXME: no plural form -}";
}
if ( $pl =~ s/\*$// ) {
$comment .= " {- FIXME: guessed plural form -}";
}
if ( $pcode eq 'proper' ) {
add_word("${name}_PN", "mkPN \"$word\"");
} else {
add_word("${name}_N", "mkN \"$word\" \"$pl\"$comment");
}
}
}
# for adjectives, get comparative & superlative forms
elsif( $pcode =~ /^O/ ) {
$pos = 'adj';
# if this is root form, work out inflected forms
unless ( $infl =~ /^[rs]/ ) {
my ($comp, $sup);
if ( $infl =~ /^[Apqt]/ ) {
$comp = $sup = '-';
}
elsif ( $infl =~ /^B/ ) {
( $comp = $word ) =~ s/$/r/;
( $sup = $word ) =~ s/$/st/;
}
elsif ( $infl =~ /^C/ ) {
( $comp = $word ) =~ s/$/er/;
( $sup = $word ) =~ s/$/est/;
}
elsif ( $infl =~ /^D/ ) {
( $comp = $word ) =~ s/y$/ier/;
( $sup = $word ) =~ s/y$/iest/;
}
elsif ( $infl =~ /^E/ ) {
# for irregulars, let's just have a guess and mark with '*'
# (there aren't very many of these)
( $comp = $word ) =~ s/(\w)$/$1$1er\*/;
( $sup = $word ) =~ s/(\w)$/$1$1est\*/;
}
$infl =~ s/^[ABCDE]/normal/;
$infl =~ s/^p/pred/;
$infl =~ s/^q/attr/;
$infl =~ s/^t/affix/;
if ( $comp eq '-' ) {
add_word("${name}_A", "compoundA (mkA \"$word\")");
} else {
add_word("${name}_A", "mkA \"$word\" \"$comp\"");
}
}
}
# adverb
elsif( $pcode =~ /^P/ ) {
$pos = 'adv';
$infl =~ s/^[u\+]/normal/;
$infl =~ s/^w/whrel/;
$infl =~ s/^v/whq/;
add_word("${name}_Adv", "mkAdv \"$word\"");
}
# pronoun
elsif( $pcode =~ s/^Q/_/ ) {
$pos = 'pron';
$infl =~ s/^x/normal/;
$infl =~ s/^y/whq/;
$infl =~ s/^z/whrel/;
my $class = '_';
# reflexive pronouns
if ( ( $word =~ /self$/ ) or
( $word =~ /selves$/ ) ) {
$pcode = 'acc';
}
# accusative personal pronouns
if ( ( $word =~ /^him/ ) or
( $word =~ /^her/ ) or
( $word =~ /^them/ ) or
( $word eq 'us' ) or
( $word eq 'thee' ) or
( $word eq 'me' ) ) {
$pcode = 'acc';
$class = 'per';
}
# nominative personal pronouns
if ( ( $word eq 'he' ) or
( $word eq 'she' ) or
( $word eq 'they' ) or
( $word eq 'we' ) or
( $word eq 'thou' ) or
( $word eq 'i' ) ) {
$pcode = 'nom';
$class = 'per';
}
# other personal pronouns
if ( ( $word =~ /.+one/ ) or
( $word =~ /one.+/ ) or
( $word =~ /body/ ) or
( $word =~ /^you/ ) or
( $word =~ /^who/ ) ) {
$class = 'per';
}
# non-personal pronouns
if ( $word =~ /thing/ ) {
$class = 'nper';
}
# otherwise case/person info will be '_' (anon variable)
# add full spec to @pron array
#push( @pron, "$pos( \'$word\', $pcode, $infl, $class ).\n" );
}
# for determiners, leave anon variable as placeholder for semantics
elsif( $pcode =~ /^[RS]/ ) {
$pos = 'det';
$pcode =~ s/^R/def/;
$pcode =~ s/^S/indef/;
#add_word("${name}_Det","mkDeterminer \"$word\"");
}
# for prepositions - nothing to say
elsif( $pcode =~ s/^T/prep/ ) {
$pos = 'prep';
add_word("${name}_Prep","mkPrep \"$word\"");
}
# for conjunctions - nothing to say
elsif( $pcode =~ s/^V/conj/ ) {
$pos = 'conj';
add_word("${name}_Conj","mkConj \"$word\"");
}
# for miscellaneous, leave '-' as placeholder for illocutionary info
elsif( $pcode =~ /^[UWXZ]/ ) {
$pos = 'misc';
#push( @prefix, "$pos( \'$word\', $pcode, '-' ).\n" ) if ( $pcode =~ s/^U/prefix/ );
#push( @interj, "$pos( \'$word\', $pcode, '-' ).\n" ) if ( $pcode =~ s/^W/interj/ );
#push( @partcl, "$pos( \'$word\', $pcode, '-' ).\n" ) if ( $pcode =~ s/^X/partcl/ );
#push( @unknown, "$pos( \'$word\', $pcode, '-' ).\n" ) if ( $pcode =~ s/^Z/unknown/ );
}
}
}
}
my $absfile = "Oald.gf";
my $cncfile = "OaldEng.gf";
my $abs_structfile = "OaldStructural.gf";
my $cnc_structfile = "OaldStructuralEng.gf";
open (ABS, '>', $absfile);
open (CNC, '>', $cncfile);
open (ABS_STRUCTURAL, '>', $abs_structfile);
open (CNC_STRUCTURAL, '>', $cnc_structfile);
# print a nice comment at the top
my $header = "-- English lexicon for GF, produced from:\n"
. "-- Oxford advanced learner's dictionary of current English:\n"
. "-- expanded 'computer usable' version compiled by Roger Mitton\n"
. "-- The computer usable version is transcribed from:\n"
. "-- Oxford advanced learner's dictionary of current English\n"
. "-- A.S. Hornby ; with the assistance of A.P. Cowie [and] J. Windsor Lewis.\n"
. "-- 3rd. ed., London : Oxford University Press, 1974.\n"
. "-- Distributed as 'dict0710' by:\n"
. "-- Oxford Text Archive\n"
. "-- Oxford University Computing Services\n"
. "-- 13 Banbury Road\n"
. "-- Oxford\n"
. "-- OX2 6NN\n"
. "-- Under these conditions:\n"
. "-- Freely available for non-commercial use provided that this header is\n"
. "-- included in its entirety with any copy distributed.\n"
. "--\n"
. "-- GF version generated by asc2gf, Bjorn Bringert Nov 2008\n"
. "-- based on asc2lex, Matthew Purver Nov 2001\n"
. "-- http://www.stanford.edu/~mpurver/software.html\n"
. "\n";
print ABS $header;
print ABS "abstract Oald = Cat ** {\n";
print CNC $header;
print CNC "--# -path=.:alltenses\n";
print CNC "concrete OaldEng of Oald = CatEng ** open ParadigmsEng, IrregEng in {\n";
print ABS_STRUCTURAL $header;
print ABS_STRUCTURAL "abstract OaldStructural = Cat ** {\n";
print CNC_STRUCTURAL $header;
print CNC_STRUCTURAL "--# -path=.:alltenses\n";
print CNC_STRUCTURAL "concrete OaldStructuralEng of OaldStructural = CatEng ** open ParadigmsEng in {\n";
foreach my $name (sort (keys %words)) {
(my $cat = $name) =~ s/.*_([A-Z][A-Za-z\d]*)$/$1/;
my $lin = $words{$name};
if ( $cat =~ /^(A)|(N)|(V)|(V2)$/ ) {
print ABS "fun $name : $cat;\n";
print CNC "lin $name = $lin;\n";
} else {
print ABS_STRUCTURAL "fun $name : $cat;\n";
print CNC_STRUCTURAL "lin $name = $lin;\n";
}
}
print ABS "}";
print CNC "}";
print ABS_STRUCTURAL "}";
print CNC_STRUCTURAL "}";
close(ABS_STRUCTURAL);
close(CNC_STRUCTURAL);
close(ABS);
close(CNC);
print "\nWrote open lexicon to $absfile and $cncfile\n";
print "Wrote closed lexicon to $abs_structfile and $cnc_structfile\n";
sub add_word {
my ($name,$lin) = @_;
if (exists $words{$name}) {
print STDERR "Duplicate word: $name\n";
} else {
$words{$name} = $lin;
}
}
|