[First version of IIT slides. bjorn@bringert.net**20080110173825] { addfile ./Food.gf hunk ./Food.gf 1 - +abstract Food = { + + cat + Phrase ; Item ; Kind ; Quality ; + + flags startcat = Phrase ; + + fun + Is : Item -> Quality -> Phrase ; + This, That : Kind -> Item ; + QKind : Quality -> Kind -> Kind ; + Wine, Pizza, Cheese, Fish : Kind ; + Very : Quality -> Quality ; + Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ; + +} addfile ./FoodEng.gf hunk ./FoodEng.gf 1 - +concrete FoodEng of Food = { + + lincat + Phrase, Item, Kind, Quality = {s : Str} ; + + lin + Is item quality = {s = item.s ++ "is" ++ quality.s} ; + This kind = {s = "this" ++ kind.s} ; + That kind = {s = "that" ++ kind.s} ; + QKind quality kind = {s = quality.s ++ kind.s} ; + Wine = {s = "wine"} ; + Pizza = {s = "pizza"} ; + Cheese = {s = "cheese"} ; + Fish = {s = "fish"} ; + Very quality = {s = "very" ++ quality.s} ; + Fresh = {s = "fresh"} ; + Warm = {s = "warm"} ; + Italian = {s = "Italian"} ; + Expensive = {s = "expensive"} ; + Delicious = {s = "delicious"} ; + Boring = {s = "boring"} ; + +} + addfile ./FoodIta.gf hunk ./FoodIta.gf 1 +concrete FoodIta of Food = { + + lincat + Phrase, Item, Kind, Quality = {s : Str} ; + + lin + Is item quality = {s = item.s ++ "è" ++ quality.s} ; + This kind = {s = "questo" ++ kind.s} ; + That kind = {s = "quello" ++ kind.s} ; + QKind quality kind = {s = kind.s ++ quality.s} ; + Wine = {s = "vino"} ; + Pizza = {s = "pizza"} ; + Cheese = {s = "formaggio"} ; + Fish = {s = "pesce"} ; + Very quality = {s = "molto" ++ quality.s} ; + Fresh = {s = "fresco"} ; + Warm = {s = "caldo"} ; + Italian = {s = "italiano"} ; + Expensive = {s = "caro"} ; + Delicious = {s = "delizioso"} ; + Boring = {s = "noioso"} ; + +} addfile ./Htmls.hs hunk ./Htmls.hs 1 +---------------------------------------------------------------------- +-- | +-- +-- chop an HTML file into separate files, each linked to the next and previous. +-- the names of the files are n-file, with n = 01,02,... +-- the chopping is performed at each separator, here defined as @\" + +link :: FilePath -> Int -> Int -> String +link file mx n = + (if n >= mx-1 then "" else (" Next")) ++ + (if n == 1 then "" else (" Previous")) ++ + (" Contents") ++ + (" Fulltext") ++ + (" First") ++ + (" Last") + where + file_ = fileName file (n - 1) + file' = fileName file (n + 1) + file0 = fileName file 0 + file1 = fileName file 1 + file2 = fileName file (mx - 1) + +fileName :: FilePath -> Int -> FilePath +fileName file n = (if n < 10 then ('0':) else id) $ show n ++ "-" ++ file + +pageNum mx num = "

" ++ show num ++"/" ++ show (mx-1) ++ "

" + +mkIndex file = unlines . mkInd 1 where + mkInd n ss = case ss of + s : rest | (s==separator) -> mkInd (n+1) rest + s : rest -> case getHeading s of + Just (i,t) -> mkLine n i t : mkInd n rest + _ -> mkInd n rest + _ -> [] + getHeading s = case dropWhile isSpace s of + '<':h:i:_:t | isDigit i -> return (i,take (length t - 5) t) -- drop final + _ -> Nothing + mkLine _ '1' t = t ++ " : Table of Contents

" -- heading of whole document + mkLine n i t = stars i ++ link n t ++ "
" + stars i = case i of + '3' -> "

  • " + '4' -> "
  • * " + _ -> "" + link n t = "" ++ t ++ "" addfile ./Makefile hunk ./Makefile 1 +slides: clean + txt2tags --no-headers gf-iit.txt + runghc Htmls.hs gf-iit.html + txt2tags gf-iit.txt + +clean: + -rm gf-iit.html ??-gf-iit.html addfile ./food.cf hunk ./food.cf 1 +Is. S ::= Item "is" Quality ; +That. Item ::= "that" Kind ; +This. Item ::= "this" Kind ; +QKind. Kind ::= Quality Kind ; +Cheese. Kind ::= "cheese" ; +Fish. Kind ::= "fish" ; +Pizza. Kind ::= "pizza" ; +Wine. Kind ::= "wine" ; +Italian. Quality ::= "Italian" ; +Boring. Quality ::= "boring" ; +Delicious. Quality ::= "delicious" ; +Expensive. Quality ::= "expensive" ; +Fresh. Quality ::= "fresh" ; +Very. Quality ::= "very" Quality ; +Warm. Quality ::= "warm" ; + addfile ./gf-iit.txt hunk ./gf-iit.txt 1 +Grammatical Framework: an Overview +Aarne Ranta and Björn Bringert +IIT Bombay, January 16, 2008 + +%!postproc(html): #NEW +%!target: html + +===GF = Grammatical Framework=== + +[``gf.digitalgrammars.com`` http://gf.digitalgrammars.com/] + +Grammar formalism = special-purpose programming language for writing +grammars + +Uses of grammars: +- translation +- random generation +- multilingual syntax editing + + +Interpreter: grammars can be used in GF system + +Compiler: grammars can be translated to programs in C, Java, JavaScript... + + +#NEW + +===Demos=== + +Here are some things that one can build with GF. + +[Multilingual and multimodal dialogue system http://www.cs.chalmers.se/~bringert/demos/gotgodis/] + +[Translator applet http://www.cs.chalmers.se/~bringert/gf/translate/] + +[Multilingual authoring system http://www.cs.chalmers.se/~markus/gramlets/letter-applet.html] + +[Multilingual Wiki http://csmisc14.cs.chalmers.se/~meza/wiki/wiki.cgi] + +[Language Trainer http://csmisc14.cs.chalmers.se/~bjorn/langtrain.cgi] + +[Web-based Multimodal Dialogue System http://www.cs.chalmers.se/~bringert/xv/pizza/pizza-movie-large.html] + + + +#NEW + +===Grammar formats=== + +**Context-free grammars** (= **BNF**) can be used in GF +``` +-- file food.cf + +Is. S ::= Item "is" Quality ; +That. Item ::= "that" Kind ; +This. Item ::= "this" Kind ; +QKind. Kind ::= Quality Kind ; +Cheese. Kind ::= "cheese" ; +Fish. Kind ::= "fish" ; +Pizza. Kind ::= "pizza" ; +Wine. Kind ::= "wine" ; +Italian. Quality ::= "Italian" ; +Boring. Quality ::= "boring" ; +Delicious. Quality ::= "delicious" ; +Expensive. Quality ::= "expensive" ; +Fresh. Quality ::= "fresh" ; +Very. Quality ::= "very" Quality ; +Warm. Quality ::= "warm" ; +``` + + +#NEW + +===Using the grammar in GF interpreter=== + +Start GF +``` + $ gf +``` +Import a grammar +``` + > import food.cf +``` +**Parse** a **string** to a **tree** +``` + > parse "this pizza is delicious" + Is (This Pizza) Delicious +``` +**Linearize** a tree to a string +``` + > linearize Is (That Wine) (Very (Very Italian)) + that wine is very very Italian +``` + + +#NEW + +===Generation and pipes=== + +**Random-generate** a tree +``` + > generate_random + Is (This (QKind Fresh Fish)) Fresh +``` +Random-generate with a **pipe** to linearization +``` + > generate_random | linearize + this pizza is warm +``` +Random-generate with a pipe to linearization, preserving a **trace** +``` + > generate_random -tr | linearize + Is (That Fish) Boring + that fish is boring +``` + + + +#NEW + +===Abstract and concrete syntax=== + +Full GF format is more expressive than BNF: +- **Abstract syntax**: semantic structure, "what to say" +- **Concrete syntax**: linguistic expression, "how to say it" + + +BNF format mixes these two in one grammar + +GF takes them apart, which enables **multilingual grammars** +- one abstract syntax + several concrete syntaxes + + + +#NEW + +===Abstract syntax of the food example=== + +``` +-- file Food.gf + +abstract Food = { + + cat + Phrase ; Item ; Kind ; Quality ; + + flags startcat = Phrase ; + + fun + Is : Item -> Quality -> Phrase ; + This, That : Kind -> Item ; + QKind : Quality -> Kind -> Kind ; + Wine, Pizza, Cheese, Fish : Kind ; + Very : Quality -> Quality ; + Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ; +} +``` + + + +#NEW + +===English concrete syntax of the food example=== + +``` +-- file FoodEng.gf + +concrete FoodEng of Food = { + + lincat + Phrase, Item, Kind, Quality = {s : Str} ; + + lin + Is item quality = {s = item.s ++ "is" ++ quality.s} ; + This kind = {s = "this" ++ kind.s} ; + That kind = {s = "that" ++ kind.s} ; + QKind quality kind = {s = quality.s ++ kind.s} ; + Wine = {s = "wine"} ; + Pizza = {s = "pizza"} ; + Cheese = {s = "cheese"} ; + Fish = {s = "fish"} ; + Very quality = {s = "very" ++ quality.s} ; + Fresh = {s = "fresh"} ; + Warm = {s = "warm"} ; + Italian = {s = "Italian"} ; + Expensive = {s = "expensive"} ; + Delicious = {s = "delicious"} ; + Boring = {s = "boring"} ; +} +``` + + +#NEW + +===Italian concrete syntax of the food example=== + +``` +-- file FoodIta.gf + +concrete FoodIta of Food = { + + lincat + Phrase, Item, Kind, Quality = {s : Str} ; + + lin + Is item quality = {s = item.s ++ "è" ++ quality.s} ; + This kind = {s = "questo" ++ kind.s} ; + That kind = {s = "quello" ++ kind.s} ; + QKind quality kind = {s = kind.s ++ quality.s} ; + Wine = {s = "vino"} ; + Pizza = {s = "pizza"} ; + Cheese = {s = "formaggio"} ; + Fish = {s = "pesce"} ; + Very quality = {s = "molto" ++ quality.s} ; + Fresh = {s = "fresco"} ; + Warm = {s = "caldo"} ; + Italian = {s = "italiano"} ; + Expensive = {s = "caro"} ; + Delicious = {s = "delizioso"} ; + Boring = {s = "noioso"} ; +} +``` + + +#NEW + +===Translation and multilingual generation=== + +Import the grammars +``` + > import FoodEng.gf + > import FoodIta.gf +``` +**Translate**: parse in English, linearize in Italian +``` + > parse -lang=FoodEng "this Italian wine is very boring" | linearize -lang=FoodIta + questo vino italiano è molto noioso +``` +Random-generate and linearize to multiple languages +``` + > generate_random | linearize -multi + quello pesce è noioso + that fish is boring +``` + +#NEW + +===Translation quiz=== + +``` +> translation_quiz FoodEng FoodIta +Welcome to GF Translation Quiz. +The quiz is over when you have done at least 10 examples +with at least 75 % success. +You can interrupt the quiz by entering a line consisting of a dot ('.'). + +this cheese is boring +questo formaggio è noioso +> Yes. +Score 1/1 + +that delicious cheese is Italian +quello vino delicioso è italiano +> No, not quello vino delicioso è italiano, but +quello formaggio delizioso è italiano +Score 1/2 +``` + + + +#NEW + +===Swedish concrete syntax of the food example?=== + +Let's try it out: +``` +-- file FoodSwe.gf + +concrete FoodSwe of Food = { + + ... +} +``` +Just replace English words with Swedish words... ? + + + +#NEW + +===Problems with string-based grammars=== + +Errors in **inflection** and **agreement** + +Solution: records and parameters + +Large-scale solution: resource grammar libraries + + + +#NEW + +===Parameters=== }