Aarne Ranta

October 2011 for GF 3.3

Grammatical Framework Quick Start

This Quick Start shows a few examples of how GF can be used. We assume that you have downloaded and installed GF, so that the command gf works for you. See download and install instructions here.

Want to try without downloading?

Using GF translation with an existing grammar.

Writing GF grammars in the cloud, without installing GF.

Using GF for translation and generation

When you have downloaded and installed GF:
  1. Copy the files Food.gf, FoodEng.gf, and FoodIta.gf. Or go to GF/examples/tutorial/food/, if you have downloaded the GF sources.
  2. Start GF with the shell command (without the prompt $)
      $ gf FoodIta.gf FoodEng.gf
    
    Alternatively, start GF with gf and give the GF command import FoodIta.gf FoodEng.gf.
  3. Translation. Try your first translation by giving the GF command
      parse "this cheese is very very Italian" | linearize
    
    Notice that the parser accept the tabulator for word completion.
  4. Generation. Random-generate sentences in two languages:
      generate_random | linearize
    
  5. Other commands. Use the help command
      help
    
  6. More examples. Go to GF/examples/phrasebook or some other subdirectory of GF/examples/. Or try a resource grammar by, for instance,
      import alltenses/LangEng.gfo alltenses/LangGer.gfo
    
      parse -lang=Eng "I love you" | linearize -treebank
    
    The resource grammars are found relative to the value of GF_LIB_PATH, which you may have to set; see here for instructions.

Grammar development

Add words to the Food grammars and try the above commands again. For instance, add the following lines:
  Bread : Kind ;          -- in Food.gf
  Bread = {s = "bread"} ; -- in FoodEng.gf
  Bread = {s = "pane"} ;  -- in FoodIta.gf
and start GF again with the same command. Now you can even translate this bread is very Italian. To lear more on GF commands and grammar development, go to the one of the tutorials: To learn about how GF is used for easily writing grammars for 16 languages, consult the

Run-time grammars and web applications

GF has its own "machine language", PGF (Portable Grammar Format), which is recommended for use in applications at run time. To produce a PGF file from the two grammars above, do
  gf -make FoodIta.gf FoodEng.gf
  wrote Food.pgf
You can use this in Haskell and Java programs, and also on web services, such as The quickest way to provide a GF web service is to start GF with the -server option:
  $ gf -server
  This is GF version 3.3
  Built on linux/i386 with ghc-7.0, flags: interrupt server cclazy
  Document root = /usr/local/share/gf-3.3/www
  Starting HTTP server, open http://localhost:41296/ in your web browser.
You can view it locally by pointing your browser to the URL shown. You can add your own .pgf grammar to the service by copying it over to the documentRoot directory. Just push "reload" in your browser after each such update.

To build more customized web application, consult the developer wiki.

User group

You are welcome to join the User Group to get help and discuss GF-related issues!