Machine translation with Constraint Grammar
Constraint Grammar is pretty flexible, it lets you shoot off your feet.
Input
"<Í>" "í" Pr @ADVL→ #1->3 "<upphavi>" "upphav" N Neu Sg Dat Indef @P← #2->1 "<skapti>" "skapa" V Ind Prt Sg @VMAIN #3->0 "<Gud>" "gudur" N Msc Sg Nom Indef @←SUBJ #4->3 "<himmal>" "himmal" N Msc Sg Acc Indef @←OBJ #5->3 "<og>" "og" CC @CC #6->5 "<jørð>" "jørð" N Fem Sg Acc Indef @←OBJ #7->5 "<.>" "." CLB #8->0
Grammars
Lexical
$ cat /tmp/lexical_transfer.cg SECTION SUBSTITUTE ("í") ("in") ("í"); SUBSTITUTE ("upphav") ("beginning") ("upphav"); SUBSTITUTE ("himmal") ("heaven") ("himmal"); SUBSTITUTE ("og") ("and") ("og"); SUBSTITUTE ("jørð") ("earth") ("jørð"); SUBSTITUTE ("skapa") ("create") ("skapa"); SUBSTITUTE ("gudur") ("god") ("gudur");
Movement
$ cat /tmp/movement.cg SECTION MOVE WITHCHILD (*) (@←SUBJ) BEFORE (-1* (@VMAIN)) ; SUBSTITUTE (@←SUBJ) (@SUBJ→) (@←SUBJ) (1 (@VMAIN)) ;
Morphological transfer
$ cat /tmp/morphtrans.cg SECTION SUBSTITUTE (Neu) (*) (Neu); SUBSTITUTE (Fem) (*) (Fem); SUBSTITUTE (Msc) (*) (Msc); SUBSTITUTE (Nom) (*) (Nom); SUBSTITUTE (Dat) (*) (Dat); SUBSTITUTE (Acc) (*) (Acc); SUBSTITUTE (Indef) (*) (Indef); ...or... SECTION LIST ToKill = Neu Fem Msc Nom Dat Acc Indef ; SUBSTITUTE $$ToKill (*) $$ToKill ;
Generation
SECTION ADDCOHORT ("<the>" "the" Det Def Sg) BEFORE (N Def) ;
Output
$ cat /tmp/in | vislcg3 --grammar /tmp/movement.cg | vislcg3 --grammar /tmp/lexical_transfer.cg | vislcg3 --grammar /tmp/morphtrans.cg "<Í>" "in" Pr #1->4 @ADVL→ "<upphavi>" "beginning" N Sg #2->1 @P← "<Gud>" "god" N Sg #3->4 @SUBJ→ "<skapti>" "create" V Ind Prt Sg #4->0 @VMAIN "<himmal>" "heaven" N Sg #5->4 @←OBJ "<og>" "and" CC #6->5 @CC "<jørð>" "earth" N Sg #7->5 @←OBJ "<.>" "." CLB #8->0