1
0
forked from GitHub/gf-core

examples of morphological synthesis/analysis as top-level grammars

This commit is contained in:
aarne
2008-08-15 12:41:04 +00:00
parent c00007c49e
commit f56ad59698
7 changed files with 259 additions and 0 deletions

27
examples/morpho/Eng.gf Normal file
View File

@@ -0,0 +1,27 @@
-- Abstract syntax for a top-level grammar for morphological analysis and synthesis
-- AR 15/8/2008
-- Use this as a template to port other morphologies to javascript, etc.
-- First import a lexicon.
abstract Eng = IrregEngAbs ** {
cat
Display ; -- what is shown: word form, analysis, or full table
Word ; -- lexical unit
Form ; -- form description
flags startcat = Display ;
fun
DAll : Word -> Display ; -- to show full table
DForm : Word -> Form -> Display ; -- to show one form
-- Here are the possible forms; this is really a copy of ResEng.VForm
-- and should be generated automatically.
VInf, VPres, VPast, VPPart, VPresPart : Form ;
WVerb : V -> Word ; -- use category V from IrregEngAbs
}

View File

@@ -0,0 +1,23 @@
--# -path=.:alltenses
concrete EngDescr of Eng = IrregEng ** open (R = ResEng) in {
lincat
Display, Word, Form = Str ;
lin
DAll w = w ++ ":" ++ "all forms" ;
DForm w f = w ++ ":" ++ f ;
-- names of forms displayed
VInf = "Infinitive" ;
VPres = "Present" ;
VPast = "Past" ;
VPPart = "Past Participle" ;
VPresPart = "Present Participle" ;
WVerb v = v.s ! R.VInf ; -- the dictionary form shown in word description
}

View File

@@ -0,0 +1,31 @@
--# -path=.:alltenses
concrete EngReal of Eng = IrregEng ** open (R = ResEng) in {
lincat
Display = Str ;
Word = R.VForm => Str ;
Form = {s : Str ; v : R.VForm} ;
lin
-- select the forms to display (here all forms)
DAll w = w ! R.VInf ++ w ! R.VPres ++ w ! R.VPast ++ w ! R.VPPart ++ w ! R.VPresPart ;
-- this code should be generated automatically
DForm w f = w ! f.v ++ f.s ;
VInf = vf R.VInf ;
VPres = vf R.VPres ;
VPast = vf R.VPast ;
VPPart = vf R.VPPart ;
VPresPart = vf R.VPresPart ;
WVerb v = v.s ;
oper
vf : R.VForm -> {s : Str ; v : R.VForm} = \f -> {s = [] ; v = f} ; ---
}

38
examples/morpho/Fre.gf Normal file
View File

@@ -0,0 +1,38 @@
-- French irregular verbs, built using Eng as template.
abstract Fre = IrregFreAbs ** {
flags startcat = Display ;
cat
Display ; Word ; Form ;
-- French verb forms have an internal structure.
TMood ; Number ; Person ; NumPersI ; Gender ; Mood ;
fun
DAll : Word -> Display ;
DForm : Word -> Form -> Display ;
VInfin : Form ;
VFin : TMood -> Number -> Person -> Form ;
VImper : NumPersI -> Form ;
VPart : Gender -> Number -> Form ;
VGer : Form ;
VPres : Mood -> TMood ;
VImperf : Mood -> TMood ;
VPasse, VFut, VCondit : TMood ;
SgP2, PlP1, PlP2 : NumPersI ;
Sg, Pl : Number ;
P1, P2, P3 : Person ;
Masc, Fem : Gender ;
Indic, Conjunct : Mood ;
WVerb : V -> Word ;
WVerb2 : V2 -> Word ;
}

View File

@@ -0,0 +1,44 @@
--# -path=.:alltenses
concrete FreDescr of Fre = IrregFre - [S] ** open (R = CommonRomance), Prelude in {
flags coding=utf8 ;
lincat
Display, Word, Form = Str ;
TMood, Number, Person, NumPersI, Gender, Mood = Str ;
lin
DAll w = w ++ ":" ++ "la conjugaison" ;
DForm w f = w ++ ":" ++ f ;
VInfin = "infinitif" ;
VFin m n p = m ++ n ++ p ;
VImper np = "imparfait" ++ np ;
VPart g n = "participe passé" ++ g ++ n ;
VGer = "participe présent" ;
VPres m = m ++ "présent" ;
VImperf m = m ++ "imparfait" ;
VPasse = "passé simple" ;
VFut = "futur" ;
VCondit = "conditionnel" ;
SgP2 = "singulier 2e" ;
PlP1 = "pluriel 1ère" ;
PlP2 = "pluriel 2e" ;
Sg = "singulier" ;
Pl = "pluriel" ;
P1 = "1ère" ;
P2 = "2e" ;
P3 = "3e" ;
Masc = "masculin" ;
Fem = "féminin" ;
Indic = "indicatif" ;
Conjunct = "subjonctif" ;
WVerb v = v.s ! R.VInfin True ;
WVerb2 v = v.s ! R.VInfin True ;
}

View File

@@ -0,0 +1,71 @@
--# -path=.:alltenses
concrete FreReal of Fre = IrregFre ** open (R = CommonRomance), Prelude in {
lincat
Display = Str ;
Word = R.VF => Str ;
Form = {s : Str ; v : R.VF} ;
TMood = {s : Str ; v : R.TMood} ;
Number = {s : Str ; v : R.Number} ;
Person = {s : Str ; v : R.Person} ;
NumPersI = {s : Str ; v : R.NumPersI} ;
Gender = {s : Str ; v : R.Gender} ;
Mood = {s : Str ; v : R.Mood} ;
lin
-- display the same subset of forms as Petit Robert
DAll w =
w ! R.VInfin True ++
w ! R.VFin (R.VPres R.Indic) R.Sg R.P1 ++
w ! R.VFin (R.VPres R.Indic) R.Sg R.P3 ++
w ! R.VFin (R.VPres R.Indic) R.Pl R.P1 ++
w ! R.VFin (R.VPres R.Indic) R.Pl R.P3 ++
w ! R.VFin (R.VImperf R.Indic) R.Sg R.P1 ++
w ! R.VFin (R.VImperf R.Indic) R.Pl R.P1 ++
w ! R.VFin R.VPasse R.Sg R.P1 ++
w ! R.VFin R.VPasse R.Pl R.P1 ++
w ! R.VFin R.VFut R.Sg R.P1 ++
w ! R.VFin R.VCondit R.Sg R.P1 ++
w ! R.VFin (R.VPres R.Conjunct) R.Sg R.P1 ++
w ! R.VImper R.SgP2 ++
w ! R.VImper R.PlP1 ++
w ! R.VGer ++
w ! R.VPart R.Masc R.Sg ;
DForm w f = w ! f.v ++ f.s ; ---
VInfin = {s = [] ; v = R.VInfin True} ;
VFin m n p = {s = m.s ++ n.s ++ p.s ; v = R.VFin m.v n.v p.v} ;
VImper np = {s = np.s ; v = R.VImper np.v} ;
VPart g n = {s = g.s ++ n.s ; v = R.VPart g.v n.v} ;
VGer = {s = [] ; v = R.VGer} ;
VPres m = {s = m.s ; v = R.VPres m.v} ;
VImperf m = {s = m.s ; v = R.VImperf m.v} ;
VPasse = {s = [] ; v = R.VPasse} ;
VFut = {s = [] ; v = R.VFut} ;
VCondit = {s = [] ; v = R.VCondit} ;
SgP2 = {s = [] ; v = R.SgP2} ;
PlP1 = {s = [] ; v = R.PlP1} ;
PlP2 = {s = [] ; v = R.PlP2} ;
Sg = {s = [] ; v = R.Sg} ;
Pl = {s = [] ; v = R.Pl} ;
P1 = {s = [] ; v = R.P1} ;
P2 = {s = [] ; v = R.P2} ;
P3 = {s = [] ; v = R.P3} ;
Masc = {s = [] ; v = R.Masc} ;
Fem = {s = [] ; v = R.Fem} ;
Indic = {s = [] ; v = R.Indic} ;
Conjunct = {s = [] ; v = R.Conjunct} ;
WVerb v = v.s ;
WVerb2 v = v.s ;
oper
vf : R.VF -> {s : Str ; v : R.VF} = \f -> {s = [] ; v = f} ; ---
}

View File

@@ -0,0 +1,25 @@
AR 15/8/2008
Here are some examples of morphological lexica turned into top-level GF grammars.
Top level is useful because it supports analysis and synthesis by normal
e.g. JavaScript tools.
The simplest example is in the following three files:
Eng.gf -- abstract syntax (English irregular verbs)
EngDescr.gf -- concrete syntax showing form descriptions
EngReal.gf -- concrete syntax showing real forms
Compile the result with
gfc --make -f js EngDescr.gf EngReal.gf
Then use Eng.js in place of GF/lib/javascript/grammar.js
Other examples:
Fre* -- French irregular verbs
NB: there are issues on character encoding of abstract verb names in Fre.