-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconversion.c
599 lines (509 loc) · 14.9 KB
/
conversion.c
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
/***************************************
$Header$
Work out how to gloss certain node types depending on the sequence
of SE cmavo that precede them. Work out the context that various
selbri components occur in, to determine which gloss to use.
***************************************/
/* COPYRIGHT */
/*
Perform handling to do with conversion (se,te etc)
*/
#include <assert.h>
#include "nodes.h"
#include "functions.h"
#include "rpc_tab.h"
#include "cmavotab.h"
/*++++++++++++++++++++++++++++++
Lookup which place is exchanged for a cmavo of selma'o SE
++++++++++++++++++++++++++++++*/
static int
lookup_converted_place(TreeNode *se_cmavo)
{
char *se;
int conv;
se = cmavo_table[se_cmavo->data.cmavo.code].cmavo;
if (!strcmp(se, "se")) {
conv = 2;
} else if (!strcmp(se, "te")) {
conv = 3;
} else if (!strcmp(se, "ve")) {
conv = 4;
} else if (!strcmp(se, "xe")) {
conv = 5;
} else {
assert(0); /* No other cmavo in selma'o SE hopefully */
}
return conv;
}
/*++++++++++++++++++++++++++++++
Go through the parse tree and mark all SE BAI cmavo with extension
records on the BAI. Simple recursive traversal over the whole parse
tree.
++++++++++++++++++++++++++++++*/
static void
conv_tag_se_bai(TreeNode *x)
{
TreeNode *c, *c1, *c2;
int nc, i;
int conv;
XBaiConversion *ext;
XDontGloss *edg;
struct nonterm *nt;
if (x->type == N_NONTERM) {
nt = &x->data.nonterm;
switch (nt->type) {
case SE_BAI:
c1 = strip_attitudinal(nt->children[0]);
assert(c1->data.cmavo.selmao == SE);
c2 = nt->children[1];
conv = lookup_converted_place(c1);
ext = prop_bai_conversion(c2, YES);
ext->conv = conv;
/* Tag the SE cmavo so we don't display a gloss for it later. */
edg = prop_dont_gloss(c1, YES);
break;
case BAI1:
c1 = nt->children[0];
ext = prop_bai_conversion(c1, YES);
ext->conv = 1;
break;
default:
/* Traverse down through children */
nc = nt->nchildren;
for (i=0; i<nc; i++) {
c = nt->children[i];
conv_tag_se_bai(c);
}
break;
}
} else {
/* Nothing to do, the se_bai construction can only occur as a
non-terminal */
}
}
/*++++++++++++++++++++++++++++++
Take a tanru_unit_2 node found by the downward scan, and work
outwards gathering conversion operators.
TreeNode *tu2 The tu2 node (ancestor of apply_to)
TreeNode *apply_to The tu_2 node that wants the conversion applying
to it when the glossing is done later.
++++++++++++++++++++++++++++++*/
static void
compute_tu2_conv(TreeNode *tu2, TreeNode *apply_to) {
/* If the node already has a conversion on it, it must be something
whose conversion was determined in terms.c processing. */
if (prop_conversion(apply_to, NO)) {
return;
} else {
/* places[1] is which place of the base word the x1 of the bridi
corresponds to. zero means x1 is a jai construction. */
int places[6];
int i;
TreeNode *x = tu2;
for (i=1; i<=5; i++) {
places[i] = i;
}
/* Barf on JAI constructions for now, fix that up later */
for (;;) {
switch (x->data.nonterm.type) {
case SE_TU2:
{
int p, t;
XDontGloss *edg;
TreeNode *se = strip_attitudinal(child_ref(x, 0));
assert (se->data.cmavo.selmao == SE);
p = lookup_converted_place(se);
t = places[1];
places[1] = places[p];
places[p] = t;
edg = prop_dont_gloss(se, YES);
}
x = x->parent;
break;
/* This block just need to go up a level and keep scanning */
case TANRU_UNIT_2:
case NAHE_TU2:
case TANRU_UNIT_1:
case TANRU_UNIT:
case SELBRI_6:
case SELBRI_5:
case SELBRI_3:
case KE_SELBRI_3:
case KE_SELBRI3_TU2:
x = x->parent;
break;
case JAI_TU2:
case JAI_TAG_TU2:
/* current x1 of the bridi lost into the fai place, no way
to recover this later (no SE which exchanges fai with a
normal place!). */
places[1] = 0;
x = x->parent;
break;
case SELBRI_4:
/* Depends on whether we're immediately below an outermost
selbri_3 as to whether we close the conversion now or
propagate. */
if ((x->parent-> data.nonterm.type == SELBRI_3) &&
(x->parent->parent->data.nonterm.type == SELBRI_3)) {
/* close */
XConversion *ext;
ext = prop_conversion(apply_to, YES);
ext->conv = places[1];
return;
} else {
x = x->parent;
}
break;
case SELBRI_2:
/* done in all cases */
{
XConversion *ext;
ext = prop_conversion(apply_to, YES);
ext->conv = places[1];
return;
}
break;
default:
fprintf(stderr, "Unexpected case!!\n");
assert(0);
break;
}
}
}
}
/*++++++++++++++++++++++++++++++
Scan down the tree looking for BRIVLA, abstractions and other forms
of tanru_unit_2 that may be subject to conversion (SE) operators.
Work back up the syntax tree, accumulating conversions, until coming
to something that indicates no more conversions apply to this
tanru_unit_2.
++++++++++++++++++++++++++++++*/
static void
conv_mark_tu2s(TreeNode *x)
{
int nc, i;
TreeNode *c;
struct nonterm *nt;
nt = &x->data.nonterm;
if (x->type == N_NONTERM) {
nc = nt->nchildren;
for (i=0; i<nc; i++) {
c = nt->children[i];
conv_mark_tu2s(c);
}
} else if (x->type == N_BRIVLA) {
compute_tu2_conv(x->parent, x);
} else if ((x->type == N_CMAVO) &&
(x->data.cmavo.selmao == NU)) {
TreeNode *y;
y = x->parent;
assert(y->type == N_NONTERM);
while (y->data.nonterm.type != TANRU_UNIT_2) {
y = y->parent;
assert(y->type == N_NONTERM);
}
compute_tu2_conv(y, x);
}
}
/*+ State used to track the nearest enclosing ancestor node which
determines the form +*/
typedef enum {
GS_NONE,
GS_MAIN_SELBRI,
GS_SUMTI,
GS_JAI,
GS_MODAL
} GlossState;
/*++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++*/
static void
conv_mark_gloss_types(TreeNode *x, GlossState g)
{
struct nonterm *nt;
int nc, i;
TreeNode *c;
XGlosstype *gt;
GlossState ng;
if (x->type == N_NONTERM) {
#if 0
fprintf(stderr, "MGT called on nonterm ty=%s gs=%d\n", nonterm_names[x->data.nonterm.type], g);
#endif
nt = &x->data.nonterm;
nc = nt->nchildren;
switch (nt->type) {
case MAIN_SELBRI:
case METALINGUISTIC_MAIN_SELBRI:
ng = GS_MAIN_SELBRI;
break;
case JAI_TAG_TU2:
case JAI_TU2:
{
TreeNode *cjai;
cjai = child_ref(x, 0);
if (g != GS_NONE) {
gt = prop_glosstype(cjai, YES);
if (g == GS_MAIN_SELBRI || g == GS_JAI) {
gt->in_selbri = 1;
} else {
gt->in_selbri = 0;
}
}
}
ng = GS_JAI;
break;
case SUMTI:
ng = GS_SUMTI;
break;
case FREE:
case OPERAND_3:
case MEX_OPERATOR:
ng = GS_NONE; /* Review later what to do with these ones */
break;
case COMPLEX_TENSE_MODAL:
ng = GS_MODAL;
break;
default:
ng = g;
break;
}
for (i=0; i<nc; i++) {
c = nt->children[i];
conv_mark_gloss_types(c, ng);
}
} else {
#if 0
if (x->type == N_BRIVLA) {
fprintf(stderr, "MGT called on brivla %s gs=%d\n", x->data.brivla.word, g);
}
if (x->type == N_CMAVO) {
fprintf(stderr, "MGT called on cmavo %s gs=%d\n", cmavo_table[x->data.cmavo.code].cmavo, g);
}
#endif
if ((x->type == N_BRIVLA) ||
(x->type == N_ZEI) ||
((x->type == N_CMAVO) &&
(x->data.cmavo.selmao == NU))) {
if (g != GS_NONE) {
gt = prop_glosstype(x, YES);
/* In something like 'le jai ca cusku' we want to treat
'cusku' as a 'verb' rather than a 'noun' when glossing */
if (g == GS_MAIN_SELBRI || g == GS_JAI) {
gt->in_selbri = 1;
} else {
gt->in_selbri = 0;
}
}
}
}
}
/*++++++++++++++++++++++++++++++++++++++
Scan the entire parse tree for selbri. Descend into each one to
work out which tanru_unit_2's inside it correspond to tertau',
i.e. need to be considered as nouns or verbs (rather than
adjectives) for glossing.
TreeNode *x
++++++++++++++++++++++++++++++++++++++*/
static void
selbri_scan(TreeNode *x, int is_tertau)
{
struct nonterm *nt;
int nc, i;
TreeNode *c;
nt = &x->data.nonterm;
nc = nt->nchildren;
if (x->type == N_NONTERM) {
nt = &x->data.nonterm;
nc = nt->nchildren;
if (is_tertau) {
switch (nt->type) {
case SELBRI:
break;
case SELBRI_1:
break;
case SELBRI_2:
break;
case SELBRI_3:
break;
case SELBRI_4:
{
TreeNode *cs4, *cs5, *cks3, *cs3;
cs4 = x;
while (nch(cs4) > 1) {
cs5 = find_nth_child(cs4, 1, SELBRI_5);
cks3 = find_nth_child(cs4, 1, KE_SELBRI_3);
if (cs5) {
selbri_scan(cs5, 1);
}
if (cks3) {
cs3 = find_nth_child(cks3, 1, SELBRI_3);
/* This is like a new selbri_3, only the last selbri_4
has tertau status, with the prefixes being
adjectival */
selbri_scan(cs3, 0);
}
cs4 = find_nth_child(cs4, 1, SELBRI_4);
}
/* Mop up final child */
cs5 = find_nth_child(cs4, 1, SELBRI_5);
selbri_scan(cs5, 1);
}
break;
case SELBRI_5:
{
TreeNode *cs5, *cs6;
cs5 = x;
do {
cs6 = find_nth_child(cs5, 1, SELBRI_6);
selbri_scan(cs6, 1);
cs5 = find_nth_child(cs5, 1, SELBRI_5);
} while (cs5);
}
break;
case SELBRI_6:
{
TreeNode *cs6, *tu;
cs6 = x;
do {
tu = find_nth_child(cs6, 1, TANRU_UNIT);
if (tu) {
selbri_scan(tu, 1);
}
/* There is a clever hack here. In the NAhE guhek
selbri gik selbri_6 case, we don't need to bother
about processing the selbri - the selbri_3 within it
will get picked up eventually anyway by scanning the
whole tree for selbri_3's. */
cs6 = find_nth_child(cs6, 1, SELBRI_6);
} while (cs6);
}
break;
case TANRU_UNIT:
{
TreeNode *ctu1, *ctu;
ctu = x;
do {
ctu1 = find_nth_child(ctu, 1, TANRU_UNIT_1);
selbri_scan(ctu1, 1);
ctu = find_nth_child(ctu, 1, TANRU_UNIT);
} while (ctu);
}
break;
case TANRU_UNIT_1:
{
TreeNode *ctu2;
ctu2 = find_nth_child(x, 1, TANRU_UNIT_2);
selbri_scan(ctu2, 1);
}
break;
case TANRU_UNIT_2:
{
TreeNode *c;
c = child_ref(x, 0);
if (c->type == N_BRIVLA || c->type == N_ZEI) {
XGlosstype *gt;
gt = prop_glosstype(c, YES);
gt->is_tertau = 1;
} else if (c->type == N_NONTERM) {
switch (c->data.nonterm.type) {
case AUGMENTED:
{
TreeNode *cc;
cc = strip_attitudinal(c);
if (cc->type == N_BRIVLA) {
XGlosstype *gt;
gt = prop_glosstype(cc, YES);
gt->is_tertau = 1;
}
}
break;
case SE_TU2:
case JAI_TU2:
case NAHE_TU2:
{
TreeNode *cc;
cc = find_nth_child(c, 1, TANRU_UNIT_2);
selbri_scan(cc, 1);
}
break;
case JAI_TAG_TU2:
{
TreeNode *cc, *cjai;
XGlosstype *gt;
cjai = child_ref(c, 0);
gt = prop_glosstype(cjai, YES);
gt->is_tertau = 1;
cc = find_nth_child(c, 1, TANRU_UNIT_2);
selbri_scan(cc, 1);
}
break;
case ABSTRACTION:
{
TreeNode *nns;
TreeNode *nu;
XGlosstype *gt;
nns = child_ref(c, 0);
while (nns) {
nu = find_nth_cmavo_child(nns, 1, NU);
gt = prop_glosstype(nu, YES);
gt->is_tertau = 1;
nns = find_nth_child(nns, 1, NU_NAI_SEQ);
}
}
break;
default:
break;
}
}
}
break;
default:
break;
}
} else {
/* If it's a selbri_3 that hasn't been scanned yet, need to do
it. The ideas is that in a selbri_2, the tertau is the last
selbri_4 term within the selbri_3 term either at the head, or
before the first CO. This selbri_4 is the last term of the
outermost selbri_3, if it's a tanru with multiple
components. */
if (nt->type == SELBRI_3 && !prop_done_s3(x, NO)) {
/* Find final selbri_4 */
TreeNode *cs4, *cs3;
XDoneS3 *xds3;
#if 0
fprintf(stderr, "Here B\n");
#endif
cs3 = x;
cs4 = find_nth_child(cs3, 1, SELBRI_4);
do {
xds3 = prop_done_s3(cs3, YES);
cs3 = find_nth_child(cs3, 1, SELBRI_3);
} while (cs3);
/* Actively scan down into selbri4 */
#if 0
fprintf(stderr, "Here A\n");
#endif
selbri_scan(cs4, 1);
}
}
/* In all cases, scan downwards to look for other selbri that haven't been tackled yet */
for (i=0; i<nc; i++) {
c = nt->children[i];
selbri_scan(c, 0);
}
} else {
/* Nothing to do */
}
}
/*++++++++++++++++++++++++++++++
Do all conversion stages
++++++++++++++++++++++++++++++*/
void
do_conversions(TreeNode *top)
{
conv_tag_se_bai(top);
conv_mark_tu2s(top);
conv_mark_gloss_types(top, GS_NONE);
selbri_scan(top, 0);
}