diff --git a/lib/resource/abstract/TestResource.gf b/lib/resource/abstract/TestResource.gf index 856cc1dda..941e6cfde 100644 --- a/lib/resource/abstract/TestResource.gf +++ b/lib/resource/abstract/TestResource.gf @@ -1,4 +1,8 @@ -abstract TestResource = Rules, Clause, Structural ** { +abstract TestResource = + Rules, +---- Verbphrase, + Clause, + Structural ** { -- a random sample of lexicon to test resource grammar with diff --git a/lib/resource/abstract/Verbphrase.gf b/lib/resource/abstract/Verbphrase.gf index ad7bb817f..1d90c6678 100644 --- a/lib/resource/abstract/Verbphrase.gf +++ b/lib/resource/abstract/Verbphrase.gf @@ -13,6 +13,8 @@ abstract Verbphrase = Categories ** { + flags optimize=all ; + -- These rules produce verb phrases. fun @@ -38,6 +40,8 @@ abstract Verbphrase = Categories ** { PredAV : AV -> VPI -> VP ; -- "is eager to leave" PredObjA2V : A2V -> NP -> VPI -> VP ; -- "is easy for us to convince" + PredProgVP : VPI -> VP ; -- "is eating fish" + -- These rules *use* verb phrases. PredVP : NP -> VP -> Cl ; -- "John walks" @@ -46,7 +50,7 @@ abstract Verbphrase = Categories ** { PosVP, NegVP : Ant -> VP -> VPI ; -- to eat, not to eat - AdvVP : VP -> AdV -> VP ; -- "always walks" +---- AdvVP : VP -> AdV -> VP ; -- "always walks" SubjVP : VP -> Subj -> S -> VP ; -- "(a man who) sings when he runs" } diff --git a/lib/resource/danish/SyntaxDan.gf b/lib/resource/danish/SyntaxDan.gf index 2a5cc7065..6cde31053 100644 --- a/lib/resource/danish/SyntaxDan.gf +++ b/lib/resource/danish/SyntaxDan.gf @@ -3,8 +3,9 @@ instance SyntaxDan of SyntaxScand = TypesDan ** open Prelude, (CO = Coordination), MorphoDan in { - oper + flags optimize=all ; + oper ------ mkAdjForm -- When common nouns are extracted from lexicon, the composite noun form is ignored. @@ -108,12 +109,9 @@ instance SyntaxDan of SyntaxScand = TypesDan ** _ => "seg" } ; - progressiveVerbPhrase : VerbGroup -> VerbGroup = \verb -> + progressiveVerbPhrase : VerbPhrase -> VerbGroup = complVerbVerb - (verbVara ** - {isAux = False} ----- {s3 = ["ved at"]} - ) - (predVerbGroup True Simul verb) ; + {s = verbVara.s ; s1 = "ved" ; isAux = False} ; progressiveClause : NounPhrase -> VerbPhrase -> Clause = \np,vp -> predVerbGroupClause np diff --git a/lib/resource/doc/gf-resource.html b/lib/resource/doc/gf-resource.html index 41faf0a9e..83e0e2ff8 100644 --- a/lib/resource/doc/gf-resource.html +++ b/lib/resource/doc/gf-resource.html @@ -152,17 +152,38 @@ Language-dependent resources -

Use as top-level grammar

+

Use as top-level grammar: testing

-Random generation, translation, morphological analysis... +Import a set of $LangX$ grammars: +
+  i english/LangEng.gf
+  i swedish/LangSwe.gf
+
+Test with random generation, translation, morphological analysis... +
 
-

-Language learning: translation and morpho quiz +

-

+ +

Use as top-level grammar: language learning quizzes

+ +Morpho quiz with words: +
+
+
+
+Morpho quiz with phrases: +
+
+
+
+Translation quiz with sentences: +
+
+
+
-Generate elementary text books from abstract syntax? @@ -179,10 +200,14 @@ No more dummy reuse modules and bulky .gfr files! If you need to convert resource category records to/from strings, use
-  Predef.toStr   : L -> Str ; 
-  Predef.fromStr : Str -> L ; 
+  Predef.toStr : (L : Type) -> L -> Str ; 
 
-L must be a linearization type. +L must be a linearization type. For instance, +
+  toStr LangNor.CN (ModAP (PositADeg old_ADeg) (UseN car_N))
+  ---> "gammel bil"
+
+ @@ -205,9 +230,14 @@ Extend vocabulary at need. + +

Example application: a small translation system

+ + + -

Implementatin details: the structure of low-level files

+

Implementation details: the structure of low-level files

diff --git a/lib/resource/english/SyntaxEng.gf b/lib/resource/english/SyntaxEng.gf index 5b4fbf2e8..c55946288 100644 --- a/lib/resource/english/SyntaxEng.gf +++ b/lib/resource/english/SyntaxEng.gf @@ -690,10 +690,12 @@ oper APl P3 => "themselves" } ; - progressiveClause : NounPhrase -> VerbPhrase -> Clause = \np,vp -> predBeGroup np (vp.s ! VIPresPart) ; + progressiveVerbPhrase : VerbPhrase -> VerbGroup = \vp -> + predClauseBeGroup (vp.s ! VIPresPart) ; + --- negation of prp ignored: "not" only for "be" --3 Tensed clauses @@ -725,16 +727,53 @@ oper } } ; +-- These three function are just to restore the $VerbGroup$ ($VP$) based structure. + + predVerbGroupClause : NounPhrase -> VerbGroup -> Clause = \np,vp -> + let + ag = np.a ; + it = np.s ! NomP + in + {s = table { + Dir => \\b,sf => it ++ vp.s ! b ! sf ! ag ++ vp.s2 ! b ! sf ! ag ; + Inv => \\b,sf => + let + does = vp.s ! b ! sf ! ag ; + walk = vp.s2 ! b ! sf ! ag + in + case sf of { + VFinite t Simul => case b of { + True => auxTense b t ag ++ it ++ walk ; + _ => does ++ it ++ walk + } ; + _ => does ++ it ++ walk + } + } + } ; + predClauseGroup : Verb -> Complement -> VerbGroup = \verb,comp -> let nvg : Agr -> (Bool => SForm => (Str * Str * Str)) = - \ag -> predVerbClauseGen {s = \\_ => [] ; a = ag} verb comp + \ag -> predVerbClauseGen {s = \\_ => [] ; a = ag} verb comp in {s = \\b,f,a => (nvg a ! b ! f).p2 ; s2 = \\b,f,a => (nvg a ! b ! f).p3 ; - isAux = False ---- + isAux = False } ; + predClauseBeGroup : Complement -> VerbGroup = \comp -> + let + nvg : Agr -> (Bool => SForm => (Str * Str * Str)) = + \ag -> predAuxClauseGen {s = \\_ => [] ; a = ag} auxVerbBe comp + in + {s = \\b,f,a => (nvg a ! b ! f).p2 ; + s2 = \\b,f,a => (nvg a ! b ! f).p3 ; + isAux = True + } ; + +-- This is the general predication function for non-auxiliary verbs, +-- i.e. ones with "do" inversion and negation. + predVerbClauseGen : NounPhrase -> Verb -> Complement -> (Bool => SForm => (Str * Str * Str)) = \np,verb,comp -> let @@ -1025,15 +1064,12 @@ oper RelClause : Type = {s : Bool => SForm => Agr => Str} ; RelSentence : Type = {s : Agr => Str} ; ------- relg relVerbPhrase : RelPron -> VerbGroup -> RelClause = \who,walks -> - {s = \\b,sf,a => [] ----- let wa = fromAgr a in ----- (predVerbGroupClause (relNounPhrase who wa.g wa.n) walks).s ! Dir ! b ! sf + {s = \\b,sf,a => + let wa = fromAgr a in + (predVerbGroupClause (relNounPhrase who wa.g wa.n) walks).s ! Dir ! b ! sf } ; ---- TODO: full tense variation in relative clauses. - relSlash : RelPron -> ClauseSlashNounPhrase -> RelClause = \who,yousee -> {s = \\b,sf,a => let @@ -1196,7 +1232,6 @@ oper in {s = \\b,sf,_ => whoisold.s ! Dir ! b ! sf} ; -{- --vg intVerbPhrase : IntPron -> VerbGroup -> Question = \who,walk -> let who : NounPhrase = {s = who.s ; a = toAgr who.n P3 who.g} ; @@ -1204,8 +1239,6 @@ oper in {s = \\b,sf,_ => whowalks.s ! Dir ! b ! sf} ; - --vg -} - intVerbClause : IntPron -> Verb -> Complement -> Question = \who,walk,here -> let who : NounPhrase = {s = who.s ; a = toAgr who.n P3 who.g} ; diff --git a/lib/resource/english/VerbphraseEng.gf b/lib/resource/english/VerbphraseEng.gf index d67e2d4dd..6fa988db1 100644 --- a/lib/resource/english/VerbphraseEng.gf +++ b/lib/resource/english/VerbphraseEng.gf @@ -23,39 +23,43 @@ concrete VerbphraseEng of Verbphrase = CategoriesEng ** open Prelude, SyntaxEng in { lin - UseV = predVerb ; - UsePassV = passVerb ; - ComplV2 = complTransVerb ; - ComplReflV2 = reflTransVerb ; - ComplVS = complSentVerb ; - ComplVV = complVerbVerb ; - ComplVQ = complQuestVerb ; - ComplVA = complAdjVerb ; - ComplV2A = complDitransAdjVerb ; - ComplSubjV2V = complDitransVerbVerb False ; - ComplObjV2V = complDitransVerbVerb True ; - ComplV2S = complDitransSentVerb ; - ComplV2Q = complDitransQuestVerb ; + UseV v = predClauseGroup v (complVerb v) ; + UsePassV v = predClauseBeGroup (passVerb v) ; + ComplV2 v x = predClauseGroup v (complTransVerb v x) ; + ComplReflV2 v = predClauseGroup v (reflTransVerb v) ; + ComplVS v x = predClauseGroup v (complSentVerb v x) ; + ComplVV v x = predClauseGroup (aux2verb v) (complVerbVerb v x) ; + ComplVQ v x = predClauseGroup v (complQuestVerb v x) ; + ComplVA v x = predClauseGroup v (complAdjVerb v x) ; + ComplV2A v x y = predClauseGroup v (complDitransAdjVerb v x y) ; + ComplSubjV2V v x y = predClauseGroup v (complDitransVerbVerb False v x y) ; + ComplObjV2V v x y = predClauseGroup v (complDitransVerbVerb True v x y) ; + ComplV2S v x y = predClauseGroup v (complDitransSentVerb v x y) ; + ComplV2Q v x y = predClauseGroup v (complDitransQuestVerb v x y) ; - PredAP = predAdjective ; - PredSuperl a = predAdjective (superlAdjPhrase a) ; - PredCN = predCommNoun ; - PredNP = predNounPhrase ; - PredPP = predAdverb ; - PredAV = complVerbAdj ; - PredObjA2V = complVerbAdj2 True ; + PredAP v = predClauseBeGroup (complAdjective v) ; + PredSuperl a = predClauseBeGroup (complAdjective (superlAdjPhrase a)) ; + PredCN v = predClauseBeGroup (complCommNoun v) ; + PredNP v = predClauseBeGroup (complNounPhrase v) ; + PredPP v = predClauseBeGroup (complAdverb v) ; + + PredAV v x = predClauseBeGroup (complVerbAdj v x) ; + PredObjA2V v x y = predClauseBeGroup (complVerbAdj2 True v x y) ; + + PredProgVP = progressiveVerbPhrase ; + +---- SPredProgVP = progressiveClause ; -- Use VPs PredVP = predVerbGroupClause ; + RelVP = relVerbPhrase ; IntVP = intVerbPhrase ; - PosVP tp = predVerbGroup True tp.a ; - NegVP tp = predVerbGroup False tp.a ; +-- PosVP tp = predVerbGroup True tp.a ; +-- NegVP tp = predVerbGroup False tp.a ; - AdvVP = adVerbPhrase ; +---- AdvVP = adVerbPhrase ; SubjVP = subjunctVerbPhrase ; - - } \ No newline at end of file diff --git a/lib/resource/norwegian/SyntaxNor.gf b/lib/resource/norwegian/SyntaxNor.gf index 001018427..5eaf4f1ae 100644 --- a/lib/resource/norwegian/SyntaxNor.gf +++ b/lib/resource/norwegian/SyntaxNor.gf @@ -3,6 +3,8 @@ instance SyntaxNor of SyntaxScand = TypesNor ** open Prelude, (CO = Coordination), MorphoNor in { + flags optimize=all ; + oper ------ mkAdjForm @@ -75,7 +77,7 @@ instance SyntaxNor of SyntaxScand = TypesNor ** auxSka = "vil" ; auxSkulle = "ville" ; - infinAtt = "at" ; + infinAtt = "å" ; varjeDet : Determiner = mkDeterminerSg (detSgInvar "hver") IndefP ; allaDet : Determiner = mkDeterminerPl "alle" IndefP ; @@ -109,12 +111,9 @@ instance SyntaxNor of SyntaxScand = TypesNor ** _ => "seg" } ; - progressiveVerbPhrase : VerbGroup -> VerbGroup = \verb -> + progressiveVerbPhrase : VerbPhrase -> VerbGroup = complVerbVerb - (verbVara ** - {isAux = False} ----- {s3 = ["ved at"]} - ) - (predVerbGroup True Simul verb) ; + ({s = verbVara.s ; s1 = "ved" ; isAux = False}) ; progressiveClause : NounPhrase -> VerbPhrase -> Clause = \np,vp -> predVerbGroupClause np diff --git a/lib/resource/scandinavian/CategoriesScand.gf b/lib/resource/scandinavian/CategoriesScand.gf index 678d6869c..0a1dc77bc 100644 --- a/lib/resource/scandinavian/CategoriesScand.gf +++ b/lib/resource/scandinavian/CategoriesScand.gf @@ -34,7 +34,7 @@ lincat V = Verb ; -- = {s : VerbForm => Str ; s1 : Str} ; - VP = {s : SForm => Str ; s2 : Bool => Str ; + VP = {s : SForm => Str ; s3 : SForm => Gender => Number => Person => Str} ; VPI = {s : VIForm => Gender => Number => Person => Str} ; V2 = TransVerb ; diff --git a/lib/resource/scandinavian/RulesScand.gf b/lib/resource/scandinavian/RulesScand.gf index b4e043837..62efde70a 100644 --- a/lib/resource/scandinavian/RulesScand.gf +++ b/lib/resource/scandinavian/RulesScand.gf @@ -133,7 +133,7 @@ lin ImperMany = imperUtterance plural ; AdvCl = advClause ; - AdvVP = advVerbPhrase ; +---- AdvVP = advVerbPhrase ; AdvPhr = advSentence ; AdCPhr = advSentence ; diff --git a/lib/resource/scandinavian/SyntaxScand.gf b/lib/resource/scandinavian/SyntaxScand.gf index b22f22f1f..9b0870dd6 100644 --- a/lib/resource/scandinavian/SyntaxScand.gf +++ b/lib/resource/scandinavian/SyntaxScand.gf @@ -9,7 +9,7 @@ interface SyntaxScand = TypesScand ** open Prelude, (CO = Coordination) in { -flags optimize=share ; +flags optimize=parametrize ; --2 Common Nouns -- @@ -535,7 +535,7 @@ oper useVerb : Verb -> (Gender => Number => Person => Str) -> VerbGroup = \verb,arg -> let aer = verbSForm verb Act in { s = \\sf => (aer sf).fin ; - s2 = negation ; + --* s2 = negation ; s3 = \\sf,g,n,p => (aer sf).inf ++ arg ! g ! n ! p } ; @@ -553,27 +553,28 @@ oper VerbGroup : Type = { s : SForm => Str ; - s2 : Bool => Str ; + --* s2 : Bool => Str ; s3 : SForm => Gender => Number => Person => Str } ; - predVerbGroup : Bool -> Anteriority -> VerbGroup -> VerbPhrase = \b,a,vg -> + predVerbGroup : Bool -> {s : Str ; a : Anteriority} -> VerbGroup -> VerbPhrase = \b,ant,vg -> let vgs = vg.s ; - vgs3 = vg.s3 + vgs3 = vg.s3 ; + a = ant.a ; in {s = table { VIInfinit => \\g,n,p => - vg.s ! VInfinit a ++ vg.s2 ! b ++ vg.s3 ! VInfinit a ! g ! n ! p ; + vg.s ! VInfinit a ++ ant.s ++ negation ! b ++ vg.s3 ! VInfinit a ! g ! n ! p ; VIImperat bo => \\g,n,p => - vg.s ! VImperat ++ vg.s2 ! bo ++ vg.s3 ! VImperat ! g ! n ! p + vg.s ! VImperat ++ ant.s ++ negation ! bo ++ vg.s3 ! VImperat ! g ! n ! p } ---- bo shadows b } ; predVerbGroupI : Bool -> {s : Str ; a : Anteriority} -> VerbGroup -> VerbPhrase = \b,ant,vg -> - let vp = predVerbGroup b ant.a vg in - {s = \\i,g,n,p => ant.s ++ vp.s ! i ! g ! n ! p + let vp = predVerbGroup b ant vg in + {s = \\i,g,n,p => vp.s ! i ! g ! n ! p } ; @@ -589,7 +590,8 @@ oper predVerb0 : Verb -> Clause = \regna -> predVerbGroupClause npDet (predVerb regna) ; - progressiveVerbPhrase : VerbGroup -> VerbGroup ; + progressiveVerbPhrase : VerbPhrase -> VerbGroup ; + progressiveClause : NounPhrase -> VerbPhrase -> Clause ; -- Verb phrases can also be formed from adjectives ("är snäll"), @@ -662,7 +664,7 @@ oper passVerb : Verb -> VerbGroup = \se -> let ses = verbSForm se Pass in { s = \\sf => (ses sf).fin ; - s2 = negation ; + --* s2 = negation ; s3 = \\sf,g,n,_ => (ses sf).inf ++ se.s1 } ; @@ -736,7 +738,7 @@ oper { --- this unfortunately generates VP#2 ::= VP#2 s = spelar.s ; - s2 = \\b => ofta.s ++ spelar.s2 ! b ; + --* s2 = \\b => ofta.s ++ spelar.s2 ! b ; ----* the essential use of s2 s3 = \\sf,g,n,p => spelar.s3 ! sf ! g ! n ! p } ; @@ -816,7 +818,7 @@ oper o = osf.o ; ser = serdiginte.s ! t ; dig = serdiginte.s3 ! t ! Jag.g ! Jag.n ! Jag.p ; - inte = serdiginte.s2 ! b + inte = negation ! b --* serdiginte.s2 ! b } in case o of { Main => jag ++ ser ++ inte ++ dig ; @@ -996,9 +998,9 @@ oper RelClause : Type = {s : Bool => SForm => GenNum => Person => Str} ; RelSent : Type = {s : GenNum => Person => Str} ; - relVerbGroup : RelPron -> VerbGroup -> RelClause = \som,sover -> + relVerbPhrase : RelPron -> VerbGroup -> RelClause = \som,sover -> {s = \\b,sf,gn,p => - som.s ! RNom ! gn ++ sover.s2 ! b ++ sover.s ! sf ++ + som.s ! RNom ! gn ++ negation ! b ++ sover.s ! sf ++ sover.s3 ! sf ! mkGenderRel som.g (genGN gn) ! numGN gn ! p } ; diff --git a/lib/resource/scandinavian/VerbphraseScand.gf b/lib/resource/scandinavian/VerbphraseScand.gf index 829f5ec02..32e4c6b4e 100644 --- a/lib/resource/scandinavian/VerbphraseScand.gf +++ b/lib/resource/scandinavian/VerbphraseScand.gf @@ -1,8 +1,5 @@ --# -path=.:../abstract:../../prelude -incomplete concrete VerbphraseScand of Verbphrase = CategoriesScand ** - open Prelude, SyntaxScand in { - --1 The Top-Level English Resource Grammar: Combination Rules -- -- Aarne Ranta 2002 -- 2003 @@ -22,8 +19,8 @@ incomplete concrete VerbphraseScand of Verbphrase = CategoriesScand ** -- one has to know how the syntactic categories are -- implemented. The parameter types are defined in $TypesEng.gf$. -concrete VerbphraseEng of Verbphrase = CategoriesEng ** - open Prelude, SyntaxEng in { +incomplete concrete VerbphraseScand of Verbphrase = CategoriesScand ** + open Prelude, SyntaxScand in { lin UseV = predVerb ; @@ -48,16 +45,18 @@ concrete VerbphraseEng of Verbphrase = CategoriesEng ** PredAV = complVerbAdj ; PredObjA2V = complVerbAdj2 True ; + PredProgVP = progressiveVerbPhrase ; + -- Use VPs PredVP = predVerbGroupClause ; RelVP = relVerbPhrase ; IntVP = intVerbPhrase ; - PosVP tp = predVerbGroup True tp.a ; - NegVP tp = predVerbGroup False tp.a ; + PosVP tp = predVerbGroup True tp ; + NegVP tp = predVerbGroup False tp ; - AdvVP = adVerbPhrase ; +---- AdvVP = adVerbPhrase ; SubjVP = subjunctVerbPhrase ; -} \ No newline at end of file +} diff --git a/lib/resource/swedish/ClauseSwe.gf b/lib/resource/swedish/ClauseSwe.gf index 44f642ff5..806308cd0 100644 --- a/lib/resource/swedish/ClauseSwe.gf +++ b/lib/resource/swedish/ClauseSwe.gf @@ -1,4 +1,5 @@ --# -path=.:../scandinavian:../abstract:../../prelude concrete ClauseSwe of Clause = CategoriesSwe ** - ClauseScand with (SyntaxScand=SyntaxSwe) ; + ClauseI with (Rules=RulesSwe), (Verbphrase=VerbphraseSwe) ; +---- ClauseScand with (SyntaxScand=SyntaxSwe) ; diff --git a/lib/resource/swedish/SyntaxSwe.gf b/lib/resource/swedish/SyntaxSwe.gf index 3ece4e873..3d8d927b2 100644 --- a/lib/resource/swedish/SyntaxSwe.gf +++ b/lib/resource/swedish/SyntaxSwe.gf @@ -115,11 +115,10 @@ instance SyntaxSwe of SyntaxScand = TypesSwe ** _ => "sig" } ; - progressiveVerbPhrase : VerbGroup -> VerbGroup = \verb -> + progressiveVerbPhrase : VerbPhrase -> VerbGroup = complVerbVerb (mkVerb "hålla" "håller" "håll" "höll" "hållit" "hållen" ** - {isAux = False}) ---- ;{s3 = ["på att"]}) - (predVerbGroup True Simul verb) ; + {isAux = False}) ; progressiveClause : NounPhrase -> VerbPhrase -> Clause = \np,vp -> predVerbGroupClause np @@ -131,6 +130,7 @@ instance SyntaxSwe of SyntaxScand = TypesSwe ** strPrep : ComplPrep -> Str = \p -> case p of { CPnoPrep => [] ; CPav => "av" ; +---- CPmed => "med" ; CPför => "för" ; CPi => "i" ; CPom => "om" ;