--# -path=.:../abstract:../common:../../prelude -- --1 Nep auxiliary operations. -- by Dinesh Simkhada and Shafqat Virk - 2011 -- -- This module contains operations that are needed to make the -- resource syntax work. resource ResNep = ParamX ** open Prelude, Predef in { flags optimize=all ; coding = utf8; param Case = Nom | Acc | Ins | Dat | Abl | Loc ; Gender = Masc | Fem ; NPerson = Pers1 | Pers2_L | Pers2_M | Pers2_H | Pers3_L | Pers3_M | Pers3_H ; Order = ODir | OQuest ; --2 For $Relative$ RAgr = RNoAg | RAg Agr ; RCase = RC Number Case ; -- for Numerial CardOrd = NCard | NOrd ; ------------------------------------------ --Verbs ------------------------------------------- VTense = NPresent | NPast PTypes | NFuture FTypes; PTypes = Simpl | Hab ; -- Unknown - Currently we didn't find the use of 'Unknown' type FTypes = Defin | NDefin ; VerbForm = VF VTense Aspect Polarity NPerson Number Gender | Root -- Root form, 'kha' is the root of 'khanu' | Inf -- Infinitive form 'khanau' | ProgRoot Aspect Number Gender | PVForm -- Partial verb form 'khan' is teh PVForm of 'khanu' | Imp ; -- Aspect Perfective and non-perfective Aspect = Perf | Imperf ; -- For distinguishing the type of noun -- Prefessions/Occupations, Humans all mapped to Living category NType = Living | NonLiving ; oper Noun = {s : Number => Case => Str ; g : Gender ; t : NType ; h : NPerson } ; Verb = {s : VerbForm => Str} ; Preposition = {s : Str}; Determiner = {s : Number => Gender => Str ; n : Number}; -- Nepali Adjectives npAdjective = {s : Number => Gender => Str} ; mkAdjnp : Str -> npAdjective = \str -> case str of { st + t@"त" + "ो" => mkAdj1 str str (st+t+"ा") ; -- No Fem for red [couple of places which takes Fem but no general rule] st + "ो" => mkAdj1 str (st+"ी") (st+"ा") ; _ => mkAdj1 str str str } ; mkAdj1 : (x1,_,x3 : Str) -> npAdjective = \sm, sf, smf -> { s = table { Sg => table { Masc => sm ; Fem => sf } ; Pl => table { Masc => smf ; Fem => smf } } }; -- Reflective Pronoun --eg. (i will do myself) -- Functions used at NounNep [TODO: inflection at morphological level and attach with VP might be good option] reflPron : Str ; reflPron = "आफैं" ; -- आफैं eko : Str ; eko = "एको" ; eko : Str ; eki = "एकी" ; eka : Str ; eka = "एका" ; sbvn : Str ; sbvn = "सबभन्दा" ; ---------------------------------------------------------- -- Grammar part ---------------------------------------------------------- param Agr = Ag Gender Number NPerson ; NPCase = NPC Case | NPObj | NPErg ; oper np2pronCase : (Case => Str) -> NPCase -> Agr -> Str = \ppf,npc,a -> case npc of { NPC c => ppf ! c ; NPObj => ppf ! Nom ; NPErg => ppf ! Ins --Nom ++ "ले" } ; toNP : (Case => Str) -> NPCase -> Str = \pn, npc -> case npc of { NPC c => pn ! c ; NPObj => pn ! Nom ; NPErg => pn ! Ins --Nom ++ "ले" } ; detcn2NP : (Determiner) -> Noun -> NPCase -> Number -> Str = \dt,cn,npc,nn -> case npc of { NPC c => dt.s ! dt.n ! Masc ++ cn.s ! nn ! c ; NPObj => dt.s ! dt.n ! Masc ++ cn.s ! nn ! Nom ; NPErg => dt.s ! dt.n ! Masc ++ cn.s ! nn ! Ins --Nom ++ "ले" } ; det2NP : (Determiner) -> NPCase -> Str = \dt,npc -> case npc of { NPC c => dt.s ! dt.n ! Masc ; NPObj => dt.s ! dt.n ! Masc ; NPErg => dt.s ! dt.n ! Masc ++ "ले" } ; ------------------------------------ -- Agreement transformations ------------------------------------ oper toAgr : Number -> NPerson -> Gender -> Agr = \n,p,g -> Ag g n p; fromAgr : Agr -> {n : Number ; p : NPerson ; g : Gender} = \a -> case a of { Ag g n p => {n = n ; p = p ; g = g} } ; conjAgr : Agr -> Agr -> Agr = \a0,b0 -> let a = fromAgr a0 ; b = fromAgr b0 in toAgr (conjNumber a.n b.n) b.p a.g; giveNumber : Agr -> Number = \a -> case a of { Ag _ n _ => n } ; giveGender : Agr -> Gender = \a -> case a of { Ag g _ _ => g } ; defaultAgr : Agr = agrP3 Masc Sg ; agrP3 : Gender -> Number -> Agr = \g,n -> Ag g n Pers3_L ; agrP1 : Gender -> Number -> Agr = \g,n -> Ag g n Pers1 ; personalAgr : Agr = agrP1 Masc Sg ; param CPolarity = CPos | CNeg Bool ; -- contracted or not oper contrNeg : Bool -> Polarity -> CPolarity = \b,p -> case p of { Pos => CPos ; Neg => CNeg b } ; NP : Type = {s : NPCase => Str ; a : Agr ; t : NType } ; param VPHTense = VPGenPres -- impf hum nahim "ी गो" | VPSmplPast --# notpresent -- impf Ta nahim "ी ौेनत" | VPFut --# notpresent -- fut na/nahim "ी सहालल गो" | VPPerfPres -- perf hum na/nahim "ी हावे गोने" | VPPerfPast --# notpresent -- perf Ta na/nahim "ी हाद गोने" | VPPerfFut --# notpresent | VPCondPres -- subj na "ी माय गो" | VPCondPast --# notpresent -- subj na "ी माय गो" ; VType = VIntrans | VTrans | VTransPost ; -- Tense defined for coupla case CTense = CPrsnt | CPast | CFuture ; oper objVType : VType -> NPCase = \vt -> case vt of { VTrans => NPObj ; _ => NPC Nom } ; VPH : Type = { s : VerbForm => {inf : Str} ; obj : {s : Str ; a : Agr} ; subj : VType ; comp : Agr => Str; inf : Str; ad : Str; embComp : Str ; } ; VPHSlash = VPH ** {c2 : Compl} ; Compl : Type = {s : Str ; c : VType} ; predV : Verb -> VPH = \verb -> {s = \\vf => case vf of { VF t a pl p n g => {inf = verb.s ! VF t a pl p n g } ; Root => {inf = verb.s ! Root } ; Inf => {inf = verb.s ! Inf } ; Imp => {inf = verb.s ! Imp } ; PVForm => {inf = verb.s ! PVForm } ; ProgRoot a n g => {inf = verb.s ! ProgRoot a n g } }; obj = {s = [] ; a = defaultAgr} ; subj = VIntrans ; inf = verb.s ! Inf; ad = []; embComp = []; comp = \\_ => [] } ; predVc : (Verb ** {c2,c1 : Str}) -> VPHSlash = \verb -> predV verb ** {c2 = {s = verb.c1 ; c = VTrans} } ; predAux : NType -> VPH =\ctype -> { s = \\vh => case vh of { VF NPresent _ pl p n g => case ctype of { Living => {inf = copulaPrLvng pl n p g } ; _ => {inf = copulaPrGen pl n p g } } ; VF (NPast _) _ pl p n g => {inf = copulaPsGen pl n p g } ; VF (NFuture _) _ pl p n g => {inf = copulaFtGen pl n p g } ; Root => { inf = ""} ; Inf=> {inf = ""} ; Imp => {inf = ""} ; ProgRoot a n g => {inf = "" } ; PVForm => {inf = ""} }; obj = {s = [] ; a = defaultAgr} ; subj = VIntrans ; inf = ""; ad = []; embComp = []; comp = \\_ => [] } ; predProg : VPH -> VPH = \verb -> { s = \\vh => case vh of { VF NPresent a pl p n g => {inf = (verb.s ! ProgRoot a n g).inf ++ copulaPrGen pl n p g} ; VF (NPast _) a pl p n g => {inf = (verb.s ! ProgRoot a n g).inf ++ copulaPsGen pl n p g} ; --# notpresent VF (NFuture _) a pl p n g => {inf = (verb.s ! ProgRoot a n g).inf ++ copulaFtGen pl n p g} ; --# notpresent Root => {inf = (verb.s ! Root).inf } ; Inf => {inf = (verb.s ! ProgRoot Imperf Sg Masc).inf } ; Imp => {inf = (verb.s ! Imp).inf } ; PVForm => {inf = (verb.s ! PVForm).inf } ; ProgRoot a n g => {inf = (verb.s ! ProgRoot a n g).inf } }; obj = verb.obj ; subj = VIntrans ; inf = verb.inf; ad = verb.ad; embComp = verb.embComp; comp = verb.comp } ; Clause : Type = {s : VPHTense => Polarity => Order => Str} ; -- TODO, ERGATIVE CASE FROM NOUN INFLETION [No Proper grammer resource found] mkClause : NP -> VPH -> Clause = \np,vp -> { s = \\vt,b,ord => let subjagr : NPCase * Agr = case vt of { VPSmplPast => case vp.subj of { VTrans => ; VTransPost => ; _ => } ; VPPerfPast => case vp.subj of { VTrans => ; VTransPost => ; _ => } ; _ => } ; subj = subjagr.p1 ; agr = subjagr.p2 ; n = (fromAgr agr).n; p = (fromAgr agr).p; g = (fromAgr agr).g; vps = case of { => vp.s ! VF NPresent Imperf Pos p n g ; => vp.s ! VF NPresent Imperf Neg p n g ; => vp.s ! VF (NFuture Defin) Imperf Pos p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Imperf Neg p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Imperf Pos p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Imperf Neg p n g ; --# notpresent => vp.s ! VF NPresent Perf Pos p n g ; => vp.s ! VF NPresent Perf Neg p n g ; => vp.s ! VF (NPast Simpl) Perf Pos p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Perf Neg p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Perf Pos p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Perf Neg p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Imperf Pos p n g ; => vp.s ! VF (NFuture Defin) Imperf Neg p n g ; => vp.s ! VF (NPast Hab) Perf Pos p n g ; --# notpresent => vp.s ! VF (NPast Hab) Perf Neg p n g --# notpresent } ; quest = case ord of { ODir => []; OQuest => "के" }; in quest ++ np.s ! subj ++ vp.ad ++ vp.obj.s ++ vp.comp ! np.a ++ vps.inf ++ vp.embComp --quest ++ np.s ! subj ++ vp.ad ++ vp.comp ! np.a ++ vp.obj.s ++ vps.inf ++ vp.embComp } ; mkSClause : Str -> Agr -> VPH -> Clause = \subj,agr,vp -> { s = \\t,b,ord => let n = (fromAgr agr).n; p = (fromAgr agr).p; g = (fromAgr agr).g; vps = case of { => vp.s ! VF NPresent Imperf Pos p n g ; => vp.s ! VF NPresent Imperf Neg p n g ; => vp.s ! VF (NFuture Defin) Imperf Pos p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Imperf Neg p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Imperf Pos p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Imperf Neg p n g ; --# notpresent => vp.s ! VF NPresent Perf Pos p n g ; => vp.s ! VF NPresent Perf Neg p n g ; => vp.s ! VF (NPast Simpl) Perf Pos p n g ; --# notpresent => vp.s ! VF (NPast Simpl) Perf Neg p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Perf Pos p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Perf Neg p n g ; --# notpresent => vp.s ! VF (NFuture Defin) Imperf Pos p n g ; => vp.s ! VF (NFuture Defin) Imperf Neg p n g ; => vp.s ! VF (NPast Hab) Perf Pos p n g ; --# notpresent => vp.s ! VF (NPast Hab) Perf Neg p n g --# notpresent } ; quest = case ord of { ODir => []; OQuest => "के" }; in quest ++ subj ++ vp.obj.s ++ vp.ad ++ vp.comp ! agr ++ vps.inf ++ vp.embComp --quest ++ subj ++ vp.ad ++ vp.comp ! agr ++ vp.obj.s ++ vps.inf ++ vp.embComp } ; insertObj : (Agr => Str) -> VPH -> VPH = \obj1,vp -> { s = vp.s ; obj = vp.obj ; subj = vp.subj ; inf = vp.inf; ad = vp.ad; embComp = vp.embComp; comp = \\a => vp.comp ! a ++ obj1 ! a } ; insertVV : {s:Agr => Str} -> VPH -> Str -> VPH -> VPH = \obj1,vp,emb,vp2 -> { s = vp.s ; obj = vp2.obj ; subj = vp.subj ; inf = vp.inf; ad = vp.ad; embComp = vp.embComp ++ emb; comp = \\a => obj1.s ! a ++ vp.comp ! a } ; insertObj2 : (Str) -> VPH -> VPH = \obj1,vp -> { s = vp.s; obj = vp.obj ; subj = vp.subj ; inf = vp.inf; ad = vp.ad; embComp = Prelude.glue vp.embComp obj1; comp = vp.comp } ; insertObjc : (Agr => Str) -> VPHSlash -> VPHSlash = \obj,vp -> insertObj obj vp ** {c2 = vp.c2} ; insertObjc2 : Str -> VPHSlash -> VPHSlash = \obj,vp -> insertObj2 obj vp ** {c2 = vp.c2} ; infVP : Bool -> VPH -> {s:Agr => Str} = \isAux,vp -> {s= \\a => vp.obj.s ++ (vp.s ! PVForm).inf ++ vp.comp ! a }; infVV : VPH -> {s:Agr => Str} = \vp -> { s = \\ agr => vp.comp ! agr ++ (vp.s ! PVForm).inf } ; infV2V : VPH -> {s :Agr => Str} = \vp -> { s = \\agr => vp.comp ! agr ++ (vp.s ! PVForm).inf -- ++ "लाइ" } ; insertObject : NP -> VPHSlash -> VPH = \np,vps -> { s = vps.s ; obj = {s = np.s ! objVType vps.c2.c ++ vps.c2.s ++ vps.obj.s ; a = np.a} ; subj = vps.c2.c ; inf = vps.inf; ad = vps.ad; embComp = vps.embComp; comp = vps.comp } ; insertObjPre : (Agr => Str) -> VPHSlash -> VPH = \obj,vp -> { s = vp.s ; obj = vp.obj ; inf = vp.inf ; subj = vp.subj ; ad = vp.ad ; embComp = vp.embComp; comp = \\a => obj ! a ++ vp.c2.s ++ vp.comp ! a } ; insertAdV : Str -> VPH -> VPH = \ad,vp -> { s = vp.s ; obj = vp.obj ; inf = vp.inf ; subj = vp.subj; ad = vp.ad ++ ad ; embComp = vp.embComp; comp = vp.comp } ; conjThat : Str = "की" ; -- की insertEmbCompl : VPH -> Str -> VPH = \vp,emb -> { s = vp.s ; obj = vp.obj ; inf = vp.inf ; subj = vp.subj; ad = vp.ad; embComp = vp.embComp ++ emb; comp = vp.comp } ; insertTrans : VPH -> VType -> VPH = \vp,vtype -> { s = vp.s ; obj = vp.obj ; inf = vp.inf ; subj = case vtype of { VIntrans => VTransPost ; VTrans => VTrans ; _ => vtype } ; ad = vp.ad; embComp = vp.embComp ; comp = vp.comp } ; -- copula cases oper -- For Human, occupation/Introductiary case copulaPrLvng : Polarity -> Number -> NPerson -> Gender -> Str = \po,n,pn,g -> case of { -- Resembles with 'mkVPreNPReg' function for positive --TODO -- Present Positive => "हुँ" ; -- हुँ => "हौँ" ; -- हौँ => "होस्" ; -- होस् -- => "होस्" ; -- छेस् => "हौ" ; -- हौ -- => "छ्यौ" ; -- छ्यौ => "हौ" ; -- हौ => "हो" ; -- हो => "हुन्" ; -- हुन् => "हुन्" ; -- हुन् -- => "हुन्" ; -- हुन् => "हुन्" ; -- हुन् --"हौ" ; -- हौ => "हुनुहुन्छ" ; --हुनुहुन्छ -- Present Negative => "हैन" ; -- => "हैनौं" ; -- हैनौं => "हैनस्" ; -- हैनस् => "हैनौ" ; -- हैनौ => "हैनौ" ; -- हैनौ => "हैन" ; --हैन => "हैनन्" ; -- हैनन् => "हैनन्" ; -- हैनन् => "हुनुहुन्‌न" -- हुनुहुन्‌न } ; copulaPrGen : Polarity -> Number -> NPerson -> Gender -> Str = \po,n,pn,g -> case of { => "छु" ; -- छु => "छौं" ; -- छौं => "छस्" ; -- छस् => "छेस्" ; -- छेस् => "छौ" ; -- छौ => "छ्यौ" ; -- छ्यौ => "छौ" ; -- छौ => "छ" ; -- छ => "छे" ; -- छे => "छन्" ; -- छन् => "छिन्" ; -- छिन् => "छन्" ; -- छन् => "हुनुहुन्छ" ; --हुनुहुन्छ -- Present Negative => "छैनँ" ; -- छैनँ => "छैनौं" ; -- छैनौं => "छैनस्" ; -- छैनस् => "छैनौ" ; -- छैनौ => "छैनौ" ; -- छैनौ => "छैन" ; --छैन => "छैनन्" ; -- छैनन् => "छैनन्" ; -- छैनन् => "हुनुहुन्‌न" -- हुनुहुन्‌न } ; copulaPsGen : Polarity -> Number -> NPerson -> Gender -> Str = \po,n,pn,g -> case of { -- Past Positive => "थिएँ" ; -- थिएँ => "थियौँ" ; -- थियौँ => "थिइस्" ; -- थिइस् => "थियौ" ; -- थियौ => "थियौ" ; -- थियौ => "थियो" ; -- थियो => "थिई" ; --थिई => "थिए" ; -- थिए => "थिइन्" ; -- थिइन् => "थिए" ; -- थिए => "हुनुहुन्‌थ्यो" ; -- हुनुहुन्‌थ्यो -- Past Positive => "थिनँ" ; -- थिनँ => "थेनौं" ; -- थेनौं => "थिनस्" ; -- थिनस् => "थेनौ" ; -- थेनौ => "थेनौ" ; -- थेनौ => "थेन" ; -- थेन => "थिन" ; --थिन => "थेनन्" ; -- थेनन् => "थिनन्" ; -- थिनन् => "थेनन्" ; -- थेनन् => "हुनुहुन्‌नथ्यो" -- हुनुहुन्‌नथ्यो } ; copulaFtGen : Polarity -> Number -> NPerson -> Gender -> Str = \po,n,pn,g -> case of { -- Future Positive => "हुनेछु" ; -- हुनेछु => "हुनेछौं" ; -- हुनेछौं => "हुनेछस्" ; -- हुनेछस् => "हुनेछौं" ; -- हुनेछौ => "हुनेछौं" ; -- हुनेछौ => "हुनेछ" ; -- हुनेछ => "हुनेछन्" ; -- हुनेछन् => "हुनेछन्" ; -- हुनेछन् => "हुनेछन्" ; -- हुनेछिन् => "हुनेछन्" ; -- हुनेछन् => "हुनुहुनेछ" ; -- हुनुहुनेछ -- Negative Case => "हुनेछैन" ; -- हुनेछैन => "हुनेछैनैँ" ; -- हुनेछैनैँ => "हुनेछैनस्" ; -- हुनेछैनस् => "हुनेछैनै" ; -- हुनेछैनै => "हुनेछैनै" ; -- हुनेछैनै => "हुनेछैन्" ; -- हुनेछैन् => "हुनेछैनन्" ; -- हुनेछैनन् => "हुनेछैनन्" ; -- हुनेछैनन् => "हुनेछैनै" ; -- हुनेछैनै => "हुनुहुनेछैन्" -- हुनुहुनेछैन् } ; }