summaryrefslogtreecommitdiff
path: root/examples/miniresource/MiniresourceSan.gf
blob: dbeecebf2c7947a39d0382dabf7c3e045f50c826 (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
concrete MiniresourceSan of Miniresource = open Prelude in {

-- module GrammarSan

  flags coding = utf8;

  lincat
    S  = {s : Str} ; 
    Cl = {s : Bool => Str} ; 
    NP = NounPhrase ;  
    VP = VerbPhrase ;  
    AP = Adj ;
    CN = Noun ;
    Det = {s : Gender => Case => Str ; n : Number} ;
    N = Noun ; 
    A = Adj ;
    V = Verb;
    V2 = Verb ** {c : Case} ;
    AdA = {s : Str} ; 
    Pol = {s : Str ; b : Bool} ;
    Tense = {s : Str} ;
    Conj = {s : Str} ;    


  lin

    UseCl t p cl = {s = t.s ++ p.s ++ cl.s ! p.b} ; 

    PredVP np vp = {
       s  = \\p => np.s ! Nom ++ neg p ++ vp.compl ! np.a ++ vp.verb.s ! VPres np.a.n np.a.p
       } ;

    ComplV2 v2 np = {
     verb  = v2 ;
     compl = \\_ => np.s ! v2.c
     } ; 

    UseV v = {
      verb = v ; 
      compl = \\_ => []
      } ; 

    DetCN det cn = {
      s = \\c => det.s ! cn.g ! c ++ cn.s ! det.n ! c ; 
      a = agr cn.g det.n P3
      } ;
      
    ModCN ap cn = {s = \\n,c => ap.s ! cn.g ! n ! c ++ cn.s ! n ! c ; g = cn.g} ;

    CompAP ap = {
      verb = copula ;
      compl = \\a => ap.s ! a.g ! a.n ! Nom 
      } ;

    AdAP ada ap = {
      s = \\g,n,c => ada.s ++ ap.s ! g ! n ! c
      } ;

    ConjNP co x y = {
      s = \\c => x.s ! c ++ co.s ++ y.s ! c ;
      a = y.a ----
      } ;

    ConjS  co x y = {s = x.s ++ co.s ++ y.s} ;  

    UseN n = n ;
    UseA adj = adj ;

    a_Det = mkDet "" Sg ;
    every_Det = mkDet "प्रति" Sg ;        
    the_Det = mkDet "" Sg ;

    this_Det = mkDet "एतद्" Sg ;
--    these_Det = mkDet "这" Pl ;
    that_Det = mkDet "तद्" Sg ;
--    those_Det = mkDet "那" Pl ;

    i_NP = pronNP "" Sg P1 ;
    youSg_NP = pronNP "" Sg P2 ;
    he_NP = pronNP "" Sg P3 ;
    she_NP = pronNP "" Sg P3 ;
    we_NP = pronNP "" Pl P1 ;
    youPl_NP = pronNP "" Pl P2 ;
    they_NP = pronNP "" Pl P3 ;

    very_AdA = ss "अति" ;    
    
    and_Conj = {s = " च"} ;

    or_Conj  = {s = "अथवा"} ;

    Pos  = {s = [] ; b = True} ;
    Neg  = {s = [] ; b = False} ;
    Pres = {s = []} ;
    Perf = {s = []} ;

-- module TestChi

lin
  man_N = mkN "नरः" ;  
  woman_N = mkN "स्त्री" ;
  house_N = mkN "गृहं" ;
  tree_N = mkN "वृक्ष";
  big_A = mkA "महाकाय" ;
  small_A = mkA "अल्प" ;
  green_A = mkA "हरित" ;
  walk_V = mkV "गम्" ;
  arrive_V = mkV "अभि-उपा-गम्" ;
  love_V2 = mkV2 "कम्" ;
  please_V2 = mkV2 "प्री" ;








-- module ResSan

-- parameters

param
    Number = Sg | Dl | Pl ;
    Case = Nom | Acc | Ins | Dat | Abl | Gen | Loc | Voc ;
    Gender = Masc | Fem | Neutr ;
    Person = P3 | P2 | P1 ;


    VForm = VPres Number Person ;

oper
    Agr = {g : Gender ; n : Number ; p : Person} ;

    agr : Gender -> Number -> Person -> Agr = \g,n,p -> {g = g ; n = n ; p = p} ;

-- parts of speech

oper

  VerbPhrase = {verb : Verb ; compl : Agr => Str} ;
  NounPhrase = {s : Case => Str ; a : Agr} ; 

-- for morphology

  Noun : Type = {s : Number => Case => Str; g : Gender} ;
  Adj  : Type = {s : Gender => Number => Case => Str} ;
  Verb : Type = {s : VForm => Str} ;

  mkNoun : (s1,_,_,_,_,_,_,_, _,_,_, _,_,_,_,_,s17 : Str) -> Gender -> Noun = 
    \snom,sacc,sins,sdat,sabl,sgen,sloc,svoc,
     dnomaccvoc,dinsdatabl,dgenloc,
     pnomvoc,pacc,pins,pdatabl,pgen,ploc, 
     gen -> {
      s = table {
        Sg => table {
           Nom => snom ; Acc => sacc ; Ins => sins ; Dat => sdat ; Abl => sabl ; Gen => sgen ; Loc => sloc ; Voc => svoc
           } ;
        Dl => table {
           Nom | Acc | Voc => dnomaccvoc ; Ins | Dat | Abl => dinsdatabl ; Gen | Loc => dgenloc 
           } ;
        Pl => table {
           Nom | Voc => pnomvoc ; Acc => pacc ; Ins => pins ; Dat | Abl => pdatabl ; Gen => pgen ; Loc => ploc
           }
        } ;
      g = gen
      } ;

  endingNoun : Str -> (s1,_,_,_,_,_,_,_, _,_,_, _,_,_,_,_,s17 : Str) -> Gender -> Noun = 
    \stem,
     snom,sacc,sins,sdat,sabl,sgen,sloc,svoc,
     dnomaccvoc,dinsdatabl,dgenloc,
     pnomvoc,pacc,pins,pdatabl,pgen,ploc, 
     gen -> 
       mkNoun
         (stem + snom) (stem + sacc) (stem + sins) (stem + sdat) (stem + sabl) (stem + sgen) (stem + sloc) (stem + svoc) 
         (stem + dnomaccvoc) (stem + dinsdatabl) (stem + dgenloc) 
         (stem + pnomvoc) (stem + pacc) (stem + pins) (stem + pdatabl) (stem + pgen) (stem + ploc) 
         gen ;


  ramaNoun : Str -> Noun = \rama ->
    let ram = init rama in
    endingNoun ram
      "ः" "म्" "ॆणॆ" "ाय" "ात्" "स्य" "ॆ" ""
      "ौ" "ाथ्याम्" "यो" 
      "ाः" "ान्" "ैः" "ेथयः" "ाणाम" "ेषु" 
      Masc ;

  mkAdj : (m,f,n : Noun) -> Adj = \m,f,n -> {s = table {Masc => m.s ; Fem => f.s ; Neutr => n.s}} ; 


  mkVerb : (s1,_,_,_,_,_,_,_,s9 : Str) -> Verb = 
    \s3,s2,s1,d3,d2,d1,p3,p2,p1 -> {
      s = table {
        VPres Sg P3 => s3 ;
        VPres Sg P2 => s2 ;
        VPres Sg P1 => s1 ;
        VPres Dl P3 => d3 ;
        VPres Dl P2 => d2 ;
        VPres Dl P1 => d1 ;
        VPres Pl P3 => p3 ;
        VPres Pl P2 => p2 ;
        VPres Pl P1 => p1
        }
      } ;

  endingVerb : Str -> (s1,_,_,_,_,_,_,_,s9 : Str) -> Verb = 
    \stem,s3,s2,s1,d3,d2,d1,p3,p2,p1 -> 
      mkVerb
        (stem + s3) (stem + s2) (stem + s1) (stem + d3) (stem + d2) (stem + d1) (stem + p3) (stem + p2) (stem + p1) ;

  patVerb : Str -> Verb = \pat ->
    endingVerb pat
      "ित" "िस" "िम" "तः" "थः" "ावः" "िनख़त" "थ" "ामः" ;

  copula : Verb = {s = \\_ => []} ;

  neg : Bool -> Str = \b -> case b of {True => [] ; False => "न"} ;


-- for structural words

  mkDet : Str -> Number -> {s : Gender => Case => Str ; n : Number} = \s,n -> {
    s = \\_,_ => s ;
    n = n
    } ;

  pronNP : (s : Str) -> Number -> Person -> NounPhrase = \s,n,p -> {
    s = \\_ => s ;
    a = agr Masc n p
    } ;
    


-- module ParadigmsSan

oper
  mkN = overload {
    mkN : (man : Str) -> N 
      = \s -> lin N (ramaNoun s) ;
    } ;  
      
  mkA : (small : Str) -> A 
      = \s -> let n = ramaNoun s in lin A (mkAdj n n n) ;
      
  mkV : (walk : Str) -> V 
      = \s -> lin V (patVerb s) ; 

  mkV2 = overload {
    mkV2 : (love : Str) -> V2 
      = \love -> lin V2 (mkV love ** {c = Acc}) ;
---    mkV2 : (love : V) -> V2 
---      = \love -> lin V2 love ;
   } ;

}