updated tutorial and quickstart for 3.2

This commit is contained in:
aarne
2010-12-23 09:33:11 +00:00
parent 0b4aad88f6
commit 3036881d20
6 changed files with 556 additions and 105 deletions

View File

@@ -9,7 +9,7 @@
<p> <p>
Aarne Ranta Aarne Ranta
<p> <p>
22 December 2010 (3 September, 2007) December 2010 for GF 3.2
<p> <p>
@@ -42,12 +42,12 @@ GF sources.
<li> <b>Translation</b>. Try your first translation by giving the GF command <li> <b>Translation</b>. Try your first translation by giving the GF command
<pre> <pre>
parse "this cheese is very very Italian" | tree_bank parse "this cheese is very very Italian" | linearize -treebank
</pre> </pre>
<li> <b>Generation</b>. Random-generate sentences in two languages: <li> <b>Generation</b>. Random-generate sentences in two languages:
<pre> <pre>
generate_random | l -multi generate_random | linearize
</pre> </pre>
<li> <b>Grammar development</b>. Add words to the <tt>Food</tt> <li> <b>Grammar development</b>. Add words to the <tt>Food</tt>
@@ -66,6 +66,35 @@ grammar development, go to the one of the tutorials:
<li> <a href="tutorial/gf-tutorial.html">GF Tutorial</a>: older, more programmer-oriented <li> <a href="tutorial/gf-tutorial.html">GF Tutorial</a>: older, more programmer-oriented
<li> <a href="gf-lrec-2010.pdf">GF Resource Tutorial</a>: newer, more linguist-oriented <li> <a href="gf-lrec-2010.pdf">GF Resource Tutorial</a>: newer, more linguist-oriented
</ul> </ul>
To learn about how GF is used for easily writing grammars for 16 languages, consult the
<ul>
<li> <a href="../lib/doc/synopsis.html">GF Resource Grammar Library</a>.
</ul>
<h2>Run-time grammars and web applications</h2>
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
<pre>
gf -make FoodIta.gf FoodEng.gf
wrote Food.pgf
</pre>
You can use this in Haskell and Java programs, and also on web services, as shown in
<a href="http://www.grammaticalframework.org:41296/minibar/minibar.html">here</a>.
To build your own web application, consult the
<a href="http://code.google.com/p/grammatical-framework/wiki/SideBar?tm=6">developer wiki</a>.
<h2>User Group</h2>
You are welcome to join the <A HREF="http://groups.google.com/group/gf-dev">User Group</A>
to get help and discuss GF-related issues!
</body></html> </body></html>

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
Grammatical Framework Tutorial Grammatical Framework Tutorial
Aarne Ranta Aarne Ranta
December 2010 (November 2008) December 2010 for GF 3.2
% NOTE: this is a txt2tags file. % NOTE: this is a txt2tags file.
@@ -64,6 +64,7 @@ December 2010 (November 2008)
%!postproc(tex): #MYTREE "input{mytree}" %!postproc(tex): #MYTREE "input{mytree}"
%!preproc(html): #MYTREE [mytree.png] %!preproc(html): #MYTREE [mytree.png]
%!preproc(html): #MYPARSE [myparse.png]
%!postproc(tex): #FOODMARKET "input{foodmarket}" %!postproc(tex): #FOODMARKET "input{foodmarket}"
%!preproc(html): #FOODMARKET [foodmarket.png] %!preproc(html): #FOODMARKET [foodmarket.png]
%!postproc(tex): #CATEGORIES "input{categories}" %!postproc(tex): #CATEGORIES "input{categories}"
@@ -1283,7 +1284,13 @@ program (from the Graphviz package).
``` ```
% dot -Tpng _grph.dot > mytree.png % dot -Tpng _grph.dot > mytree.png
``` ```
You can also visualize **parse trees**, which show categories and words instead of
function symbols. The command is ``visualize_parse = vp``:
```
> parse "this delicious cheese is very Italian" | visualize_parse
```
#MYPARSE
#NEW #NEW
@@ -1296,9 +1303,9 @@ You can give a **system command** without leaving GF:
> ! open mytree.png > ! open mytree.png
``` ```
A system command may also receive its argument from A system command may also receive its argument from
a GF pipes. It then has the name ``sp`` = ``system_pipe``: a GF pipes. It then uses the symbol ``?``:
``` ```
> generate_trees -depth=4 | sp -command="wc -l" > generate_trees -depth=4 | ? wc -l
``` ```
This command example returns the number of generated trees. This command example returns the number of generated trees.
@@ -2766,23 +2773,27 @@ Goals:
==The coverage of the library== ==The coverage of the library==
The current 12 resource languages are The current 16 resource languages (GF version 3.2, December 2010) are
- ``Bul``garian - ``Bul``garian
- ``Cat``alan - ``Cat``alan
- ``Dan``ish - ``Dan``ish
- ``Dut``ch
- ``Eng``lish - ``Eng``lish
- ``Fin``nish - ``Fin``nish
- ``Fre``nch - ``Fre``nch
- ``Ger``man - ``Ger``man
- ``Ita``lian - ``Ita``lian
- ``Nor``wegian - ``Nor``wegian
- ``Pol``ish
- ``Ron``, Romanian
- ``Rus``sian - ``Rus``sian
- ``Spa``nish - ``Spa``nish
- ``Swe``dish - ``Swe``dish
- ``Urd``u
The first three letters (``Eng`` etc) are used in grammar module names The first three letters (``Eng`` etc) are used in grammar module names
(ISO 639 standard). (ISO 639-3 standard).
#NEW #NEW
@@ -2832,8 +2843,7 @@ Two kinds of lexical categories:
- structural words / function words, e.g. - structural words / function words, e.g.
``` ```
Conj ; -- conjunction e.g. "and" Conj ; -- conjunction e.g. "and"
QuantSg ; -- singular quantifier e.g. "this" Det ; -- determiner e.g. "this"
QuantPl ; -- plural quantifier e.g. "this"
``` ```
- **open**: - **open**:
@@ -2852,8 +2862,7 @@ Two kinds of lexical categories:
Closed classes: module ``Syntax``. In the ``Foods`` grammar, we need Closed classes: module ``Syntax``. In the ``Foods`` grammar, we need
``` ```
this_QuantSg, that_QuantSg : QuantSg ; this_Det, that_Det, these_Det, those_Det : Det ;
these_QuantPl, those_QuantPl : QuantPl ;
very_AdA : AdA ; very_AdA : AdA ;
``` ```
Naming convention: word followed by the category (so we can Naming convention: word followed by the category (so we can
@@ -2917,8 +2926,7 @@ Common nouns are made into noun phrases by adding determiners.
We need the following combinations: We need the following combinations:
``` ```
mkCl : NP -> AP -> Cl ; -- e.g. "this pizza is very warm" mkCl : NP -> AP -> Cl ; -- e.g. "this pizza is very warm"
mkNP : QuantSg -> CN -> NP ; -- e.g. "this pizza" mkNP : Det -> CN -> NP ; -- e.g. "this pizza"
mkNP : QuantPl -> CN -> NP ; -- e.g. "these pizzas"
mkCN : AP -> CN -> CN ; -- e.g. "warm pizza" mkCN : AP -> CN -> CN ; -- e.g. "warm pizza"
mkAP : AdA -> AP -> AP ; -- e.g. "very warm" mkAP : AdA -> AP -> AP ; -- e.g. "very warm"
``` ```
@@ -2944,7 +2952,7 @@ The sentence
can be built as follows: can be built as follows:
``` ```
mkCl mkCl
(mkNP these_QuantPl (mkNP these_Det
(mkCN (mkAP very_AdA (mkAP warm_A)) (mkCN pizza_CN))) (mkCN (mkAP very_AdA (mkAP warm_A)) (mkCN pizza_CN)))
(mkAP italian_AP) (mkAP italian_AP)
``` ```
@@ -2970,7 +2978,7 @@ Language-specific and language-independent parts - roughly,
Full API documentation on-line: the **resource synopsis**, Full API documentation on-line: the **resource synopsis**,
[``grammaticalframework.org/lib/resource/doc/synopsis.html`` http://grammaticalframework.org/lib/doc/synopsis.html] [``grammaticalframework.org/lib/doc/synopsis.html`` http://grammaticalframework.org/lib/doc/synopsis.html]
#NEW #NEW
@@ -2983,8 +2991,7 @@ Full API documentation on-line: the **resource synopsis**,
| ``CN`` | common noun (without determiner) | //red house// | | ``CN`` | common noun (without determiner) | //red house// |
| ``NP`` | noun phrase (subject or object) | //the red house// | | ``NP`` | noun phrase (subject or object) | //the red house// |
| ``AdA`` | adjective-modifying adverb, | //very// | | ``AdA`` | adjective-modifying adverb, | //very// |
| ``QuantSg`` | singular quantifier | //these// | | ``Det`` | determiner | //these// |
| ``QuantPl`` | plural quantifier | //this// |
| ``A`` | one-place adjective | //warm// | | ``A`` | one-place adjective | //warm// |
| ``N`` | common noun | //house// | | ``N`` | common noun | //house// |
@@ -2995,8 +3002,7 @@ Full API documentation on-line: the **resource synopsis**,
|| Function | Type | Example || || Function | Type | Example ||
| ``mkCl`` | ``NP -> AP -> Cl`` | //John is very old// | | ``mkCl`` | ``NP -> AP -> Cl`` | //John is very old// |
| ``mkNP`` | ``QuantSg -> CN -> NP`` | //this old man// | | ``mkNP`` | ``Det -> CN -> NP`` | //these old man// |
| ``mkNP`` | ``QuantPl -> CN -> NP`` | //these old man// |
| ``mkCN`` | ``N -> CN`` | //house// | | ``mkCN`` | ``N -> CN`` | //house// |
| ``mkCN`` | ``AP -> CN -> CN`` | //very big blue house// | | ``mkCN`` | ``AP -> CN -> CN`` | //very big blue house// |
| ``mkAP`` | ``A -> AP`` | //old// | | ``mkAP`` | ``A -> AP`` | //old// |
@@ -3007,10 +3013,10 @@ Full API documentation on-line: the **resource synopsis**,
===A miniature resource API: structural words=== ===A miniature resource API: structural words===
|| Function | Type | In English || || Function | Type | In English ||
| ``this_QuantSg`` | ``QuantSg`` | //this// | | ``this_Det`` | ``Det`` | //this// |
| ``that_QuantSg`` | ``QuantSg`` | //that// | | ``that_Det`` | ``Det`` | //that// |
| ``these_QuantPl`` | ``QuantPl`` | //this// | | ``these_Det`` | ``Det`` | //this// |
| ``those_QuantPl`` | ``QuantPl`` | //that// | | ``those_Det`` | ``Det`` | //that// |
| ``very_AdA`` | ``AdA`` | //very// | | ``very_AdA`` | ``AdA`` | //very// |
@@ -3112,10 +3118,10 @@ Now the combination rules we need almost write themselves automatically:
``` ```
lin lin
Is item quality = mkCl item quality ; Is item quality = mkCl item quality ;
This kind = mkNP this_QuantSg kind ; This kind = mkNP this_Det kind ;
That kind = mkNP that_QuantSg kind ; That kind = mkNP that_Det kind ;
These kind = mkNP these_QuantPl kind ; These kind = mkNP these_Det kind ;
Those kind = mkNP those_QuantPl kind ; Those kind = mkNP those_Det kind ;
QKind quality kind = mkCN quality kind ; QKind quality kind = mkCN quality kind ;
Very quality = mkAP very_AdA quality ; Very quality = mkAP very_AdA quality ;
``` ```
@@ -3234,10 +3240,10 @@ we can write a **functor instantiation**,
Quality = AP ; Quality = AP ;
lin lin
Is item quality = mkCl item quality ; Is item quality = mkCl item quality ;
This kind = mkNP this_QuantSg kind ; This kind = mkNP this_Det kind ;
That kind = mkNP that_QuantSg kind ; That kind = mkNP that_Det kind ;
These kind = mkNP these_QuantPl kind ; These kind = mkNP these_Det kind ;
Those kind = mkNP those_QuantPl kind ; Those kind = mkNP those_Det kind ;
QKind quality kind = mkCN quality kind ; QKind quality kind = mkCN quality kind ;
Very quality = mkAP very_AdA quality ; Very quality = mkAP very_AdA quality ;
@@ -4530,10 +4536,10 @@ This facility is based on several components:
The portable format is called PGF, "Portable Grammar Format". The portable format is called PGF, "Portable Grammar Format".
This format is produced by the GF batch compiler ``gf``, This format is produced by using GF as batch compiler, with the option ``-make``,
executable from the operative system shell: from the operative system shell:
``` ```
% gf --make SOURCE.gf % gf -make SOURCE.gf
``` ```
PGF is the recommended format in PGF is the recommended format in
which final grammar products are distributed, because they which final grammar products are distributed, because they
@@ -4598,7 +4604,7 @@ translate gr s = case parseAllLang gr (startCat gr) s of
``` ```
To run the translator, first compile it by To run the translator, first compile it by
``` ```
% ghc --make -o trans Translator.hs % ghc -make -o trans Translator.hs
``` ```
For this, you need the Haskell compiler [GHC http://www.haskell.org/ghc]. For this, you need the Haskell compiler [GHC http://www.haskell.org/ghc].
@@ -4610,7 +4616,7 @@ For this, you need the Haskell compiler [GHC http://www.haskell.org/ghc].
Then produce a PGF file. For instance, the ``Food`` grammar set can be Then produce a PGF file. For instance, the ``Food`` grammar set can be
compiled as follows: compiled as follows:
``` ```
% gf --make FoodEng.gf FoodIta.gf % gf -make FoodEng.gf FoodIta.gf
``` ```
This produces the file ``Food.pgf`` (its name comes from the abstract syntax). This produces the file ``Food.pgf`` (its name comes from the abstract syntax).
@@ -4718,7 +4724,7 @@ abstract syntax to a system of Haskell datatypes:
``` ```
It is also possible to produce the Haskell file together with PGF, by It is also possible to produce the Haskell file together with PGF, by
``` ```
% gf --make --output-format=haskell QueryEng.gf % gf -make --output-format=haskell QueryEng.gf
``` ```
The result is a file named ``Query.hs``, containing a The result is a file named ``Query.hs``, containing a
module named ``Query``. module named ``Query``.
@@ -4871,7 +4877,7 @@ translate tr gr s = case parseAllLang gr (startCat gr) s of
To automate the production of the system, we write a ``Makefile`` as follows: To automate the production of the system, we write a ``Makefile`` as follows:
``` ```
all: all:
gf --make --output-format=haskell QueryEng gf -make --output-format=haskell QueryEng
ghc --make -o ./math TransferLoop.hs ghc --make -o ./math TransferLoop.hs
strip math strip math
``` ```
@@ -4928,7 +4934,7 @@ program compiled from GF grammars as run on an iPhone.
JavaScript is one of the output formats of the GF batch compiler. Thus the following JavaScript is one of the output formats of the GF batch compiler. Thus the following
command generates a JavaScript file from two ``Food`` grammars. command generates a JavaScript file from two ``Food`` grammars.
``` ```
% gf --make --output-format=js FoodEng.gf FoodIta.gf % gf -make --output-format=js FoodEng.gf FoodIta.gf
``` ```
The name of the generated file is ``Food.js``, derived from the top-most abstract The name of the generated file is ``Food.js``, derived from the top-most abstract
syntax name. This file contains the multilingual grammar as a JavaScript object. syntax name. This file contains the multilingual grammar as a JavaScript object.
@@ -4974,7 +4980,7 @@ GSL is produced from GF by running ``gf`` with the flag
Example: GSL generated from ``FoodsEng.gf``. Example: GSL generated from ``FoodsEng.gf``.
``` ```
% gf --make --output-format=gsl FoodsEng.gf % gf -make --output-format=gsl FoodsEng.gf
% more FoodsEng.gsl % more FoodsEng.gsl
;GSL2.0 ;GSL2.0

View File

@@ -35,10 +35,10 @@ incomplete concrete ExtFoodsI of ExtFoods = FoodsI ** open Syntax, LexFoods in {
You = mkNP youPol_Pron ; You = mkNP youPol_Pron ;
We = mkNP we_Pron ; We = mkNP we_Pron ;
GThis = mkNP this_QuantSg ; GThis = mkNP this_Det ;
GThat = mkNP that_QuantSg ; GThat = mkNP that_Det ;
GThese = mkNP these_QuantPl ; GThese = mkNP these_Det ;
GThose = mkNP those_QuantPl ; GThose = mkNP those_Det ;
Eat = eat_V2 ; Eat = eat_V2 ;
Drink = drink_V2 ; Drink = drink_V2 ;

View File

@@ -8,10 +8,10 @@ concrete FoodsEng of Foods = open SyntaxEng,ParadigmsEng in {
Quality = AP ; Quality = AP ;
lin lin
Is item quality = mkCl item quality ; Is item quality = mkCl item quality ;
This kind = mkNP this_Quant kind ; This kind = mkNP this_Det kind ;
That kind = mkNP that_Quant kind ; That kind = mkNP that_Det kind ;
These kind = mkNP this_Quant plNum kind ; These kind = mkNP these_Det kind ;
Those kind = mkNP that_Quant plNum kind ; Those kind = mkNP those_Det kind ;
QKind quality kind = mkCN quality kind ; QKind quality kind = mkCN quality kind ;
Wine = mkCN (mkN "wine") ; Wine = mkCN (mkN "wine") ;
Pizza = mkCN (mkN "pizza") ; Pizza = mkCN (mkN "pizza") ;

View File

@@ -9,10 +9,10 @@ incomplete concrete FoodsI of Foods = open Syntax, LexFoods in {
lin lin
Is item quality = mkUtt (mkCl item quality) ; Is item quality = mkUtt (mkCl item quality) ;
Isnt item quality = mkUtt (mkS negativePol (mkCl item quality)) ; Isnt item quality = mkUtt (mkS negativePol (mkCl item quality)) ;
This kind = mkNP this_Quant kind ; This kind = mkNP this_Det kind ;
That kind = mkNP that_Quant kind ; That kind = mkNP that_Det kind ;
These kind = mkNP this_Quant plNum kind ; These kind = mkNP these_Det kind ;
Those kind = mkNP that_Quant plNum kind ; Those kind = mkNP those_Det kind ;
QKind quality kind = mkCN quality kind ; QKind quality kind = mkCN quality kind ;
Very quality = mkAP very_AdA quality ; Very quality = mkAP very_AdA quality ;