summaryrefslogtreecommitdiff
path: root/grammars/resource/russian/Syntax.gf
blob: 11b325bfcb133bd71e2fe6e5436262dd8b905e46 (plain)
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
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
--1 A Small Russian Resource Syntax          
--
-- Aarne Ranta, Janna Khegai 2003
--
-- This resource grammar contains definitions needed to construct 
-- indicative, interrogative, and imperative sentences in Russian.
--
-- The following files are presupposed:
resource Syntax = Morpho ** open Prelude, (CO = Coordination) in {
flags  coding=utf8 ;
  
--2 Common Nouns
--
--
--3 Common noun phrases
--
-- Complex common nouns ($Comm'NounPhrase$)  have in principle
-- the same parameters as simple ones.

oper
  CommNounPhrase: Type = {s : Number => Case => Str; g : Gender; anim : Animacy}  ;

  noun2CommNounPhrase : CommNoun -> CommNounPhrase = \sb ->
    {s = \\n,c => sb.s ! SF n c ; 
     g = sb.g ; 
     anim = sb.anim
    } ;

  commNounPhrase2CommNoun : CommNounPhrase -> CommNoun = \sb ->
    {s = \\sf => sb.s ! (numSF sf) ! (caseSF sf) ; 
     g = sb.g ; 
     anim = sb.anim
    } ;

  n2n = noun2CommNounPhrase;
  n2n2 = commNounPhrase2CommNoun ;

--2 Noun Phrases
--

oper

  NounPhrase : Type = { s : PronForm => Str ; n : Number ; 
   p : Person ; g: Gender ; anim : Animacy ;  pron: Bool} ;

  -- A function specific for Russian for setting the gender for 
  -- personal pronouns in first and second person, singular :
  setNPGender : Gender -> NounPhrase -> NounPhrase = \gen, pronI -> 
    { s = pronI.s ; g = gen ; anim = pronI.anim ;
      n = pronI.n ; nComp = pronI.nComp ; p = pronI.p ; pron = pronI.pron } ;  


  mkNounPhrase : Number -> CommNounPhrase -> NounPhrase = \n,chelovek -> 
    {s = \\cas => chelovek.s ! n ! (extCase cas) ;
     n = n ; g = chelovek.g ; p = P3 ; pron =False ;
     anim = chelovek.anim 
    } ;
  pron2NounPhrase : Pronoun -> Animacy -> NounPhrase = \ona, anim -> 
    {s = ona.s ; n = ona.n ; g = pgen2gen ona.g ; 
     pron = ona.pron; p = ona.p ; anim = anim } ;

  nameNounPhrase : ProperName -> NounPhrase = 
    \masha -> {s = \\c => masha.s ! (extCase c) ; 
      p = P3; g = masha.g ; anim = masha.anim ; 
      n = Sg; nComp = Sg; pron = False} ;


--2 Determiners
--
-- Determiners (only determinative pronouns in Russian) are inflected 
-- according to the gender of nouns they determine.
-- The determined noun has the case parameter specific for the determiner:

  Determiner : Type = Adjective ** { n: Number; c : Case } ;

  anyPlDet = kakojNibudDet ** {n = Pl;  c= Nom} ; 

  detNounPhrase : Determiner -> CommNounPhrase -> NounPhrase = \kazhduj, okhotnik -> 
    {s = \\c => case kazhduj.c of {
       Nom => 
        kazhduj.s ! AF (extCase c) okhotnik.anim (gNum okhotnik.g kazhduj.n) ++ 
         okhotnik.s ! kazhduj.n ! (extCase c) ; 
       _ => 
        kazhduj.s ! AF (extCase c) okhotnik.anim (gNum okhotnik.g kazhduj.n) ++ 
         okhotnik.s ! kazhduj.n ! kazhduj.c };
     n = kazhduj.n ; 
     p = P3 ;
     pron = False;
     g = okhotnik.g ;
     anim = okhotnik.anim 
    } ;

  indefNounPhrase : Number -> CommNounPhrase -> NounPhrase = \n,mashina -> 
    {s = \\c =>  mashina.s ! n !  (extCase c) ;
     n = n ; p = P3 ; g = mashina.g ; anim = mashina.anim ; 
     pron = False
    } ;

  defNounPhrase : Number -> CommNounPhrase -> NounPhrase = \n,mashina -> 
    { s = \\c => mashina.s ! n ! (extCase c) ; 
     n = n ; p = P3 ; g = mashina.g ;anim = mashina.anim ;  pron = False } ;

-- Genitives of noun phrases can be used like determiners, 
-- to build noun phrases.
-- The number argument makes the difference between "мой дом" - "мои дома".
--
-- The variation like in "the car of John / John's car" in English is
-- not equally natural for proper names and pronouns and the rest of nouns.
-- Compare "дверца машины" and "машины дверца", while 
-- "Ванина мама" and "мама Вани" or "моя мама" and "мама моя".
-- Here we have to make a choice of a universal form, which will be
-- "моя мама" - "Вани мама" - "машины дверца", which sounds
-- the best for pronouns, a little worse for proper names and 
-- the worst for the rest of nouns. The reason is the fact that 
-- possession/genetive is more a human category and pronouns are 
-- used very often, so we try to suit this case in the first place.

  npGenDet : Number -> NounPhrase -> CommNounPhrase -> NounPhrase = 
    \n,masha,mashina -> 
      {s = \\c => case masha.pron of 
           { True =>  masha.s ! (mkPronForm Nom No (Poss (gNum mashina.g n))) ++ 
                   mashina.s ! n ! (extCase c)  ;
             False => masha.s ! (mkPronForm Gen No (Poss (gNum mashina.g n))) ++ 
                   mashina.s ! n ! (extCase c)  
           } ;
       n = n ; p = P3 ;  g = mashina.g ; anim = mashina.anim ; pron = False
      } ;

--2 Adjectives
--3 Simple adjectives
--
-- A special type of adjectives just having positive forms 
-- (for semantic reasons)  is useful, e.g. "русский".
 
oper 

  extAdjective : AdjDegr -> Adjective = \adj ->
    { s = \\af => adj.s ! Pos ! af } ;

  -- Coercions between the compound gen-num type and gender and number:

  gNum : Gender -> Number -> GenNum = \g,n -> 
    case n of {Sg => case g of 
                 { Fem => ASg Fem ;
                   Masc => ASg Masc ;
                   Neut => ASg Neut 
                   -- _  => variants {ASg Masc ; ASg Fem}
                   } ; Pl => APl} ;



--3 Adjective phrases
-- 
-- An adjective phrase may contain a complement, e.g. "моложе Риты".
-- Then it is used as postfix in modification, e.g. "человек, моложе Риты".

  IsPostfixAdj = Bool ;

  AdjPhrase : Type = Adjective ** {p : IsPostfixAdj} ;

-- Simple adjectives are not postfix:

  adj2adjPhrase : Adjective -> AdjPhrase = \novuj -> novuj ** {p = False} ;

--3 Comparison adjectives
--
-- Each of the comparison forms has a characteristic use:
--
-- Positive forms are used alone, as adjectival phrases ("большой").

  positAdjPhrase : AdjDegr -> AdjPhrase = \bolshoj -> 
    adj2adjPhrase (extAdjective bolshoj) ;

-- Comparative forms are used with an object of comparison, as
-- adjectival phrases ("больше тебя").

  comparAdjPhrase : AdjDegr -> NounPhrase -> AdjPhrase = \bolshoj, tu ->
    {s = \\af => bolshoj.s ! Comp ! af ++ tu.s ! (mkPronForm Gen Yes NonPoss) ; 
     p = True
    } ;

-- Superlative forms are used with a modified noun, picking out the
-- maximal representative of a domain ("самый большой дом").

  superlNounPhrase : AdjDegr -> CommNounPhrase -> NounPhrase = \bolshoj, dom ->
    {s = \\pf => bolshoj.s ! Super ! AF (extCase pf) dom.anim (gNum dom.g Sg) ++ 
         dom.s  ! Sg ! (extCase pf) ; 
     n = Sg ;
     p = P3 ;
     pron = False;
     anim = dom.anim ;
     g = dom.g
    } ;


--3 Two-place adjectives
--
-- A two-place adjective is an adjective with a preposition used before
-- the complement. (Rem. $Complement =  {s2 : Preposition ; c : Case} $).

  
  AdjCompl = Adjective ** Complement ;

  complAdj : AdjCompl -> NounPhrase -> AdjPhrase = \vlublen,tu ->
    {s = \\af => vlublen.s ! af ++ vlublen.s2 ++ 
          tu.s ! (mkPronForm vlublen.c No NonPoss) ;
     p = True
    } ;

--3 Complements
--

  Complement =  {s2 : Preposition ; c : Case} ;

  complement : Str -> Complement = \cherez ->
    {s2 = cherez ; c = Nom} ;

  complementDir : Complement = complement [] ;

  complementCas : Case -> Complement = \c ->
    {s2 = [] ; c = c} ;

--2 Individual-valued functions

-- An individual-valued function is a common noun together with the
-- preposition prefixed to its argument ("ключ от дома").
-- The situation is analogous to two-place adjectives and transitive verbs.
--
-- We allow the genitive construction to be used as a variant of
-- all function applications. It would definitely be too restrictive only
-- to allow it when the required case is genitive. We don't know if there
-- are counterexamples to the liberal choice we've made.

  Function = CommNounPhrase ** Complement ;


-- The application of a function gives, in the first place, a common noun:
-- "ключ от дома". From this, other rules of the resource grammar 
-- give noun phrases, such as "ключи от дома", "ключи от дома
-- и от машины", and "ключ от дома и машины" (the
-- latter two corresponding to distributive and collective functions,
-- respectively). Semantics will eventually tell when each
-- of the readings is meaningful.

  appFunComm : Function -> NounPhrase -> CommNounPhrase = \mama,ivan -> 
     {s = \\n, cas => 
         mama.s ! n ! cas ++ mama.s2 ++ 
         ivan.s ! (mkPronForm mama.c No (Poss (gNum mama.g n)));
       g = mama.g ;
       anim = mama.anim
      } ;

-- It is possible to use a function word as a common noun; the semantics is
-- often existential or indexical.

  funAsCommNounPhrase : Function -> CommNounPhrase = \x -> x ;

  mkFun : CommNoun -> Preposition -> Case -> Function = \f,p,c ->
    (n2n f) ** {s2 = p ; c = c} ;

-- The following is an aggregate corresponding to the original function application
-- producing "детство Ивана" and "Иваново детство". It does not appear in the
-- resource abstract syntax any longer.
-- Both versions return "детсво Ивана" although "Иваново детство"
-- must also be included 
-- Such possesive form is only possible with proper names in Russian :

  appFun : Bool -> Function -> NounPhrase -> NounPhrase = \coll,detstvo, ivan -> 
    let {n = ivan.n ; nf = if_then_else Number coll Sg n} in 
    variants {
      defNounPhrase nf (appFunComm detstvo ivan) ; -- detstvoIvana
      npGenDet nf ivan detstvo
      } ;


-- The commonest cases are functions with Genitive.

  funGen : CommNoun -> Function = \urovenCen -> 
    mkFun urovenCen [] Gen ;

--3 Modification of common nouns
--
-- The two main functions of adjective are in predication ("Иван - молод")
-- and in modification ("молодой человек"). Predication will be defined
-- later, in the chapter on verbs.

  modCommNounPhrase : AdjPhrase -> CommNounPhrase -> CommNounPhrase = 
    \khoroshij,novayaMashina ->
    {s = \\n, c => 
         khoroshij.s ! AF c novayaMashina.anim (gNum novayaMashina.g n) ++ 
         novayaMashina.s ! n ! c ;
         g = novayaMashina.g ; 
         anim = novayaMashina.anim
     } ;                          

--2 Verbs

--3 Transitive verbs
--
-- Transitive verbs are verbs with a preposition for the complement,
-- in analogy with two-place adjectives and functions.
-- One might prefer to use the term "2-place verb", since
-- "transitive" traditionally means that the inherent preposition is empty
-- and the case is accusative. 
-- Such a verb is one with a *direct object*.
-- Note: Direct verb phrases where the Genitive case is also possible 
-- ("купить хлеба", "не читать газет") are overlooked in mkDirectVerb
-- and can be expressed via more a general rule mkTransVerb.

  TransVerb : Type = Verb ** {s2 : Preposition ; c: Case } ; 

  complementOfTransVerb : TransVerb -> Complement = \v -> {s2 = v.s2 ; c = v.c} ;
  verbOfTransVerb       : TransVerb -> Verb   = \v -> 
    {s = v.s; t = v.t; a = v.a ; w = v.w } ;

  mkTransVerb : Verb -> Preposition  -> Case -> TransVerb = \v,p,cas -> 
    v ** {s2 = p ; c = cas } ;

  mkDirectVerb : Verb -> TransVerb = \v -> 
    mkTransVerb v nullPrep Acc;

  nullPrep : Preposition = [] ;

-- The rule for using transitive verbs is the complementization rule:

  complTransVerb : Bool -> TransVerb -> NounPhrase -> VerbPhrase = \b,se,tu ->
    {s = se.s ; a = se.a ; t = se.t ; w = se.w ; s2 = negation b ;
     s3 = \\_,_ => se.s2 ++ tu.s ! (mkPronForm se.c No NonPoss) ; 
     negBefore = True } ;

--3 Verb phrases
--
-- Verb phrases are discontinuous: the parts of a verb phrase are
-- (s) an inflected verb, (s2) verb adverbials (such as negation), and
-- (s3) complement. This discontinuity is needed in sentence formation
-- to account for word order variations.

  VerbPhrase : Type = Verb ** {s2 : Str ; s3 : Gender => Number => Str ;
    negBefore: Bool} ;

-- A simple verb can be made into a verb phrase with an empty complement.
-- There are two versions, depending on if we want to negate the verb.

  predVerb : Bool -> Verb -> VerbPhrase = \b,vidit -> 
    vidit ** {
     s2 = negation b ; 
     s3 = \\_,_ => [] ;
     negBefore = True
     } ;

  negation : Bool -> Str = \b -> if_then_else Str b [] "не" ; 

-- Sometimes we want to extract the verb part of a verb phrase.

  verbOfPhrase : VerbPhrase -> Verb = \v -> 
    {s = v.s; t = v.t ; a = v.a ; w =v.w} ;


-- Verb phrases can also be formed from adjectives ("- молод"),
-- common nouns ("- человек"), and noun phrases ("- самый молодой").
-- The third rule is overgenerating: "- каждый человек" has to be ruled out
-- on semantic grounds.
-- Note: in some case we can even omit a dash "-"  :
-- "Я думаю, что это хорошая машина".

  predAdjective : Bool -> Adjective -> VerbPhrase = \b,zloj ->
    { s= \\_ => "-" ;        
      t = Present ; 
      a = Imperfective ;
      w = Act ;
      s2 = negation b ; 
      s3 = \\g,n => case n of {
          Sg => zloj.s ! AF Nom Animate (ASg g) ;
          Pl => zloj.s ! AF Nom Animate APl  
          } ;
     negBefore = False
    } ;

  predCommNoun : Bool -> CommNounPhrase -> VerbPhrase = \b,chelovek ->
   {  s= \\_ => "-" ;        
      t = Present ; 
      a = Imperfective ;
      w = Act ;
      s2 = negation b ;
      s3 = \\_,n => (indefNounPhrase n chelovek ).s ! (mkPronForm Nom No NonPoss) ;
      negBefore = False
     } ;

  predNounPhrase : Bool -> NounPhrase -> VerbPhrase = \b,masha ->
    { s= \\_ => "-" ;        
      t = Present ; 
      a = Imperfective ;
      w = Act ;
      s2 = negation b ;
      s3 = \\_,_ => masha.s ! (mkPronForm Nom No NonPoss) ;
      negBefore = False
    } ;

  -- A function specific for Russian :
  predNeedShortAdjective: Bool -> NounPhrase -> CommNounPhrase -> Sentence = 
     \ b, Jag, Dig -> { s =
    let {
      mne  = Jag.s ! (mkPronForm Dat No NonPoss) ; 
      nuzhen  = need.s ! AF Nom Inanimate (gNum Dig.g Sg)  ;
      doctor = Dig.s ! Sg ! Nom ;
      ne = negation b
    } in
       mne ++ ne ++ nuzhen ++ doctor 
    } ;

--2 Adverbials
--
  adVerbPhrase : VerbPhrase -> Adverb -> VerbPhrase = \poet, khorosho ->
    {s = \\vf => khorosho.s ++ poet.s ! vf ; s2 = poet.s2; s3 = poet.s3;
     a = poet.a; w = poet.w; t = poet.t ; negBefore = poet.negBefore } ;
                   
-- Adverbials are typically generated by prefixing prepositions.
-- The rule for creating locative noun phrases by the preposition "в"
-- is a little shaky: "в России" but "на острове".

  locativeNounPhrase : NounPhrase -> Adverb = \ivan ->
    {s = "в" ++ ivan.s ! (mkPronForm Prepos Yes NonPoss) } ;

-- This is a source of the "man with a telescope" ambiguity, and may produce
-- strange things, like "машины всегда".
-- Semantics will have to make finer distinctions among adverbials.

  advCommNounPhrase : CommNounPhrase -> Adverb -> CommNounPhrase = \chelovek,uTelevizora ->
    {s = \\n,c => chelovek.s ! n ! c ++ uTelevizora.s ;
     g = chelovek.g ;
     anim = chelovek.anim 
    } ;


--2 Sentences
--
-- We do not introduce the word order parameter for sentences in Russian
-- although there exist several word orders, but they are too specific
-- to capture on the level we work here. 

oper
   Sentence : Type = { s : Str } ;

-- This is the traditional $S -> NP VP$ rule. 

    predVerbPhrase : NounPhrase -> VerbPhrase -> Sentence = 
    \Ya, tebyaNeVizhu -> { s =
       let 
       { ya = Ya.s ! (mkPronForm Nom No NonPoss);
         ne = tebyaNeVizhu.s2;
         vizhu = tebyaNeVizhu.s ! VFin (gNum Ya.g Ya.n) Ya.p;
         tebya = tebyaNeVizhu.s3 ! Ya.g ! Ya.n 
       }
       in
       if_then_else Str tebyaNeVizhu.negBefore  
        (ya ++ ne ++ vizhu ++ tebya)
        (ya ++ vizhu ++ ne ++ tebya)
       
    } ;

  -- A function specific for Russian: 
  U_predTransVerb : Bool -> TransVerb -> NounPhrase -> NounPhrase -> Sentence = 
    \b,Ser,Jag,Dig -> { s =
    let {
      menya  =  Jag.s ! (mkPronForm Gen Yes NonPoss) ; 
      bolit  = Ser.s ! VFin (gNum Dig.g Dig.n) Dig.p ;
      golova = Dig.s ! (mkPronForm Nom No NonPoss) ;
      ne = negation b
    } in
       "у" ++ menya ++ ne ++ bolit  ++ golova 
    } ;


-- This is a macro for simultaneous predication and complementation.

  predTransVerb : Bool -> TransVerb -> NounPhrase -> NounPhrase -> Sentence = 
    \b,vizhu,ya,tu -> predVerbPhrase ya (complTransVerb b vizhu tu) ;
 
--3 Sentence-complement verbs
--
-- Sentence-complement verbs take sentences as complements.

  SentenceVerb : Type = Verb ;

-- To generate "сказал, что Иван гуляет" / "не сказал, что Иван гуляет":

  complSentVerb : Bool -> SentenceVerb -> Sentence -> VerbPhrase = 
    \b,vidit,tuUlubaeshsya ->
    {s = vidit.s ; s2 = negation b ; s3 = \\_,_ => [", что"] ++ 
     tuUlubaeshsya.s ;
     t = vidit.t ; w = vidit.w ; a = vidit.a ; negBefore = True } ;


--2 Sentences missing noun phrases
--
-- This is one instance of Gazdar's *slash categories*, corresponding to his
-- $S/NP$.
-- We cannot have - nor would we want to have - a productive slash-category former.
-- Perhaps a handful more will be needed.
--
-- Notice that the slash category has the same relation to sentences as
-- transitive verbs have to verbs: it's like a *sentence taking a complement*.

  SentenceSlashNounPhrase = Sentence ** Complement ;

  slashTransVerb : Bool -> NounPhrase -> TransVerb -> SentenceSlashNounPhrase = 
    \b,ivan,lubit ->
    predVerbPhrase ivan (predVerb b (verbOfTransVerb lubit)) ** 
    complementOfTransVerb lubit ;


--2 Coordination
--
-- Coordination is to some extent orthogonal to the rest of syntax, and
-- has been treated in a generic way in the module $CO$ in the file
-- $coordination.gf$. The overall structure is independent of category,
-- but there can be differences in parameter dependencies.
--
--3 Conjunctions
--
-- Coordinated phrases are built by using conjunctions, which are either
-- simple ("и", "или") or distributed ("как - так", "либо - либо").
--
-- The conjunction has an inherent number, which is used when conjoining
-- noun phrases: "Иван и Маша поют" vs. "Иван или Маша поет"; in the
-- case of "или", the result is however plural if any of the disjuncts is.

  Conjunction = CO.Conjunction ** {n : Number} ;
  ConjunctionDistr = CO.ConjunctionDistr ** {n : Number} ;

--2 Relative pronouns and relative clauses
--

oper
  identRelPron : RelPron = { s  = \\gn, c, anim => 
     kotorujDet.s ! (AF c anim gn )} ;

  funRelPron : Function -> RelPron -> RelPron = \mama, kotoruj -> 
    {s = \\gn,c, anim => let {nu = numGNum gn} in
           mama.s ! nu ! c ++  
           mama.s2 ++ kotoruj.s !  gn ! mama.c ! anim
    } ;

-- Relative clauses can be formed from both verb phrases ("видит Машу") and
-- slash expressions ("я вижу"). 

  RelClause : Type = RelPron ;

  relVerbPhrase : RelPron -> VerbPhrase -> RelClause = \kotoruj, gulyaet ->
    { s = \\gn, c, anim =>  let { nu = numGNum gn } in
      kotoruj.s ! gn ! c ! anim ++ gulyaet.s2 ++ gulyaet.s ! VFin gn P3 ++ 
       gulyaet.s3 ! genGNum gn ! nu
    } ;

  relSlash : RelPron -> SentenceSlashNounPhrase -> RelClause = 
   \kotoruj, yaVizhu ->
    {s = \\gn, _ , anim => yaVizhu.s2 ++ kotoruj.s ! gn ! yaVizhu.c ! anim 
         ++ yaVizhu.s 
    } ;

-- A 'degenerate' relative clause is the one often used in mathematics, e.g.
-- "число x, такое что x - четное".

  relSuch : Sentence -> RelClause = \A ->
    {s = \\gn,c, anim => takoj.s ! AF c anim gn ++ "что" ++ A.s } ;

-- The main use of relative clauses is to modify common nouns.
-- The result is a common noun, out of which noun phrases can be formed
-- by determiners. A comma is used before the relative clause.

  modRelClause : CommNounPhrase -> RelClause -> CommNounPhrase = 
    \chelovek,kotorujSmeetsya ->
    { s = \\n,c => chelovek.s ! n ! c ++ "," ++ 
           kotorujSmeetsya.s ! gNum chelovek.g n ! Nom ! chelovek.anim;
      g = chelovek.g ;
      anim = chelovek.anim
    } ;


--2 Interrogative pronouns
--
-- If relative pronouns are adjective-like, interrogative pronouns are
-- noun-phrase-like. Actually we can use the very same type!

  IntPron : Type = NounPhrase ; 

-- In analogy with relative pronouns, we have a rule for applying a function
-- to a relative pronoun to create a new one. We can reuse the rule applying
-- functions to noun phrases!

  funIntPron : Function -> IntPron -> IntPron = 
    appFun False ; 

-- There is a variety of simple interrogative pronouns:
-- "какая машина", "кто", "что".

  nounIntPron : Number -> CommNounPhrase -> IntPron = \n, x ->
    detNounPhrase (kakojDet ** {n = n;  c= Nom}) x ;

  intPronKto : Number -> IntPron = \num -> 
  { s = table {
    PF Nom _ _ => "кто"  ; 
    PF Gen _ _ => "кого" ;
    PF Dat _  _ => "кому" ; 
    PF Acc _ _ => "кого" ; 
    PF Inst _ _ => "кем" ;
    PF Prepos _ _ => ["о ком"] 
    } ;
    g = Masc ;
    anim = Animate ;
    n = num ;
    p = P3  ;
    pron = False
  } ;
 


  intPronChto : Number -> IntPron = \num -> 
  { s = table {
    PF Nom _ _ => "что"  ; 
    PF Gen _ _ => "чего" ;
    PF Dat _ _ => "чему" ; 
    PF Acc _ _ => "что" ; 
    PF Inst _ _ => "чем" ;
    PF Prepos _ _=> ["о чем"] 
    } ;
    g = Neut ;
    anim = Inanimate ;
    n = num ;
    p = P3  ;
    pron = False
  } ;


--2 Utterances

-- By utterances we mean whole phrases, such as 
-- 'can be used as moves in a language game': indicatives, questions, imperative,
-- and one-word utterances. The rules are far from complete.
--
-- N.B. we have not included rules for texts, which we find we cannot say much
-- about on this level. In semantically rich GF grammars, texts, dialogues, etc, 
-- will of course play an important role as categories not reducible to utterances.
-- An example is proof texts, whose semantics show a dependence between premises
-- and conclusions. Another example is intersentential anaphora.

  Utterance = SS ;

  indicUtt : Sentence -> Utterance = \x -> postfixSS "." (defaultSentence x) ;
  interrogUtt : Question -> Utterance = \x -> postfixSS "?" (defaultQuestion x) ;

--2 Questions
--
-- Questions are either direct ("Ты счастлив?") 
-- or indirect ("Потом он спросил счастлив ли ты").

param 
  QuestForm = DirQ | IndirQ ;

oper
  Question = SS1 QuestForm ;

--3 Yes-no questions 
--
-- Yes-no questions are used both independently ("Ты взял мяч?")
-- and after interrogative adverbials ("Почему ты взял мяч?").

-- Note: The particle "ли" can also be used in direct questions:
-- Видел ли ты что-нибудь подобное?
-- but we are not considering this case.

  questVerbPhrase : NounPhrase -> VerbPhrase -> Question = 
  \tu,spish -> 
    let { vu = tu.s ! (mkPronForm Nom No NonPoss); 
         spish = spish.s ! VFin (gNum tu.g tu.n) tu.p 
              ++ spish.s2 ++ spish.s3 ! tu.g ! tu.n } in
     { s = table {
       DirQ   =>  vu ++ spish  ;
       IndirQ => spish ++ "ли" ++ vu 
      }
    } ;

--3 Wh-questions
--
-- Wh-questions are of two kinds: ones that are like $NP - VP$ sentences,
-- others that are like $S/NP - NP$ sentences.

  intVerbPhrase : IntPron -> VerbPhrase -> Question = \kto,spit ->
    {s = table { _  => (predVerbPhrase kto spit).s }
    } ;

  intSlash : IntPron -> SentenceSlashNounPhrase -> Question = \Kto, yaGovoru ->
    let {  kom = Kto.s ! (mkPronForm yaGovoru.c No NonPoss) ; o = yaGovoru.s2 } in
    {s = table {  _ => o ++ kom ++ yaGovoru.s  } 
    } ;

--3 Interrogative adverbials
--
-- These adverbials will be defined in the lexicon: they include
-- "когда", "где", "как", "почему", etc, which are all invariant one-word
-- expressions. In addition, they can be formed by adding prepositions
-- to interrogative pronouns, in the same way as adverbials are formed
-- from noun phrases. N.B. we rely on record subtyping when ignoring the
-- position component.

  IntAdverb = SS ;

-- A question adverbial can be applied to anything, and whether this makes
-- sense is a semantic question.

  questAdverbial : IntAdverb -> NounPhrase -> VerbPhrase -> Question = 
    \kak, tu, pozhivaesh ->
    {s = \\q => kak.s ++ tu.s ! (mkPronForm Nom No NonPoss) ++ 
       pozhivaesh.s2 ++ pozhivaesh.s ! VFin (gNum tu.g tu.n) tu.p ++ 
       pozhivaesh.s3 ! tu.g ! tu.n } ; 
 
--2 Imperatives
--
-- We only consider second-person imperatives. 

  Imperative: Type = { s: Gender => Number => Str } ;

  imperVerbPhrase : VerbPhrase -> Imperative = \budGotov -> 
    {s = \\g, n => budGotov.s ! VImper n P2 ++ budGotov.s2 ++ budGotov.s3 ! g ! n} ;  

  imperUtterance : Gender -> Number -> Imperative -> Utterance = \g,n,I ->
    ss (I.s ! g ! n ++ "!") ;

--3 Coordinating sentences
--
-- We need a category of lists of sentences. It is a discontinuous
-- category, the parts corresponding to 'init' and 'last' segments
-- (rather than 'head' and 'tail', because we have to keep track of the slot between
-- the last two elements of the list). A list has at least two elements.

  ListSentence : Type = SD2 ;

  twoSentence : (_,_ : Sentence) -> ListSentence = CO.twoSS ;

  consSentence : ListSentence -> Sentence -> ListSentence =
    CO.consSS CO.comma ;

-- To coordinate a list of sentences by a simple conjunction, we place
-- it between the last two elements; commas are put in the other slots,
-- e.g. "ты куришь, вы пьете и я ем".

  conjunctSentence : Conjunction -> ListSentence -> Sentence = \c,xs ->
    ss (CO.conjunctX c xs) ;

-- To coordinate a list of sentences by a distributed conjunction, we place
-- the first part (e.g. "как") in front of the first element, the second
-- part ("так и") between the last two elements, and commas in the other slots.
-- For sentences this is really not used.

  conjunctDistrSentence : ConjunctionDistr -> ListSentence -> Sentence = 
    \c,xs ->
    ss (CO.conjunctDistrX c xs) ;

--3 Coordinating adjective phrases
--
-- The structure is the same as for sentences. The result is a prefix adjective
-- if and only if all elements are prefix.

  ListAdjPhrase : Type = 
    {s1,s2 : AdjForm => Str ; p : Bool} ;

  twoAdjPhrase : (_,_ : AdjPhrase) -> ListAdjPhrase = \x,y ->
    CO.twoTable AdjForm x y ** {p = andB x.p y.p} ;

  consAdjPhrase : ListAdjPhrase -> AdjPhrase -> ListAdjPhrase =  \xs,x ->
    CO.consTable AdjForm CO.comma xs x ** {p = andB xs.p x.p} ;

  conjunctAdjPhrase : Conjunction -> ListAdjPhrase -> AdjPhrase = \c,xs ->
    CO.conjunctTable AdjForm c xs ** {p = xs.p} ;

  conjunctDistrAdjPhrase : ConjunctionDistr -> ListAdjPhrase -> AdjPhrase = \c,xs ->
    CO.conjunctDistrTable AdjForm c xs ** {p = xs.p} ;


--3 Coordinating noun phrases
--
-- The structure is the same as for sentences. The result is either always plural
-- or plural if any of the components is, depending on the conjunction.

  ListNounPhrase : Type = { s1,s2 : PronForm => Str ; g: Gender ; 
                   anim : Animacy ; n : Number ; p : Person ;  pron : Bool } ;

  twoNounPhrase : (_,_ : NounPhrase) -> ListNounPhrase = \x,y ->
    CO.twoTable PronForm x y ** {n = conjNumber x.n y.n ; 
       g = conjGender x.g y.g ; p = conjPerson x.p y.p ;
       pron = conjPron x.pron y.pron ; anim = conjAnim x.anim y.anim } ;

  consNounPhrase : ListNounPhrase -> NounPhrase -> ListNounPhrase =  \xs,x ->
    CO.consTable PronForm CO.comma xs x ** 
       {n = conjNumber xs.n x.n ; g = conjGender x.g xs.g ;
          anim = conjAnim x.anim xs.anim ;
          p = conjPerson xs.p x.p; pron = conjPron xs.pron x.pron} ;

  conjunctNounPhrase : Conjunction -> ListNounPhrase -> NounPhrase = \c,xs ->
    CO.conjunctTable PronForm c xs ** {n = conjNumber c.n xs.n ;
      anim = xs.anim ;
       p = xs.p; g = xs.g ; pron = xs.pron} ;

  conjunctDistrNounPhrase : ConjunctionDistr -> ListNounPhrase -> NounPhrase = 
    \c,xs ->
    CO.conjunctDistrTable PronForm c xs ** {n = conjNumber c.n xs.n ; 
      p = xs.p ; pron = xs.pron ; anim = xs.anim ; 
       g = xs.g } ;

-- We have to define a calculus of numbers of persons. For numbers,
-- it is like the conjunction with $Pl$ corresponding to $False$.

  conjNumber : Number -> Number -> Number = \m,n -> case <m,n> of {
    <Sg,Sg> => Sg ;
    _ => Pl 
    } ;

-- For persons, we let the latter argument win ("либо ты, либо я пойду"
-- but "либо я, либо ты пойдешь"). This is not quite clear.

  conjPerson : Person -> Person -> Person = \_,p -> 
    p ;

-- For pron, we let the latter argument win - "Маша или моя мама" (Nominative case)
-- but - "моей или Машина мама" (Genetive case) both corresponds to 
-- "Masha's or my mother"), which is actually not exactly correct, since
-- different cases should be used - "Машина или моя мама".

  conjPron : Bool -> Bool -> Bool = \_,p -> 
    p ;

-- For gender in a similar manner as for person:
-- Needed for adjective predicates like:
-- "Маша или Оля - красивая", "Антон или Олег - красивый",
-- "Маша или Олег - красивый".
-- The later is not totally correct, but there is no correct way to say that.

  conjGender : Gender -> Gender -> Gender = \_,m -> m ; 

  conjAnim : Animacy -> Animacy -> Animacy = \_,m -> m ; 

--2 Subjunction
--
-- Subjunctions ("когда", "если", etc) 
-- are a different way to combine sentences than conjunctions.
-- The main clause can be a sentence, an imperative, or a question,
-- but the subjoined clause must be a sentence.
--
-- There are uniformly two variant word orders, e.g. 
-- "если ты закуришь, я рассержусь"
-- and "я рассержусь, если ты закуришь".

  Subjunction = SS ;

  subjunctSentence : Subjunction -> Sentence -> Sentence -> Sentence = 
    \if, A, B -> 
    ss (subjunctVariants if A.s B.s) ;

  subjunctImperative : Subjunction -> Sentence -> Imperative -> Imperative = 
    \if, A, B -> 
    {s = \\g,n => subjunctVariants if A.s (B.s ! g ! n)} ;

  subjunctQuestion : Subjunction -> Sentence -> Question -> Question = 
    \if, A, B ->
    {s = \\q => subjunctVariants if A.s (B.s ! q)} ;

  subjunctVariants : Subjunction -> Str -> Str -> Str = \if,A,B ->
    variants {if.s ++ A ++ "," ++ B ; B ++ "," ++ if.s ++ A} ;

--2 One-word utterances
-- 
-- An utterance can consist of one phrase of almost any category, 
-- the limiting case being one-word utterances. These
-- utterances are often (but not always) in what can be called the
-- default form of a category, e.g. the nominative.
-- This list is far from exhaustive.

  useNounPhrase : NounPhrase -> Utterance = \masha ->
    postfixSS "." (defaultNounPhrase masha) ;

  useCommonNounPhrase : Number -> CommNounPhrase -> Utterance = \n,mashina -> 
    useNounPhrase (indefNounPhrase n mashina) ;

  useRegularName : Gender -> SS -> NounPhrase = \g, masha -> 
    nameNounPhrase (case g of { Masc => mkProperNameMasc masha.s Animate;
        _ => mkProperNameFem masha.s Animate }) ;

-- Here are some default forms.

  defaultNounPhrase : NounPhrase -> SS = \masha -> 
    ss (masha.s ! PF Nom No NonPoss) ;

  defaultQuestion : Question -> SS = \ktoTu ->
    ss (ktoTu.s ! DirQ) ;

  defaultSentence : Sentence -> Utterance = \x -> 
    x ;
};