From fd917d04eaa3b3295af55d598d735a407a0f2f41 Mon Sep 17 00:00:00 2001 From: aarne Date: Fri, 16 Dec 2005 20:25:52 +0000 Subject: tutorial elaboration --- doc/tutorial/gf-tutorial2.html | 156 +++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 61 deletions(-) (limited to 'doc/tutorial/gf-tutorial2.html') diff --git a/doc/tutorial/gf-tutorial2.html b/doc/tutorial/gf-tutorial2.html index 329b47ae3..d7365d029 100644 --- a/doc/tutorial/gf-tutorial2.html +++ b/doc/tutorial/gf-tutorial2.html @@ -7,7 +7,7 @@

Grammatical Framework Tutorial

Author: Aarne Ranta <aarne (at) cs.chalmers.se>
-Last update: Fri Dec 16 15:10:23 2005 +Last update: Fri Dec 16 21:04:37 2005

@@ -22,19 +22,32 @@ Last update: Fri Dec 16 15:10:23 2005 -
  • The GF grammar format +
  • The GF grammar format +
  • Topics still to be written + -
  • Topics still to be written

    @@ -102,7 +115,7 @@ Now you are ready to try out your first grammar. We start with one that is not written in GF language, but in the ubiquitous BNF notation (Backus Naur Form), which GF can also understand. Type (or copy) the following lines in a file named -paleolithic.ebnf: +paleolithic.cf:

         S   ::= NP VP ;
    @@ -120,38 +133,48 @@ understand. Type (or copy) the following lines in a file named
     stoneage,
     which implements a fragment of primitive language. This fragment
     was defined by the linguist Morris Swadesh as a tool for studying
    -the historical relations of languages. But as pointed out
    +the historical relations of languages. But as suggested
     in the Wiktionary article on
     Swadesh list, the
    -fragment is also usable for basic communication with foreigners.)
    +fragment is also usable for basic communication between foreigners.)
     

    Importing grammars and parsing strings

    The first GF command when using a grammar is to import it. The command has a long name, import, and a short name, i. +You can type either

    -    import paleolithic.gf
    +  import paleolithic.cf
     
    +

    -The GF program now compiles your grammar into an internal +or +

    +
    +  i paleolithic.cf
    +
    +

    +

    +to get the same effect. +The effect is that the GF program compiles your grammar into an internal representation, and shows a new prompt when it is ready.

    -You can use GF for parsing: +You can now use GF for parsing:

         > parse "the boy eats a snake"
    -    Mks_0 (Mks_6 Mks_9) (Mks_2 Mks_20 (Mks_7 Mks_11))
    +    S_NP_VP (NP_the_CN CN_boy) (VP_TV_NP TV_eats (NP_a_CN CN_snake))
       
         > parse "the snake eats a boy"
    -    Mks_0 (Mks_6 Mks_11) (Mks_2 Mks_20 (Mks_7 Mks_9))
    +    S_NP_VP (NP_the_CN CN_snake) (VP_TV_NP TV_eats (NP_a_CN CN_boy))
     

    The parse (= p) command takes a string (in double quotes) and returns an abstract syntax tree - the thing -with Mkss and parentheses. We will see soon how to make sense +beginning with S_NP_VP. We will see soon how to make sense of the abstract syntax trees - now you should just notice that the tree is different for the two strings.

    @@ -161,7 +184,7 @@ you imported. Try parsing something else, and you fail

         > p "hello world"
    -    No success in cf parsing
    +    No success in cf parsing hello world
         no tree found
     

    @@ -173,8 +196,8 @@ You can also use GF for linearizing parsing, taking trees into strings:

    -    > linearize Mks_0 (Mks_6 Mks_11) (Mks_2 Mks_20 (Mks_7 Mks_9))
    -    the snake eats a boy
    +    > linearize S_NP_VP (NP_the_CN CN_boy) (VP_TV_NP TV_eats (NP_a_CN CN_snake))
    +    the boy eats a snake
     

    What is the use of this? Typically not that you type in a tree at @@ -184,7 +207,7 @@ you can obtain a tree from somewhere else. One way to do so is

         > generate_random
    -    Mks_0 (Mks_4 Mks_11) (Mks_3 Mks_15)
    +    S_NP_VP (NP_this_CN (CN_A_CN A_thick CN_worm)) (VP_V V_sleeps)
     

    Now you can copy the tree and paste it to the linearize command. @@ -197,6 +220,24 @@ a pipe.

    +

    Visualizing trees

    +

    +The gibberish code with parentheses returned by the parser does not +look like trees. Why is it called so? Trees are a data structure that +represent <b>nesting</b>: trees are branching entities, and the branches +are themselves trees. Parentheses give a linear representation of trees, +useful for the computer. But the human eye may prefer to see a visualization; +for this purpose, GF provides the command visualizre_tree = vt, to which +parsing (and any other tree-producing command) can be piped: +

    +
    +  parse "the green boy eats a warm snake" | vt
    +
    +

    +

    + +

    +

    Some random-generated sentences

    Random generation can be quite amusing. So you may want to @@ -216,7 +257,7 @@ generate ten strings with one and the same command: a boy is green

    - +

    Systematic generation

    To generate <i>all<i> sentence that a grammar @@ -246,7 +287,7 @@ You get quite a few trees but not all of them: only up to a given Quiz. If the command gt generated all trees in your grammar, it would never terminate. Why?

    - +

    More on pipes; tracing

    A pipe of GF commands can have any length, but the "output type" @@ -269,7 +310,7 @@ This facility is good for test purposes: for instance, you may want to see if a grammar is ambiguous, i.e. contains strings that can be parsed in more than one way.

    - +

    Writing and reading files

    To save the outputs of GF commands into a file, you can @@ -292,7 +333,7 @@ the file separately. Without the flag, the grammar could not recognize the string in the file, because it is not a sentence but a sequence of ten sentences.

    - +

    Labelled context-free grammars

    The syntax trees returned by GF's parser in the previous examples @@ -389,7 +430,7 @@ old grammar from the GF shell state. a louse is thick

    - +

    The GF grammar format

    To see what there really is in GF's shell state when a grammar @@ -413,7 +454,7 @@ one more way of defining the same grammar as in Then we will show how the full GF grammar format enables you to do things that are not possible in the weaker formats.

    - +

    Abstract and concrete syntax

    A GF grammar consists of two main parts: @@ -893,7 +934,7 @@ The graph uses

    <img src="Gatherer.gif">

    - +

    Resource modules

    Suppose we want to say, with the vocabulary included in @@ -1039,7 +1080,7 @@ Resource modules can extend other resource modules, in the same way as modules of other types can extend modules of the same type.

    - +

    Opening a ``resource``

    Any number of resource modules can be @@ -1386,36 +1427,29 @@ GF currently requires that all fields in linearization records that have a table with value type Str have as labels either s or s with an integer index.

    - +

    Topics still to be written

    -

    -Free variation -

    -

    -Record extension, tuples -

    -

    -Predefined types and operations -

    -

    -Lexers and unlexers -

    -

    -Grammars of formal languages -

    -

    -Resource grammars and their reuse -

    -

    -Embedded grammars in Haskell and Java -

    -

    -Dependent types, variable bindings, semantic definitions -

    -

    -Transfer rules -

    + +

    Free variation

    + +

    Record extension, tuples

    + +

    Predefined types and operations

    + +

    Lexers and unlexers

    + +

    Grammars of formal languages

    + +

    Resource grammars and their reuse

    + +

    Embedded grammars in Haskell, Java, and Prolog

    + +

    Dependent types, variable bindings, semantic definitions

    + +

    Transfer modules

    + +

    Alternative input and output grammar formats

    - + -- cgit v1.2.3