summaryrefslogtreecommitdiff
path: root/doc/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'doc/tutorial')
-rw-r--r--doc/tutorial/Foods.gf4
-rw-r--r--doc/tutorial/FoodsEng.gf11
-rw-r--r--doc/tutorial/applications/Comments.gf12
-rw-r--r--doc/tutorial/applications/CommentsEng.gf2
-rw-r--r--doc/tutorial/applications/CommentsI.gf21
-rw-r--r--doc/tutorial/applications/CommentsIta.gf2
-rw-r--r--doc/tutorial/applications/FoodComments.gf7
-rw-r--r--doc/tutorial/applications/FoodCommentsEng.gf18
-rw-r--r--doc/tutorial/applications/FoodCommentsIta.gf17
-rw-r--r--doc/tutorial/gf-tutorial2.html552
-rw-r--r--doc/tutorial/gf-tutorial2.txt228
-rw-r--r--doc/tutorial/resource/LexEng.gf34
-rw-r--r--doc/tutorial/resource/LexFoods.gf4
-rw-r--r--doc/tutorial/resource/LexIta.gf46
-rw-r--r--doc/tutorial/resource/MorphoEng.gf (renamed from doc/tutorial/MorphoEng.gf)0
-rw-r--r--doc/tutorial/resource/MorphoIta.gf87
-rw-r--r--doc/tutorial/resource/Syntax.gf46
-rw-r--r--doc/tutorial/resource/SyntaxEng.gf67
-rw-r--r--doc/tutorial/resource/SyntaxIta.gf81
19 files changed, 1036 insertions, 203 deletions
diff --git a/doc/tutorial/Foods.gf b/doc/tutorial/Foods.gf
index 985eff0c8..9337e234a 100644
--- a/doc/tutorial/Foods.gf
+++ b/doc/tutorial/Foods.gf
@@ -5,9 +5,9 @@ abstract Foods = {
fun
Is : Item -> Quality -> S ;
- This, That, All, Most : Kind -> Item ;
+ This, That, These, Those : Kind -> Item ;
QKind : Quality -> Kind -> Kind ;
- Wine, Cheese, Fish : Kind ;
+ Wine, Cheese, Fish, Pizza : Kind ;
Very : Quality -> Quality ;
Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ;
diff --git a/doc/tutorial/FoodsEng.gf b/doc/tutorial/FoodsEng.gf
index 1899c0e96..ee3857166 100644
--- a/doc/tutorial/FoodsEng.gf
+++ b/doc/tutorial/FoodsEng.gf
@@ -1,4 +1,4 @@
---# -path=.:prelude
+--# -path=.:resource:prelude
concrete FoodsEng of Foods = open Prelude, MorphoEng in {
@@ -9,14 +9,15 @@ concrete FoodsEng of Foods = open Prelude, MorphoEng in {
lin
Is item quality = ss (item.s ++ (mkVerb "are" "is").s ! item.n ++ quality.s) ;
- This = det Sg "this" ;
- That = det Sg "that" ;
- All = det Pl "all" ;
- Most = det Pl "most" ;
+ This = det Sg "this" ;
+ That = det Sg "that" ;
+ These = det Pl "these" ;
+ Those = det Pl "those" ;
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
Wine = regNoun "wine" ;
Cheese = regNoun "cheese" ;
Fish = mkNoun "fish" "fish" ;
+ Pizza = regNoun "pizza" ;
Very = prefixSS "very" ;
Fresh = ss "fresh" ;
Warm = ss "warm" ;
diff --git a/doc/tutorial/applications/Comments.gf b/doc/tutorial/applications/Comments.gf
new file mode 100644
index 000000000..3801ee77a
--- /dev/null
+++ b/doc/tutorial/applications/Comments.gf
@@ -0,0 +1,12 @@
+abstract Comments = {
+
+ cat
+ S ; Item ; Kind ; Quality ;
+
+ fun
+ Is : Item -> Quality -> S ;
+ This, That, These, Those : Kind -> Item ;
+ QKind : Quality -> Kind -> Kind ;
+ Very : Quality -> Quality ;
+
+}
diff --git a/doc/tutorial/applications/CommentsEng.gf b/doc/tutorial/applications/CommentsEng.gf
new file mode 100644
index 000000000..cd8879118
--- /dev/null
+++ b/doc/tutorial/applications/CommentsEng.gf
@@ -0,0 +1,2 @@
+concrete CommentsEng of Comments = CommentsI with
+ (Syntax = SyntaxEng) ;
diff --git a/doc/tutorial/applications/CommentsI.gf b/doc/tutorial/applications/CommentsI.gf
new file mode 100644
index 000000000..d21150ff0
--- /dev/null
+++ b/doc/tutorial/applications/CommentsI.gf
@@ -0,0 +1,21 @@
+--# -path=.:prelude
+
+incomplete concrete CommentsI of Comments = open Syntax in {
+
+ lincat
+ S = Syntax.S ;
+ Quality = AP ;
+ Kind = CN ;
+ Item = NP ;
+
+ lin
+ Is item quality = PosVP item (PredAP quality) ;
+ This = DetCN this_Det ;
+ That = DetCN that_Det ;
+ These = DetCN these_Det ;
+ Those = DetCN those_Det ;
+ QKind = ModCN ;
+ Very = AdAP very_AdA ;
+
+}
+ \ No newline at end of file
diff --git a/doc/tutorial/applications/CommentsIta.gf b/doc/tutorial/applications/CommentsIta.gf
new file mode 100644
index 000000000..eb60a8935
--- /dev/null
+++ b/doc/tutorial/applications/CommentsIta.gf
@@ -0,0 +1,2 @@
+concrete CommentsIta of Comments = CommentsI with
+ (Syntax = SyntaxIta) ;
diff --git a/doc/tutorial/applications/FoodComments.gf b/doc/tutorial/applications/FoodComments.gf
new file mode 100644
index 000000000..2d9f7013b
--- /dev/null
+++ b/doc/tutorial/applications/FoodComments.gf
@@ -0,0 +1,7 @@
+abstract FoodComments = Comments ** {
+
+ fun
+ Wine, Cheese, Fish, Pizza : Kind ;
+ Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ;
+
+}
diff --git a/doc/tutorial/applications/FoodCommentsEng.gf b/doc/tutorial/applications/FoodCommentsEng.gf
new file mode 100644
index 000000000..4ac054dd3
--- /dev/null
+++ b/doc/tutorial/applications/FoodCommentsEng.gf
@@ -0,0 +1,18 @@
+--# -path=.:../resource:prelude
+
+
+concrete FoodCommentsEng of FoodComments = CommentsEng ** open LexEng in {
+
+ lin
+ Wine = regN "wine" ;
+ Cheese = regN "cheese" ;
+ Fish = mkN "fish" "fish" ;
+ Pizza = regN "pizza" ;
+ Fresh = mkA "fresh" ;
+ Warm = mkA "warm" ;
+ Italian = mkA "Italian" ;
+ Expensive = mkA "expensive" ;
+ Delicious = mkA "delicious" ;
+ Boring = mkA "boring" ;
+
+}
diff --git a/doc/tutorial/applications/FoodCommentsIta.gf b/doc/tutorial/applications/FoodCommentsIta.gf
new file mode 100644
index 000000000..a75c4a8b7
--- /dev/null
+++ b/doc/tutorial/applications/FoodCommentsIta.gf
@@ -0,0 +1,17 @@
+--# -path=.:../resource:prelude
+
+concrete FoodCommentsIta of FoodComments = CommentsIta ** open LexIta in {
+
+ lin
+ Wine = regN "vino" ;
+ Cheese = mkN masculine "formaggio" "formaggi" ;
+ Fish = regN "pesce" ;
+ Pizza = regN "pizza" ;
+ Fresh = mkA "fresco" "fresca" "freschi" "fresche" ;
+ Warm = regA "caldo" ;
+ Italian = regA "italiano" ;
+ Expensive = regA "caro" ;
+ Delicious = regA "delizioso" ;
+ Boring = regA "noioso" ;
+
+}
diff --git a/doc/tutorial/gf-tutorial2.html b/doc/tutorial/gf-tutorial2.html
index 1fc1dd015..85d69fbcb 100644
--- a/doc/tutorial/gf-tutorial2.html
+++ b/doc/tutorial/gf-tutorial2.html
@@ -7,115 +7,120 @@
<P ALIGN="center"><CENTER><H1>Grammatical Framework Tutorial</H1>
<FONT SIZE="4">
<I>Author: Aarne Ranta &lt;aarne (at) cs.chalmers.se&gt;</I><BR>
-Last update: Sun Dec 18 22:29:50 2005
+Last update: Mon Dec 19 17:31:35 2005
</FONT></CENTER>
<P></P>
<HR NOSHADE SIZE=1>
<P></P>
<UL>
- <LI><A HREF="#toc1">GF = Grammatical Framework</A>
+ <LI><A HREF="#toc1">Introduction</A>
<UL>
- <LI><A HREF="#toc2">Getting the GF program</A>
+ <LI><A HREF="#toc2">GF = Grammatical Framework</A>
+ <LI><A HREF="#toc3">What are GF grammars used for</A>
+ <LI><A HREF="#toc4">Who is this tutorial for</A>
+ <LI><A HREF="#toc5">The coverage of the tutorial</A>
+ <LI><A HREF="#toc6">Getting the GF program</A>
</UL>
- <LI><A HREF="#toc3">The ``.cf`` grammar format</A>
+ <LI><A HREF="#toc7">The .cf grammar format</A>
<UL>
- <LI><A HREF="#toc4">Importing grammars and parsing strings</A>
- <LI><A HREF="#toc5">Generating trees and strings</A>
- <LI><A HREF="#toc6">Visualizing trees</A>
- <LI><A HREF="#toc7">Some random-generated sentences</A>
- <LI><A HREF="#toc8">Systematic generation</A>
- <LI><A HREF="#toc9">More on pipes; tracing</A>
- <LI><A HREF="#toc10">Writing and reading files</A>
- <LI><A HREF="#toc11">Labelled context-free grammars</A>
- <LI><A HREF="#toc12">The labelled context-free format</A>
+ <LI><A HREF="#toc8">Importing grammars and parsing strings</A>
+ <LI><A HREF="#toc9">Generating trees and strings</A>
+ <LI><A HREF="#toc10">Visualizing trees</A>
+ <LI><A HREF="#toc11">Some random-generated sentences</A>
+ <LI><A HREF="#toc12">Systematic generation</A>
+ <LI><A HREF="#toc13">More on pipes; tracing</A>
+ <LI><A HREF="#toc14">Writing and reading files</A>
+ <LI><A HREF="#toc15">Labelled context-free grammars</A>
+ <LI><A HREF="#toc16">The labelled context-free format</A>
</UL>
- <LI><A HREF="#toc13">The ``.gf`` grammar format</A>
+ <LI><A HREF="#toc17">The ``.gf`` grammar format</A>
<UL>
- <LI><A HREF="#toc14">Abstract and concrete syntax</A>
- <LI><A HREF="#toc15">Judgement forms</A>
- <LI><A HREF="#toc16">Module types</A>
- <LI><A HREF="#toc17">Record types, records, and ``Str``s</A>
- <LI><A HREF="#toc18">An abstract syntax example</A>
- <LI><A HREF="#toc19">A concrete syntax example</A>
- <LI><A HREF="#toc20">Modules and files</A>
+ <LI><A HREF="#toc18">Abstract and concrete syntax</A>
+ <LI><A HREF="#toc19">Judgement forms</A>
+ <LI><A HREF="#toc20">Module types</A>
+ <LI><A HREF="#toc21">Record types, records, and ``Str``s</A>
+ <LI><A HREF="#toc22">An abstract syntax example</A>
+ <LI><A HREF="#toc23">A concrete syntax example</A>
+ <LI><A HREF="#toc24">Modules and files</A>
</UL>
- <LI><A HREF="#toc21">Multilingual grammars and translation</A>
+ <LI><A HREF="#toc25">Multilingual grammars and translation</A>
<UL>
- <LI><A HREF="#toc22">An Italian concrete syntax</A>
- <LI><A HREF="#toc23">Using a multilingual grammar</A>
- <LI><A HREF="#toc24">Translation session</A>
- <LI><A HREF="#toc25">Translation quiz</A>
+ <LI><A HREF="#toc26">An Italian concrete syntax</A>
+ <LI><A HREF="#toc27">Using a multilingual grammar</A>
+ <LI><A HREF="#toc28">Translation session</A>
+ <LI><A HREF="#toc29">Translation quiz</A>
</UL>
- <LI><A HREF="#toc26">Grammar architecture</A>
+ <LI><A HREF="#toc30">Grammar architecture</A>
<UL>
- <LI><A HREF="#toc27">Extending a grammar</A>
- <LI><A HREF="#toc28">Multiple inheritance</A>
- <LI><A HREF="#toc29">Visualizing module structure</A>
+ <LI><A HREF="#toc31">Extending a grammar</A>
+ <LI><A HREF="#toc32">Multiple inheritance</A>
+ <LI><A HREF="#toc33">Visualizing module structure</A>
</UL>
- <LI><A HREF="#toc30">System commands</A>
- <LI><A HREF="#toc31">Resource modules</A>
+ <LI><A HREF="#toc34">System commands</A>
+ <LI><A HREF="#toc35">Resource modules</A>
<UL>
- <LI><A HREF="#toc32">The golden rule of functional programming</A>
- <LI><A HREF="#toc33">Operation definitions</A>
- <LI><A HREF="#toc34">The ``resource`` module type</A>
- <LI><A HREF="#toc35">Opening a ``resource``</A>
- <LI><A HREF="#toc36">Division of labour</A>
+ <LI><A HREF="#toc36">The golden rule of functional programming</A>
+ <LI><A HREF="#toc37">Operation definitions</A>
+ <LI><A HREF="#toc38">The ``resource`` module type</A>
+ <LI><A HREF="#toc39">Opening a ``resource``</A>
+ <LI><A HREF="#toc40">Division of labour</A>
</UL>
- <LI><A HREF="#toc37">Morphology</A>
+ <LI><A HREF="#toc41">Morphology</A>
<UL>
- <LI><A HREF="#toc38">Parameters and tables</A>
- <LI><A HREF="#toc39">Inflection tables, paradigms, and ``oper`` definitions</A>
- <LI><A HREF="#toc40">Worst-case macros and data abstraction</A>
- <LI><A HREF="#toc41">A system of paradigms using ``Prelude`` operations</A>
- <LI><A HREF="#toc42">An intelligent noun paradigm using ``case`` expressions</A>
- <LI><A HREF="#toc43">Pattern matching</A>
- <LI><A HREF="#toc44">Morphological ``resource`` modules</A>
- <LI><A HREF="#toc45">Testing ``resource`` modules</A>
+ <LI><A HREF="#toc42">Parameters and tables</A>
+ <LI><A HREF="#toc43">Inflection tables, paradigms, and ``oper`` definitions</A>
+ <LI><A HREF="#toc44">Worst-case macros and data abstraction</A>
+ <LI><A HREF="#toc45">A system of paradigms using ``Prelude`` operations</A>
+ <LI><A HREF="#toc46">An intelligent noun paradigm using ``case`` expressions</A>
+ <LI><A HREF="#toc47">Pattern matching</A>
+ <LI><A HREF="#toc48">Morphological ``resource`` modules</A>
+ <LI><A HREF="#toc49">Testing ``resource`` modules</A>
</UL>
- <LI><A HREF="#toc46">Using morphology in concrete syntax</A>
+ <LI><A HREF="#toc50">Using morphology in concrete syntax</A>
<UL>
- <LI><A HREF="#toc47">Parametric vs. inherent features, agreement</A>
- <LI><A HREF="#toc48">English concrete syntax with parameters</A>
- <LI><A HREF="#toc49">Hierarchic parameter types</A>
- <LI><A HREF="#toc50">Morphological analysis and morphology quiz</A>
- <LI><A HREF="#toc51">Discontinuous constituents</A>
+ <LI><A HREF="#toc51">Parametric vs. inherent features, agreement</A>
+ <LI><A HREF="#toc52">English concrete syntax with parameters</A>
+ <LI><A HREF="#toc53">Hierarchic parameter types</A>
+ <LI><A HREF="#toc54">Morphological analysis and morphology quiz</A>
+ <LI><A HREF="#toc55">Discontinuous constituents</A>
</UL>
- <LI><A HREF="#toc52">More constructs for concrete syntax</A>
+ <LI><A HREF="#toc56">More constructs for concrete syntax</A>
<UL>
- <LI><A HREF="#toc53">Free variation</A>
- <LI><A HREF="#toc54">Record extension and subtyping</A>
- <LI><A HREF="#toc55">Tuples and product types</A>
- <LI><A HREF="#toc56">Prefix-dependent choices</A>
- <LI><A HREF="#toc57">Predefined types and operations</A>
+ <LI><A HREF="#toc57">Local definitions</A>
+ <LI><A HREF="#toc58">Free variation</A>
+ <LI><A HREF="#toc59">Record extension and subtyping</A>
+ <LI><A HREF="#toc60">Tuples and product types</A>
+ <LI><A HREF="#toc61">Prefix-dependent choices</A>
+ <LI><A HREF="#toc62">Predefined types and operations</A>
</UL>
- <LI><A HREF="#toc58">More features of the module system</A>
+ <LI><A HREF="#toc63">More features of the module system</A>
<UL>
- <LI><A HREF="#toc59">Resource grammars and their reuse</A>
- <LI><A HREF="#toc60">Interfaces, instances, and functors</A>
- <LI><A HREF="#toc61">Restricted inheritance and qualified opening</A>
+ <LI><A HREF="#toc64">Resource grammars and their reuse</A>
+ <LI><A HREF="#toc65">Interfaces, instances, and functors</A>
+ <LI><A HREF="#toc66">Restricted inheritance and qualified opening</A>
</UL>
- <LI><A HREF="#toc62">More concepts of abstract syntax</A>
+ <LI><A HREF="#toc67">More concepts of abstract syntax</A>
<UL>
- <LI><A HREF="#toc63">Dependent types</A>
- <LI><A HREF="#toc64">Higher-order abstract syntax</A>
- <LI><A HREF="#toc65">Semantic definitions</A>
+ <LI><A HREF="#toc68">Dependent types</A>
+ <LI><A HREF="#toc69">Higher-order abstract syntax</A>
+ <LI><A HREF="#toc70">Semantic definitions</A>
</UL>
- <LI><A HREF="#toc66">Transfer modules</A>
- <LI><A HREF="#toc67">Practical issues</A>
+ <LI><A HREF="#toc71">Transfer modules</A>
+ <LI><A HREF="#toc72">Practical issues</A>
<UL>
- <LI><A HREF="#toc68">Lexers and unlexers</A>
- <LI><A HREF="#toc69">Efficiency of grammars</A>
- <LI><A HREF="#toc70">Speech input and output</A>
- <LI><A HREF="#toc71">Multilingual syntax editor</A>
- <LI><A HREF="#toc72">Interactive Development Environment (IDE)</A>
- <LI><A HREF="#toc73">Communicating with GF</A>
- <LI><A HREF="#toc74">Embedded grammars in Haskell, Java, and Prolog</A>
- <LI><A HREF="#toc75">Alternative input and output grammar formats</A>
+ <LI><A HREF="#toc73">Lexers and unlexers</A>
+ <LI><A HREF="#toc74">Efficiency of grammars</A>
+ <LI><A HREF="#toc75">Speech input and output</A>
+ <LI><A HREF="#toc76">Multilingual syntax editor</A>
+ <LI><A HREF="#toc77">Interactive Development Environment (IDE)</A>
+ <LI><A HREF="#toc78">Communicating with GF</A>
+ <LI><A HREF="#toc79">Embedded grammars in Haskell, Java, and Prolog</A>
+ <LI><A HREF="#toc80">Alternative input and output grammar formats</A>
</UL>
- <LI><A HREF="#toc76">Case studies</A>
+ <LI><A HREF="#toc81">Case studies</A>
<UL>
- <LI><A HREF="#toc77">Interfacing formal and natural languages</A>
+ <LI><A HREF="#toc82">Interfacing formal and natural languages</A>
</UL>
</UL>
@@ -126,7 +131,9 @@ Last update: Sun Dec 18 22:29:50 2005
<IMG ALIGN="middle" SRC="../gf-logo.gif" BORDER="0" ALT="">
</P>
<A NAME="toc1"></A>
-<H2>GF = Grammatical Framework</H2>
+<H2>Introduction</H2>
+<A NAME="toc2"></A>
+<H3>GF = Grammatical Framework</H3>
<P>
The term GF is used for different things:
</P>
@@ -147,7 +154,161 @@ It will guide you
<LI>to write programs in which GF grammars are used as components
</UL>
-<A NAME="toc2"></A>
+<A NAME="toc3"></A>
+<H3>What are GF grammars used for</H3>
+<P>
+A grammar is a definition of a language.
+From this definition, different language processing components
+can be derived:
+</P>
+<UL>
+<LI>parsing: to analyse the language
+<LI>linearization: to generate the language
+<LI>translation: to analyse one language and generate another
+</UL>
+
+<P>
+A GF grammar can be seen as a declarative program from which these
+processing tasks can be automatically derived. In addition, many
+other tasks are readily available for GF grammars:
+</P>
+<UL>
+<LI>morphological analysis: find out the possible inflection forms of words
+<LI>morphological synthesis: generate all inflection forms of words
+<LI>random generation: generate random expressions
+<LI>corpus generation: generate all expressions
+<LI>teaching quizzes: train morphology and translation
+<LI>multilingual authoring: create a document in many languages simultaneously
+<LI>speech input: optimize a speech recognition system for your grammar
+</UL>
+
+<P>
+A typical GF application is based on a <B>multilingual grammar</B> involving
+translation on a special domain. Existing applications of this idea include
+</P>
+<UL>
+<LI><A HREF="http://www.cs.chalmers.se/%7Ehallgren/Alfa/Tutorial/GFplugin.html">Alfa:</A>:
+ a natural-language interface to a proof editor
+ (languages: English, French, Swedish)
+<LI><A HREF="http://www.key-project.org/">KeY</A>:
+ a multilingual authoring system for creating software specifications
+ (languages: OCL, English, German)
+<LI><A HREF="http://www.talk-project.org">TALK</A>:
+ multilingual and multimodal dialogue systems
+<LI><A HREF="http://webalt.math.helsinki.fi/content/index_eng.html">WebALT</A>:
+ a multilingual translator of mathematical exercises
+ (languages: Catalan, English, Finnish, French, Spanish, Swedish)
+<LI><A HREF="http://www.cs.chalmers.se/~bringert/gf/translate/">Numeral translator</A>:
+ number words from 1 to 999,999
+ (88 languages)
+</UL>
+
+<P>
+The specialization of a grammar to a domain makes it possible to
+obtain much better translations than in an unlimited machine translation
+system. This is due to the well-defined semantics of such domains.
+Grammars having this character are called <B>application grammars</B>.
+They are different from most grammars written by linguists just
+because they are multilingual and domain-specific.
+</P>
+<P>
+However, there is another kind of grammars, which we call <B>resource grammars</B>.
+These are large, comprehensive grammars that can be used on any domain.
+The GF Resource Grammar Library has resource grammars for 10 languages.
+These grammars can be used as <B>libraries</B> to define application grammars.
+In this way, it is possible to write a high-quality grammar without
+knowing about linguistics: in general, to write an application grammar
+by using the resource library just requires practical knowledge of
+the target language.
+</P>
+<A NAME="toc4"></A>
+<H3>Who is this tutorial for</H3>
+<P>
+This tutorial is mainly for programmers who want to learn to write
+application grammars. It will go through GF's programming concepts
+without entering too deep into linguistics. Thus it should
+be accessible to anyone who has some previous programming experience.
+</P>
+<P>
+A separate document is being written on how to write resource grammars.
+This includes the ways in which linguistic problems posed by different
+languages are solved in GF.
+</P>
+<A NAME="toc5"></A>
+<H3>The coverage of the tutorial</H3>
+<P>
+The tutorial gives a hands-on introduction to grammar writing.
+We start by building a small grammar for the domain of food:
+in this grammar, you can say things like
+</P>
+<PRE>
+ this Italian cheese is delicious
+</PRE>
+<P>
+in English and Italian.
+</P>
+<P>
+The first English grammar
+<A HREF="food.cf"><CODE>food.cf</CODE></A>
+is written in a context-free
+notation (also known as BNF). The BNF format is often a good
+starting point for GF grammar development, because it is
+simple and widely used. However, the BNF format is not
+good for multilingual grammars. While it is possible to
+translate the words contained in a BNF grammar to another
+language, proper translation usually involves more, e.g.
+changing the word order in
+</P>
+<PRE>
+ Italian cheese ===&gt; formaggio italiano
+</PRE>
+<P>
+The full GF grammar format is designed to support such
+changes, by separating between the <B>abstract syntax</B>
+(the logical structure) and the <B>concrete syntax</B> (the
+sequence of words) of expressions.
+</P>
+<P>
+There is more than words and word order that makes languages
+different. Words can have different forms, and which forms
+they have vary from language to language. For instance,
+Italian adjectives usually have four forms where English
+has just one:
+</P>
+<PRE>
+ delicious (wine | wines | pizza | pizzas)
+ vino delizioso, vini deliziosi, pizza deliziosa, pizze deliziose
+</PRE>
+<P>
+The <B>morphology</B> of a language describes the
+forms of its words. While the complete description of morphology
+belongs to resource grammars, the tutorial will explain the
+main programming concepts involved. This will moreover
+make it possible to grow the fragment covered by the food example.
+The tutorial will in fact build a toy resource grammar in order
+to illustrate the module structure of library-based application
+grammar writing.
+</P>
+<P>
+Thus it is by elaborating the initial <CODE>food.cf</CODE> example that
+the tutorial makes a guided tour through all concepts of GF.
+While the constructs of the GF language are the main focus,
+also the commands of the GF system are introduced as they
+are needed.
+</P>
+<P>
+To learn how to write GF grammars is not the only goal of
+this tutorial. To learn the commands of the GF system means
+that simple applications of grammars, such as translation and
+quiz systems, can be built simply by writing scripts for the
+system. More complicated applications, such as natural-language
+interfaces and dialogue systems, also require programming in
+some general-purpose language. We will briefly explain how
+GF grammars are used as components of Haskell, Java, and
+Prolog grammars. The tutorial concludes with a couple of
+case studies showing how such complete systems can be built.
+</P>
+<A NAME="toc6"></A>
<H3>Getting the GF program</H3>
<P>
The program is open-source free software, which you can download via the
@@ -196,8 +357,8 @@ As a common convention in this Tutorial, we will use
Thus you should not type these prompts, but only the lines that
follow them.
</P>
-<A NAME="toc3"></A>
-<H2>The ``.cf`` grammar format</H2>
+<A NAME="toc7"></A>
+<H2>The .cf grammar format</H2>
<P>
Now you are ready to try out your first grammar.
We start with one that is not written in GF language, but
@@ -220,7 +381,7 @@ It builds <B>sentences</B> (<CODE>S</CODE>) by assigning <CODE>Qualities</CODE>
they are small grammars describing some more or less well-defined
domain, such as in this case food.
</P>
-<A NAME="toc4"></A>
+<A NAME="toc8"></A>
<H3>Importing grammars and parsing strings</H3>
<P>
The first GF command when using a grammar is to <B>import</B> it.
@@ -269,7 +430,7 @@ you imported. Try parsing something else, and you fail
no tree found
</PRE>
<P></P>
-<A NAME="toc5"></A>
+<A NAME="toc9"></A>
<H3>Generating trees and strings</H3>
<P>
You can also use GF for <B>linearizing</B>
@@ -300,7 +461,7 @@ a <B>pipe</B>.
this fresh cheese is delicious
</PRE>
<P></P>
-<A NAME="toc6"></A>
+<A NAME="toc10"></A>
<H3>Visualizing trees</H3>
<P>
The gibberish code with parentheses returned by the parser does not
@@ -318,7 +479,7 @@ parsing (and any other tree-producing command) can be piped:
<P>
<IMG ALIGN="middle" SRC="Tree.png" BORDER="0" ALT="">
</P>
-<A NAME="toc7"></A>
+<A NAME="toc11"></A>
<H3>Some random-generated sentences</H3>
<P>
Random generation can be quite amusing. So you may want to
@@ -338,7 +499,7 @@ generate ten strings with one and the same command:
this fish is boring
</PRE>
<P></P>
-<A NAME="toc8"></A>
+<A NAME="toc12"></A>
<H3>Systematic generation</H3>
<P>
To generate <I>all</I> sentence that a grammar
@@ -369,7 +530,7 @@ You get quite a few trees but not all of them: only up to a given
<B>Quiz</B>. If the command <CODE>gt</CODE> generated all
trees in your grammar, it would never terminate. Why?
</P>
-<A NAME="toc9"></A>
+<A NAME="toc13"></A>
<H3>More on pipes; tracing</H3>
<P>
A pipe of GF commands can have any length, but the "output type"
@@ -393,7 +554,7 @@ This facility is good for test purposes: for instance, you
may want to see if a grammar is <B>ambiguous</B>, i.e.
contains strings that can be parsed in more than one way.
</P>
-<A NAME="toc10"></A>
+<A NAME="toc14"></A>
<H3>Writing and reading files</H3>
<P>
To save the outputs of GF commands into a file, you can
@@ -416,7 +577,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.
</P>
-<A NAME="toc11"></A>
+<A NAME="toc15"></A>
<H3>Labelled context-free grammars</H3>
<P>
The syntax trees returned by GF's parser in the previous examples
@@ -459,7 +620,7 @@ and so on. These labels are formed automatically when the grammar
is compiled by GF, in a way that guarantees that different rules
get different labels.
</P>
-<A NAME="toc12"></A>
+<A NAME="toc16"></A>
<H3>The labelled context-free format</H3>
<P>
The <B>labelled context-free grammar</B> format permits user-defined
@@ -496,7 +657,7 @@ With this grammar, the trees look as follows:
<P>
<IMG ALIGN="middle" SRC="Tree2.png" BORDER="0" ALT="">
</P>
-<A NAME="toc13"></A>
+<A NAME="toc17"></A>
<H2>The ``.gf`` grammar format</H2>
<P>
To see what there is in GF's shell state when a grammar
@@ -521,7 +682,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.
</P>
-<A NAME="toc14"></A>
+<A NAME="toc18"></A>
<H3>Abstract and concrete syntax</H3>
<P>
A GF grammar consists of two main parts:
@@ -556,7 +717,7 @@ The latter rule, with the keyword <CODE>lin</CODE>, belongs to the concrete synt
It defines the <B>linearization function</B> for
syntax trees of form (<CODE>Is</CODE> <I>item</I> <I>quality</I>).
</P>
-<A NAME="toc15"></A>
+<A NAME="toc19"></A>
<H3>Judgement forms</H3>
<P>
Rules in a GF grammar are called <B>judgements</B>, and the keywords
@@ -612,7 +773,7 @@ First we will look at how judgements are grouped into modules, and
show how the paleolithic grammar is
expressed by using modules and judgements.
</P>
-<A NAME="toc16"></A>
+<A NAME="toc20"></A>
<H3>Module types</H3>
<P>
A GF grammar consists of <B>modules</B>,
@@ -626,7 +787,7 @@ module forms are
abstract syntax A, with judgements in the module body M.
</UL>
-<A NAME="toc17"></A>
+<A NAME="toc21"></A>
<H3>Record types, records, and ``Str``s</H3>
<P>
The linearization type of a category is a <B>record type</B>, with
@@ -686,7 +847,7 @@ can be used for lists of tokens. The expression
<P>
denotes the empty token list.
</P>
-<A NAME="toc18"></A>
+<A NAME="toc22"></A>
<H3>An abstract syntax example</H3>
<P>
To express the abstract syntax of <CODE>food.cf</CODE> in
@@ -718,7 +879,7 @@ Notice the use of shorthands permitting the sharing of
the keyword in subsequent judgements, and of the type
in subsequent <CODE>fun</CODE> judgements.
</P>
-<A NAME="toc19"></A>
+<A NAME="toc23"></A>
<H3>A concrete syntax example</H3>
<P>
Each category introduced in <CODE>Food.gf</CODE> is
@@ -750,7 +911,7 @@ apply as in <CODE>abstract</CODE> modules.
}
</PRE>
<P></P>
-<A NAME="toc20"></A>
+<A NAME="toc24"></A>
<H3>Modules and files</H3>
<P>
Module name + <CODE>.gf</CODE> = file name
@@ -777,7 +938,7 @@ GF source files. When reading a module, GF decides whether
to use an existing <CODE>.gfc</CODE> file or to generate
a new one, by looking at modification times.
</P>
-<A NAME="toc21"></A>
+<A NAME="toc25"></A>
<H2>Multilingual grammars and translation</H2>
<P>
The main advantage of separating abstract from concrete syntax is that
@@ -790,7 +951,7 @@ translation. Let us buid an Italian concrete syntax for
<CODE>Food</CODE> and then test the resulting
multilingual grammar.
</P>
-<A NAME="toc22"></A>
+<A NAME="toc26"></A>
<H3>An Italian concrete syntax</H3>
<PRE>
concrete FoodIta of Food = {
@@ -818,7 +979,7 @@ multilingual grammar.
</PRE>
<P></P>
-<A NAME="toc23"></A>
+<A NAME="toc27"></A>
<H3>Using a multilingual grammar</H3>
<P>
Import the two grammars in the same GF session.
@@ -857,7 +1018,7 @@ To see what grammars are in scope and which is the main one, use the command
actual concretes : FoodIta FoodEng
</PRE>
<P></P>
-<A NAME="toc24"></A>
+<A NAME="toc28"></A>
<H3>Translation session</H3>
<P>
If translation is what you want to do with a set of grammars, a convenient
@@ -880,7 +1041,7 @@ A dot <CODE>.</CODE> terminates the translation session.
&gt;
</PRE>
<P></P>
-<A NAME="toc25"></A>
+<A NAME="toc29"></A>
<H3>Translation quiz</H3>
<P>
This is a simple language exercise that can be automatically
@@ -920,9 +1081,9 @@ file for later use, by the command <CODE>translation_list = tl</CODE>
<P>
The <CODE>number</CODE> flag gives the number of sentences generated.
</P>
-<A NAME="toc26"></A>
+<A NAME="toc30"></A>
<H2>Grammar architecture</H2>
-<A NAME="toc27"></A>
+<A NAME="toc31"></A>
<H3>Extending a grammar</H3>
<P>
The module system of GF makes it possible to <B>extend</B> a
@@ -957,7 +1118,7 @@ be built for concrete syntaxes:
The effect of extension is that all of the contents of the extended
and extending module are put together.
</P>
-<A NAME="toc28"></A>
+<A NAME="toc32"></A>
<H3>Multiple inheritance</H3>
<P>
Specialized vocabularies can be represented as small grammars that
@@ -992,7 +1153,7 @@ At this point, you would perhaps like to go back to
<CODE>Food</CODE> and take apart <CODE>Wine</CODE> to build a special
<CODE>Drink</CODE> module.
</P>
-<A NAME="toc29"></A>
+<A NAME="toc33"></A>
<H3>Visualizing module structure</H3>
<P>
When you have created all the abstract syntaxes and
@@ -1019,7 +1180,7 @@ The graph uses
<IMG ALIGN="middle" SRC="Foodmarket.png" BORDER="0" ALT="">
</UL>
-<A NAME="toc30"></A>
+<A NAME="toc34"></A>
<H2>System commands</H2>
<P>
To document your grammar, you may want to print the
@@ -1047,9 +1208,9 @@ are available:
&gt; help -printer
</PRE>
<P></P>
-<A NAME="toc31"></A>
+<A NAME="toc35"></A>
<H2>Resource modules</H2>
-<A NAME="toc32"></A>
+<A NAME="toc36"></A>
<H3>The golden rule of functional programming</H3>
<P>
In comparison to the <CODE>.cf</CODE> format, the <CODE>.gf</CODE> format still looks rather
@@ -1071,7 +1232,7 @@ changing parts, parameters. In functional programming languages, such as
<A HREF="http://www.haskell.org">Haskell</A>, it is possible to share muc more than in
the languages such as C and Java.
</P>
-<A NAME="toc33"></A>
+<A NAME="toc37"></A>
<H3>Operation definitions</H3>
<P>
GF is a functional programming language, not only in the sense that
@@ -1101,7 +1262,7 @@ its type, and an expression defining it. As for the syntax of the defining
expression, notice the <B>lambda abstraction</B> form <CODE>\x -&gt; t</CODE> of
the function.
</P>
-<A NAME="toc34"></A>
+<A NAME="toc38"></A>
<H3>The ``resource`` module type</H3>
<P>
Operator definitions can be included in a concrete syntax.
@@ -1132,7 +1293,7 @@ Resource modules can extend other resource modules, in the
same way as modules of other types can extend modules of the
same type. Thus it is possible to build resource hierarchies.
</P>
-<A NAME="toc35"></A>
+<A NAME="toc39"></A>
<H3>Opening a ``resource``</H3>
<P>
Any number of <CODE>resource</CODE> modules can be
@@ -1170,7 +1331,7 @@ opened in a new version of <CODE>FoodEng</CODE>.
The same string operations could be use to write <CODE>FoodIta</CODE>
more concisely.
</P>
-<A NAME="toc36"></A>
+<A NAME="toc40"></A>
<H3>Division of labour</H3>
<P>
Using operations defined in resource modules is a
@@ -1182,7 +1343,7 @@ available through resource grammar modules, whose users only need
to pick the right operations and not to know their implementation
details.
</P>
-<A NAME="toc37"></A>
+<A NAME="toc41"></A>
<H2>Morphology</H2>
<P>
Suppose we want to say, with the vocabulary included in
@@ -1217,7 +1378,7 @@ and many new expression forms.
We also need to generalize linearization types
from strings to more complex types.
</P>
-<A NAME="toc38"></A>
+<A NAME="toc42"></A>
<H3>Parameters and tables</H3>
<P>
We define the <B>parameter type</B> of number in Englisn by
@@ -1258,7 +1419,7 @@ operator <CODE>!</CODE>. For instance,
<P>
is a selection, whose value is <CODE>"cheeses"</CODE>.
</P>
-<A NAME="toc39"></A>
+<A NAME="toc43"></A>
<H3>Inflection tables, paradigms, and ``oper`` definitions</H3>
<P>
All English common nouns are inflected in number, most of them in the
@@ -1292,7 +1453,7 @@ are written together to form one <B>token</B>. Thus, for instance,
(regNoun "cheese").s ! Pl ---&gt; "cheese" + "s" ---&gt; "cheeses"
</PRE>
<P></P>
-<A NAME="toc40"></A>
+<A NAME="toc44"></A>
<H3>Worst-case macros and data abstraction</H3>
<P>
Some English nouns, such as <CODE>mouse</CODE>, are so irregular that
@@ -1333,7 +1494,7 @@ interface (i.e. the system of type signatures) that makes it
correct to use these functions in concrete modules. In programming
terms, <CODE>Noun</CODE> is then treated as an <B>abstract datatype</B>.
</P>
-<A NAME="toc41"></A>
+<A NAME="toc45"></A>
<H3>A system of paradigms using ``Prelude`` operations</H3>
<P>
In addition to the completely regular noun paradigm <CODE>regNoun</CODE>,
@@ -1365,7 +1526,7 @@ The operator <CODE>init</CODE> belongs to a set of operations in the
resource module <CODE>Prelude</CODE>, which therefore has to be
<CODE>open</CODE>ed so that <CODE>init</CODE> can be used.
</P>
-<A NAME="toc42"></A>
+<A NAME="toc46"></A>
<H3>An intelligent noun paradigm using ``case`` expressions</H3>
<P>
It may be hard for the user of a resource morphology to pick the right
@@ -1395,7 +1556,7 @@ this, either use <CODE>mkNoun</CODE> or modify
<CODE>regNoun</CODE> so that the <CODE>"y"</CODE> case does not
apply if the second-last character is a vowel.
</P>
-<A NAME="toc43"></A>
+<A NAME="toc47"></A>
<H3>Pattern matching</H3>
<P>
Expressions of the <CODE>table</CODE> form are built from lists of
@@ -1431,14 +1592,14 @@ programming languages are syntactic sugar for table selections:
case e of {...} === table {...} ! e
</PRE>
<P></P>
-<A NAME="toc44"></A>
+<A NAME="toc48"></A>
<H3>Morphological ``resource`` modules</H3>
<P>
A common idiom is to
gather the <CODE>oper</CODE> and <CODE>param</CODE> definitions
needed for inflecting words in
a language into a morphology module. Here is a simple
-example, <A HREF="MorphoEng.gf"><CODE>MorphoEng</CODE></A>.
+example, <A HREF="resource/MorphoEng.gf"><CODE>MorphoEng</CODE></A>.
</P>
<PRE>
--# -path=.:prelude
@@ -1482,7 +1643,7 @@ module depends on. The directory <CODE>prelude</CODE> is a subdirectory of
set the environment variable <CODE>GF_LIB_PATH</CODE> to point to this
directory.
</P>
-<A NAME="toc45"></A>
+<A NAME="toc49"></A>
<H3>Testing ``resource`` modules</H3>
<P>
To test a <CODE>resource</CODE> module independently, you can import it
@@ -1525,7 +1686,7 @@ Why does the command also show the operations that form
<CODE>Verb</CODE> is first computed, and its value happens to be
the same as the value of <CODE>Noun</CODE>.
</P>
-<A NAME="toc46"></A>
+<A NAME="toc50"></A>
<H2>Using morphology in concrete syntax</H2>
<P>
We can now enrich the concrete syntax definitions to
@@ -1536,7 +1697,7 @@ parameters and linearization types are different in
different languages - but this does not prevent the
use of a common abstract syntax.
</P>
-<A NAME="toc47"></A>
+<A NAME="toc51"></A>
<H3>Parametric vs. inherent features, agreement</H3>
<P>
The rule of subject-verb agreement in English says that the verb
@@ -1566,14 +1727,22 @@ the predication structure:
The following section will present
<CODE>FoodsEng</CODE>, assuming the abstract syntax <CODE>Foods</CODE>
that is similar to <CODE>Food</CODE> but also has the
-plural determiners <CODE>All</CODE> and <CODE>Most</CODE>.
+plural determiners <CODE>These</CODE> and <CODE>Those</CODE>.
The reader is invited to inspect the way in which agreement works in
the formation of sentences.
</P>
-<A NAME="toc48"></A>
+<A NAME="toc52"></A>
<H3>English concrete syntax with parameters</H3>
+<P>
+The grammar uses both
+<A HREF="../../lib/prelude/Prelude.gf"><CODE>Prelude</CODE></A> and
+<A HREF="resource/MorphoEng"><CODE>MorphoEng</CODE></A>.
+We will later see how to make the grammar even
+more high-level by using a resource grammar library
+and parametrized modules.
+</P>
<PRE>
- --# -path=.:prelude
+ --# -path=.:resource:prelude
concrete FoodsEng of Foods = open Prelude, MorphoEng in {
@@ -1584,10 +1753,10 @@ the formation of sentences.
lin
Is item quality = ss (item.s ++ (mkVerb "are" "is").s ! item.n ++ quality.s) ;
- This = det Sg "this" ;
- That = det Sg "that" ;
- All = det Pl "all" ;
- Most = det Pl "most" ;
+ This = det Sg "this" ;
+ That = det Sg "that" ;
+ These = det Pl "these" ;
+ Those = det Pl "those" ;
QKind quality kind = {s = \\n =&gt; quality.s ++ kind.s ! n} ;
Wine = regNoun "wine" ;
Cheese = regNoun "cheese" ;
@@ -1609,7 +1778,7 @@ the formation of sentences.
}
</PRE>
<P></P>
-<A NAME="toc49"></A>
+<A NAME="toc53"></A>
<H3>Hierarchic parameter types</H3>
<P>
The reader familiar with a functional programming language such as
@@ -1638,20 +1807,31 @@ yields an accurate system of three adjectival forms.
</P>
<PRE>
param AdjForm = ASg Gender | APl ;
- param Gender = Uter | Neuter ;
+ param Gender = Utr | Neutr ;
</PRE>
<P>
-In pattern matching, a constructor can have patterns as arguments. For instance,
-the adjectival paradigm in which the two singular forms are the same, can be defined
+Here is an example of pattern matching, the paradigm of regular adjectives.
</P>
<PRE>
- oper plattAdj : Str -&gt; AdjForm =&gt; Str = \x -&gt; table {
- ASg _ =&gt; x ;
- APl =&gt; x + "a" ;
+ oper regAdj : Str -&gt; AdjForm =&gt; Str = \fin -&gt; table {
+ ASg Utr =&gt; fin ;
+ ASg Neutr =&gt; fin + "t" ;
+ APl =&gt; fin + "a" ;
+ }
+</PRE>
+<P>
+A constructor can have patterns as arguments. For instance,
+the adjectival paradigm in which the two singular forms are the same,
+can be defined
+</P>
+<PRE>
+ oper plattAdj : Str -&gt; AdjForm =&gt; Str = \platt -&gt; table {
+ ASg _ =&gt; platt ;
+ APl =&gt; platt + "a" ;
}
</PRE>
<P></P>
-<A NAME="toc50"></A>
+<A NAME="toc54"></A>
<H3>Morphological analysis and morphology quiz</H3>
<P>
Even though in GF morphology
@@ -1691,7 +1871,7 @@ file for later use, by the command <CODE>morpho_list = ml</CODE>
<P>
The <CODE>number</CODE> flag gives the number of exercises generated.
</P>
-<A NAME="toc51"></A>
+<A NAME="toc55"></A>
<H3>Discontinuous constituents</H3>
<P>
A linearization type may contain more strings than one.
@@ -1707,8 +1887,8 @@ type with two strings and not just one. The second judgement
shows how the constituents are separated by the object in complementization.
</P>
<PRE>
- lincat TV = {s : Number =&gt; Str ; s2 : Str} ;
- lin ComplTV tv obj = {s = \\n =&gt; tv.s ! n ++ obj.s ++ tv.s2} ;
+ lincat TV = {s : Number =&gt; Str ; part : Str} ;
+ lin PredTV tv obj = {s = \\n =&gt; tv.s ! n ++ obj.s ++ tv.part} ;
</PRE>
<P>
There is no restriction in the number of discontinuous constituents
@@ -1721,9 +1901,31 @@ the parsing and linearization commands only give reliable results
for categories whose linearization type has a unique <CODE>Str</CODE> valued
field labelled <CODE>s</CODE>.
</P>
-<A NAME="toc52"></A>
+<A NAME="toc56"></A>
<H2>More constructs for concrete syntax</H2>
-<A NAME="toc53"></A>
+<A NAME="toc57"></A>
+<H3>Local definitions</H3>
+<P>
+Local definitions ("<CODE>let</CODE> expressions") are used in functional
+programming for two reasons: to structure the code into smaller
+expressions, and to avoid repeated computation of one and
+the same expression. Here is an example, from
+<A HREF="resource/MorphoIta.gf">``MorphoIta</A>:
+</P>
+<PRE>
+ oper regNoun : Str -&gt; Noun = \vino -&gt;
+ let
+ vin = init vino ;
+ o = last vino
+ in
+ case o of {
+ "a" =&gt; mkNoun Fem vino (vin + "e") ;
+ "o" | "e" =&gt; mkNoun Masc vino (vin + "i") ;
+ _ =&gt; mkNoun Masc vino vino
+ } ;
+</PRE>
+<P></P>
+<A NAME="toc58"></A>
<H3>Free variation</H3>
<P>
Sometimes there are many alternative ways to define a concrete syntax.
@@ -1733,7 +1935,7 @@ are in <B>free variation</B>. The <CODE>variants</CODE> construct of GF can
be used to give a list of strings in free variation. For example,
</P>
<PRE>
- NegVerb verb = {s = variants {["does not"] ; "doesn't} ++ verb.s} ;
+ NegVerb verb = {s = variants {["does not"] ; "doesn't} ++ verb.s ! Pl} ;
</PRE>
<P>
An empty variant list
@@ -1751,7 +1953,7 @@ user of the library has no way to choose among the variants.
Moreover, even though <CODE>variants</CODE> admits lists of any type,
its semantics for complex types can cause surprises.
</P>
-<A NAME="toc54"></A>
+<A NAME="toc59"></A>
<H3>Record extension and subtyping</H3>
<P>
Record types and records can be <B>extended</B> with new fields. For instance,
@@ -1781,7 +1983,7 @@ be used whenever a verb is required.
<B>Contravariance</B> means that a function taking an <I>R</I> as argument
can also be applied to any object of a subtype <I>T</I>.
</P>
-<A NAME="toc55"></A>
+<A NAME="toc60"></A>
<H3>Tuples and product types</H3>
<P>
Product types and tuples are syntactic sugar for record types and records:
@@ -1793,7 +1995,7 @@ Product types and tuples are syntactic sugar for record types and records:
<P>
Thus the labels <CODE>p1, p2,...`</CODE> are hard-coded.
</P>
-<A NAME="toc56"></A>
+<A NAME="toc61"></A>
<H3>Prefix-dependent choices</H3>
<P>
The construct exemplified in
@@ -1822,15 +2024,15 @@ This very example does not work in all situations: the prefix
} ;
</PRE>
<P></P>
-<A NAME="toc57"></A>
+<A NAME="toc62"></A>
<H3>Predefined types and operations</H3>
<P>
GF has the following predefined categories in abstract syntax:
</P>
<PRE>
cat Int ; -- integers, e.g. 0, 5, 743145151019
- cat Float ; -- floats, e.g. 0.0, 3.1415926
- cat String ; -- strings, e.g. "", "foo", "123"
+ cat Float ; -- floats, e.g. 0.0, 3.1415926
+ cat String ; -- strings, e.g. "", "foo", "123"
</PRE>
<P>
The objects of each of these categories are <B>literals</B>
@@ -1845,31 +2047,31 @@ they can be used as arguments. For example:
-- e.g. (StreetAddress 10 "Downing Street") : Address
</PRE>
<P></P>
-<A NAME="toc58"></A>
+<A NAME="toc63"></A>
<H2>More features of the module system</H2>
-<A NAME="toc59"></A>
+<A NAME="toc64"></A>
<H3>Resource grammars and their reuse</H3>
<P>
See
<A HREF="../../lib/resource/doc/gf-resource.html">resource library documentation</A>
</P>
-<A NAME="toc60"></A>
+<A NAME="toc65"></A>
<H3>Interfaces, instances, and functors</H3>
<P>
See an
<A HREF="../../examples/mp3/mp3-resource.html">example built this way</A>
</P>
-<A NAME="toc61"></A>
+<A NAME="toc66"></A>
<H3>Restricted inheritance and qualified opening</H3>
-<A NAME="toc62"></A>
+<A NAME="toc67"></A>
<H2>More concepts of abstract syntax</H2>
-<A NAME="toc63"></A>
+<A NAME="toc68"></A>
<H3>Dependent types</H3>
-<A NAME="toc64"></A>
+<A NAME="toc69"></A>
<H3>Higher-order abstract syntax</H3>
-<A NAME="toc65"></A>
+<A NAME="toc70"></A>
<H3>Semantic definitions</H3>
-<A NAME="toc66"></A>
+<A NAME="toc71"></A>
<H2>Transfer modules</H2>
<P>
Transfer means noncompositional tree-transforming operations.
@@ -1888,9 +2090,9 @@ See the
<A HREF="../transfer.html">transfer language documentation</A>
for more information.
</P>
-<A NAME="toc67"></A>
+<A NAME="toc72"></A>
<H2>Practical issues</H2>
-<A NAME="toc68"></A>
+<A NAME="toc73"></A>
<H3>Lexers and unlexers</H3>
<P>
Lexers and unlexers can be chosen from
@@ -1926,7 +2128,7 @@ Given by <CODE>help -lexer</CODE>, <CODE>help -unlexer</CODE>:
</PRE>
<P></P>
-<A NAME="toc69"></A>
+<A NAME="toc74"></A>
<H3>Efficiency of grammars</H3>
<P>
Issues:
@@ -1937,7 +2139,7 @@ Issues:
<LI>parsing efficiency: <CODE>-mcfg</CODE> vs. others
</UL>
-<A NAME="toc70"></A>
+<A NAME="toc75"></A>
<H3>Speech input and output</H3>
<P>
The<CODE>speak_aloud = sa</CODE> command sends a string to the speech
@@ -1967,7 +2169,7 @@ The method words only for grammars of English.
Both Flite and ATK are freely available through the links
above, but they are not distributed together with GF.
</P>
-<A NAME="toc71"></A>
+<A NAME="toc76"></A>
<H3>Multilingual syntax editor</H3>
<P>
The
@@ -1984,18 +2186,18 @@ Here is a snapshot of the editor:
The grammars of the snapshot are from the
<A HREF="http://www.cs.chalmers.se/~aarne/GF/examples/letter">Letter grammar package</A>.
</P>
-<A NAME="toc72"></A>
+<A NAME="toc77"></A>
<H3>Interactive Development Environment (IDE)</H3>
<P>
Forthcoming.
</P>
-<A NAME="toc73"></A>
+<A NAME="toc78"></A>
<H3>Communicating with GF</H3>
<P>
Other processes can communicate with the GF command interpreter,
and also with the GF syntax editor.
</P>
-<A NAME="toc74"></A>
+<A NAME="toc79"></A>
<H3>Embedded grammars in Haskell, Java, and Prolog</H3>
<P>
GF grammars can be used as parts of programs written in the
@@ -2007,15 +2209,15 @@ following languages. The links give more documentation.
<LI><A HREF="http://www.cs.chalmers.se/~peb/software.html">Prolog</A>
</UL>
-<A NAME="toc75"></A>
+<A NAME="toc80"></A>
<H3>Alternative input and output grammar formats</H3>
<P>
A summary is given in the following chart of GF grammar compiler phases:
<IMG ALIGN="middle" SRC="../gf-compiler.png" BORDER="0" ALT="">
</P>
-<A NAME="toc76"></A>
+<A NAME="toc81"></A>
<H2>Case studies</H2>
-<A NAME="toc77"></A>
+<A NAME="toc82"></A>
<H3>Interfacing formal and natural languages</H3>
<P>
<A HREF="http://www.cs.chalmers.se/~krijo/thesis/thesisA4.pdf">Formal and Informal Software Specifications</A>,
@@ -2028,6 +2230,6 @@ English and German.
A simpler example will be explained here.
</P>
-<!-- html code generated by txt2tags 2.3 (http://txt2tags.sf.net) -->
+<!-- html code generated by txt2tags 2.0 (http://txt2tags.sf.net) -->
<!-- cmdline: txt2tags -\-toc gf-tutorial2.txt -->
</BODY></HTML>
diff --git a/doc/tutorial/gf-tutorial2.txt b/doc/tutorial/gf-tutorial2.txt
index cc5e323c0..4eed17774 100644
--- a/doc/tutorial/gf-tutorial2.txt
+++ b/doc/tutorial/gf-tutorial2.txt
@@ -8,12 +8,23 @@ Last update: %%date(%c)
%!target:html
+% workaround for some missing things in the format
+% %!postproc(html): C- <center>
+% %!postproc(html): -C </center>
+% %!postproc(html): t- <tt>
+% %!postproc(html): -t </tt>
+
+
+
+
[../gf-logo.gif]
%--!
-==GF = Grammatical Framework==
+==Introduction==
+
+===GF = Grammatical Framework===
The term GF is used for different things:
@@ -32,6 +43,143 @@ It will guide you
+%--!
+===What are GF grammars used for===
+
+A grammar is a definition of a language.
+From this definition, different language processing components
+can be derived:
+
+- parsing: to analyse the language
+- linearization: to generate the language
+- translation: to analyse one language and generate another
+
+
+A GF grammar can be seen as a declarative program from which these
+processing tasks can be automatically derived. In addition, many
+other tasks are readily available for GF grammars:
+
+- morphological analysis: find out the possible inflection forms of words
+- morphological synthesis: generate all inflection forms of words
+- random generation: generate random expressions
+- corpus generation: generate all expressions
+- teaching quizzes: train morphology and translation
+- multilingual authoring: create a document in many languages simultaneously
+- speech input: optimize a speech recognition system for your grammar
+
+
+A typical GF application is based on a **multilingual grammar** involving
+translation on a special domain. Existing applications of this idea include
+
+- [Alfa: http://www.cs.chalmers.se/%7Ehallgren/Alfa/Tutorial/GFplugin.html]:
+ a natural-language interface to a proof editor
+ (languages: English, French, Swedish)
+- [KeY http://www.key-project.org/]:
+ a multilingual authoring system for creating software specifications
+ (languages: OCL, English, German)
+- [TALK http://www.talk-project.org]:
+ multilingual and multimodal dialogue systems
+- [WebALT http://webalt.math.helsinki.fi/content/index_eng.html]:
+ a multilingual translator of mathematical exercises
+ (languages: Catalan, English, Finnish, French, Spanish, Swedish)
+- [Numeral translator http://www.cs.chalmers.se/~bringert/gf/translate/]:
+ number words from 1 to 999,999
+ (88 languages)
+
+
+The specialization of a grammar to a domain makes it possible to
+obtain much better translations than in an unlimited machine translation
+system. This is due to the well-defined semantics of such domains.
+Grammars having this character are called **application grammars**.
+They are different from most grammars written by linguists just
+because they are multilingual and domain-specific.
+
+However, there is another kind of grammars, which we call **resource grammars**.
+These are large, comprehensive grammars that can be used on any domain.
+The GF Resource Grammar Library has resource grammars for 10 languages.
+These grammars can be used as **libraries** to define application grammars.
+In this way, it is possible to write a high-quality grammar without
+knowing about linguistics: in general, to write an application grammar
+by using the resource library just requires practical knowledge of
+the target language.
+
+
+
+
+%--!
+===Who is this tutorial for===
+
+This tutorial is mainly for programmers who want to learn to write
+application grammars. It will go through GF's programming concepts
+without entering too deep into linguistics. Thus it should
+be accessible to anyone who has some previous programming experience.
+
+A separate document is being written on how to write resource grammars.
+This includes the ways in which linguistic problems posed by different
+languages are solved in GF.
+
+
+%--!
+===The coverage of the tutorial===
+
+The tutorial gives a hands-on introduction to grammar writing.
+We start by building a small grammar for the domain of food:
+in this grammar, you can say things like
+``` this Italian cheese is delicious
+in English and Italian.
+
+The first English grammar
+[``food.cf`` food.cf]
+is written in a context-free
+notation (also known as BNF). The BNF format is often a good
+starting point for GF grammar development, because it is
+simple and widely used. However, the BNF format is not
+good for multilingual grammars. While it is possible to
+translate the words contained in a BNF grammar to another
+language, proper translation usually involves more, e.g.
+changing the word order in
+``` Italian cheese ===> formaggio italiano
+The full GF grammar format is designed to support such
+changes, by separating between the **abstract syntax**
+(the logical structure) and the **concrete syntax** (the
+sequence of words) of expressions.
+
+There is more than words and word order that makes languages
+different. Words can have different forms, and which forms
+they have vary from language to language. For instance,
+Italian adjectives usually have four forms where English
+has just one:
+```
+ delicious (wine | wines | pizza | pizzas)
+ vino delizioso, vini deliziosi, pizza deliziosa, pizze deliziose
+```
+The **morphology** of a language describes the
+forms of its words. While the complete description of morphology
+belongs to resource grammars, the tutorial will explain the
+main programming concepts involved. This will moreover
+make it possible to grow the fragment covered by the food example.
+The tutorial will in fact build a toy resource grammar in order
+to illustrate the module structure of library-based application
+grammar writing.
+
+Thus it is by elaborating the initial ``food.cf`` example that
+the tutorial makes a guided tour through all concepts of GF.
+While the constructs of the GF language are the main focus,
+also the commands of the GF system are introduced as they
+are needed.
+
+To learn how to write GF grammars is not the only goal of
+this tutorial. To learn the commands of the GF system means
+that simple applications of grammars, such as translation and
+quiz systems, can be built simply by writing scripts for the
+system. More complicated applications, such as natural-language
+interfaces and dialogue systems, also require programming in
+some general-purpose language. We will briefly explain how
+GF grammars are used as components of Haskell, Java, and
+Prolog grammars. The tutorial concludes with a couple of
+case studies showing how such complete systems can be built.
+
+
%--!
===Getting the GF program===
@@ -74,7 +222,7 @@ follow them.
%--!
-==The ``.cf`` grammar format==
+==The .cf grammar format==
Now you are ready to try out your first grammar.
We start with one that is not written in GF language, but
@@ -1186,7 +1334,7 @@ A common idiom is to
gather the ``oper`` and ``param`` definitions
needed for inflecting words in
a language into a morphology module. Here is a simple
-example, [``MorphoEng`` MorphoEng.gf].
+example, [``MorphoEng`` resource/MorphoEng.gf].
```
--# -path=.:prelude
@@ -1302,7 +1450,7 @@ the predication structure:
The following section will present
``FoodsEng``, assuming the abstract syntax ``Foods``
that is similar to ``Food`` but also has the
-plural determiners ``All`` and ``Most``.
+plural determiners ``These`` and ``Those``.
The reader is invited to inspect the way in which agreement works in
the formation of sentences.
@@ -1310,8 +1458,14 @@ the formation of sentences.
%--!
===English concrete syntax with parameters===
+The grammar uses both
+[``Prelude`` ../../lib/prelude/Prelude.gf] and
+[``MorphoEng`` resource/MorphoEng].
+We will later see how to make the grammar even
+more high-level by using a resource grammar library
+and parametrized modules.
```
---# -path=.:prelude
+--# -path=.:resource:prelude
concrete FoodsEng of Foods = open Prelude, MorphoEng in {
@@ -1322,10 +1476,10 @@ concrete FoodsEng of Foods = open Prelude, MorphoEng in {
lin
Is item quality = ss (item.s ++ (mkVerb "are" "is").s ! item.n ++ quality.s) ;
- This = det Sg "this" ;
- That = det Sg "that" ;
- All = det Pl "all" ;
- Most = det Pl "most" ;
+ This = det Sg "this" ;
+ That = det Sg "that" ;
+ These = det Pl "these" ;
+ Those = det Pl "those" ;
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
Wine = regNoun "wine" ;
Cheese = regNoun "cheese" ;
@@ -1375,14 +1529,23 @@ it would be inaccurate to define adjective paradigms using the type
yields an accurate system of three adjectival forms.
```
param AdjForm = ASg Gender | APl ;
- param Gender = Uter | Neuter ;
+ param Gender = Utr | Neutr ;
+```
+Here is an example of pattern matching, the paradigm of regular adjectives.
+```
+ oper regAdj : Str -> AdjForm => Str = \fin -> table {
+ ASg Utr => fin ;
+ ASg Neutr => fin + "t" ;
+ APl => fin + "a" ;
+ }
```
-In pattern matching, a constructor can have patterns as arguments. For instance,
-the adjectival paradigm in which the two singular forms are the same, can be defined
+A constructor can have patterns as arguments. For instance,
+the adjectival paradigm in which the two singular forms are the same,
+can be defined
```
- oper plattAdj : Str -> AdjForm => Str = \x -> table {
- ASg _ => x ;
- APl => x + "a" ;
+ oper plattAdj : Str -> AdjForm => Str = \platt -> table {
+ ASg _ => platt ;
+ APl => platt + "a" ;
}
```
@@ -1437,8 +1600,8 @@ The first of the following judgements defines transitive verbs as
type with two strings and not just one. The second judgement
shows how the constituents are separated by the object in complementization.
```
- lincat TV = {s : Number => Str ; s2 : Str} ;
- lin ComplTV tv obj = {s = \\n => tv.s ! n ++ obj.s ++ tv.s2} ;
+ lincat TV = {s : Number => Str ; part : Str} ;
+ lin PredTV tv obj = {s = \\n => tv.s ! n ++ obj.s ++ tv.part} ;
```
There is no restriction in the number of discontinuous constituents
(or other fields) a ``lincat`` may contain. The only condition is that
@@ -1456,6 +1619,30 @@ field labelled ``s``.
%--!
+===Local definitions===
+
+Local definitions ("``let`` expressions") are used in functional
+programming for two reasons: to structure the code into smaller
+expressions, and to avoid repeated computation of one and
+the same expression. Here is an example, from
+[``MorphoIta resource/MorphoIta.gf]:
+```
+ oper regNoun : Str -> Noun = \vino ->
+ let
+ vin = init vino ;
+ o = last vino
+ in
+ case o of {
+ "a" => mkNoun Fem vino (vin + "e") ;
+ "o" | "e" => mkNoun Masc vino (vin + "i") ;
+ _ => mkNoun Masc vino vino
+ } ;
+```
+
+
+
+
+%--!
===Free variation===
Sometimes there are many alternative ways to define a concrete syntax.
@@ -1464,7 +1651,7 @@ For instance, the verb negation in English can be expressed both by
are in **free variation**. The ``variants`` construct of GF can
be used to give a list of strings in free variation. For example,
```
- NegVerb verb = {s = variants {["does not"] ; "doesn't} ++ verb.s} ;
+ NegVerb verb = {s = variants {["does not"] ; "doesn't} ++ verb.s ! Pl} ;
```
An empty variant list
```
@@ -1542,14 +1729,13 @@ This very example does not work in all situations: the prefix
```
-
===Predefined types and operations===
GF has the following predefined categories in abstract syntax:
```
cat Int ; -- integers, e.g. 0, 5, 743145151019
- cat Float ; -- floats, e.g. 0.0, 3.1415926
- cat String ; -- strings, e.g. "", "foo", "123"
+ cat Float ; -- floats, e.g. 0.0, 3.1415926
+ cat String ; -- strings, e.g. "", "foo", "123"
```
The objects of each of these categories are **literals**
as indicated in the comments above. No ``fun`` definition
diff --git a/doc/tutorial/resource/LexEng.gf b/doc/tutorial/resource/LexEng.gf
new file mode 100644
index 000000000..c939aac9f
--- /dev/null
+++ b/doc/tutorial/resource/LexEng.gf
@@ -0,0 +1,34 @@
+--# -path=.:prelude
+
+resource LexEng = open SyntaxEng, MorphoEng, Prelude in {
+
+ oper
+
+ -- constructors for open lexicon
+
+ mkN : (man,men : Str) -> CN ;
+ regN : (car : Str) -> CN ;
+
+ mkA : (hot : Str) -> AP ;
+
+ mkV : (go,goes : Str) -> V ;
+ regV : (walk : Str) -> V ;
+
+ mkV2 : (look : V) -> (at : Str) -> V2 ;
+ dirV2 : (eat : V) -> V2 ;
+
+ --------------------------------------------
+ -- definitions, hidden from users
+
+ mkN x y = mkNoun x y ** {lock_CN = <>} ;
+ regN x = regNoun x ** {lock_CN = <>} ;
+
+ mkA x = ss x ** {lock_AP = <>} ;
+
+ mkV x y = mkVerb x y ** {lock_V = <>} ;
+ regV x = regVerb x ** {lock_V = <>} ;
+
+ mkV2 x p = x ** {c = p ; lock_V2 = <>} ;
+ dirV2 x = mkV2 x [] ;
+
+}
diff --git a/doc/tutorial/resource/LexFoods.gf b/doc/tutorial/resource/LexFoods.gf
new file mode 100644
index 000000000..5bda608a3
--- /dev/null
+++ b/doc/tutorial/resource/LexFoods.gf
@@ -0,0 +1,4 @@
+interface LexFoods = open Syntax in {
+
+
+} \ No newline at end of file
diff --git a/doc/tutorial/resource/LexIta.gf b/doc/tutorial/resource/LexIta.gf
new file mode 100644
index 000000000..0b8940e1e
--- /dev/null
+++ b/doc/tutorial/resource/LexIta.gf
@@ -0,0 +1,46 @@
+--# -path=.:prelude
+
+resource LexIta = open SyntaxIta, MorphoIta, Prelude in {
+
+ oper
+
+ -- constructors for genders
+
+ Gender : Type ;
+ masculine, feminine : Gender ;
+
+ -- constructors for open lexicon
+
+ mkN : Gender -> (vino,vini : Str) -> CN ;
+ regN : (vino : Str) -> CN ;
+ femN : CN -> CN ;
+
+ mkA : (nero,nera,neri,nere : Str) -> AP ;
+ regA : (nero : Str) -> AP ;
+
+ mkV : (ama,amano : Str) -> V ;
+ regV : (amare : Str) -> V ;
+
+ mkV2 : (aspettare : V) -> (a : Str) -> V2 ;
+ dirV2 : (mangiare : V) -> V2 ;
+
+ --------------------------------------------
+ -- definitions, hidden from users
+
+ Gender = MorphoIta.Gender ;
+ masculine = Masc ;
+ feminine = Fem ;
+
+ mkN g x y = mkNoun g x y ** {lock_CN = <>} ;
+ regN x = regNoun x ** {lock_CN = <>} ;
+
+ mkA x y z u = mkAdjective x y z u ** {lock_AP = <>} ;
+ regA x = regAdjective x ** {lock_AP = <>} ;
+
+ mkV x y = mkVerb x y ** {lock_V = <>} ;
+ regV x = regVerb x ** {lock_V = <>} ;
+
+ mkV2 x p = x ** {c = p ; lock_V2 = <>} ;
+ dirV2 x = mkV2 x [] ;
+
+}
diff --git a/doc/tutorial/MorphoEng.gf b/doc/tutorial/resource/MorphoEng.gf
index a6a25b08c..a6a25b08c 100644
--- a/doc/tutorial/MorphoEng.gf
+++ b/doc/tutorial/resource/MorphoEng.gf
diff --git a/doc/tutorial/resource/MorphoIta.gf b/doc/tutorial/resource/MorphoIta.gf
new file mode 100644
index 000000000..2d5272812
--- /dev/null
+++ b/doc/tutorial/resource/MorphoIta.gf
@@ -0,0 +1,87 @@
+--# -path=.:prelude
+
+ -- This is a simple Italian resource morphology for the GF tutorial.
+
+ resource MorphoIta = open Prelude in {
+
+ param
+ Number = Sg | Pl ;
+ Gender = Masc | Fem ;
+
+ oper
+ Noun : Type = {s : Number => Str ; g : Gender} ;
+ Adjective : Type = {s : Gender => Number => Str} ;
+
+ -- we will only use present indicative third person verb forms
+
+ Verb : Type = {s : Number => Str} ;
+
+ -- this function takes the gender and both singular and plural forms
+
+ mkNoun : Gender -> Str -> Str -> Noun = \g,vino,vini -> {
+ s = table {
+ Sg => vino ;
+ Pl => vini
+ } ;
+ g = g
+ } ;
+
+ -- this function takes the singular form
+
+ regNoun : Str -> Noun = \vino ->
+ let
+ vin = init vino ;
+ o = last vino
+ in
+ case o of {
+ "a" => mkNoun Fem vino (vin + "e") ; -- pizza
+ "o" | "e" => mkNoun Masc vino (vin + "i") ; -- vino, pane
+ _ => mkNoun Masc vino vino -- tram
+ } ;
+
+ -- to make nouns such as "carne", "università" feminine
+
+ femNoun : Noun -> Noun = \mano -> {
+ s = mano.s ;
+ g = Fem
+ } ;
+
+ -- this takes both genders and numbers
+
+ mkAdjective : (x1,_,_,x4 : Str) -> Adjective = \nero,nera,neri,nere -> {
+ s = table {
+ Masc => (mkNoun Masc nero neri).s ;
+ Fem => (mkNoun Fem nera nere).s
+ }
+ } ;
+
+ -- this takes the masculine singular form
+
+ regAdjective : Str -> Adjective = \nero ->
+ let ner = init nero in
+ case last nero of {
+ "o" => mkAdjective (ner + "o") (ner + "a") (ner + "i") (ner + "e") ;
+ "e" => mkAdjective (ner + "e") (ner + "e") (ner + "i") (ner + "i") ;
+ _ => mkAdjective nero nero nero nero
+ } ;
+
+ -- this function takes the singular and plural forms
+
+ mkVerb : Str -> Str -> Verb = \ama,amano -> {
+ s = table {
+ Sg => ama ;
+ Pl => amano
+ }
+ } ;
+
+ -- this function takes the infinitive form
+
+ regVerb : Str -> Verb = \amare ->
+ let am = Predef.tk 3 amare in
+ case Predef.dp 3 amare of {
+ "ere" => mkVerb (am + "e") (am + "ono") ; -- premere
+ "ire" => mkVerb (am + "isce") (am + "iscono") ; -- finire
+ _ => mkVerb (am + "a") (am + "ano") -- amare
+ } ;
+
+ }
diff --git a/doc/tutorial/resource/Syntax.gf b/doc/tutorial/resource/Syntax.gf
new file mode 100644
index 000000000..4fef6b543
--- /dev/null
+++ b/doc/tutorial/resource/Syntax.gf
@@ -0,0 +1,46 @@
+abstract Syntax = {
+
+ flags startcat=Phr ;
+
+ cat
+ S ; -- declarative sentence e.g. "this pizza is good"
+ NP ; -- noun phrase e.g. "this pizza"
+ CN ; -- common noun e.g. "pizza"
+ Det ; -- determiner e.g. "this"
+ AP ; -- adjectival phrase e.g. "very good"
+ AdA ; -- adadjective e.g. "very"
+ VP ; -- verb phrase e.g. "is good"
+ V ; -- intransitive verb e.g. "boil"
+ V2 ; -- two-place verb e.g. "eat"
+
+ fun
+ PosVP, NegVP : NP -> VP -> S ;
+
+ PredAP : AP -> VP ;
+ PredV : V -> VP ;
+ PredV2 : V2 -> NP -> VP ;
+
+ DetCN : Det -> CN -> NP ;
+
+ ModCN : AP -> CN -> CN ;
+
+ AdAP : AdA -> AP -> AP ;
+
+
+ -- entries of the closed lexicon
+
+ this_Det : Det ;
+ that_Det : Det ;
+ these_Det : Det ;
+ those_Det : Det ;
+ every_Det : Det ;
+ theSg_Det : Det ;
+ thePl_Det : Det ;
+ a_Det : Det ;
+ plur_Det : Det ;
+ two_Det : Det ;
+
+ very_AdA : AdA ;
+ too_AdA : AdA ;
+
+} \ No newline at end of file
diff --git a/doc/tutorial/resource/SyntaxEng.gf b/doc/tutorial/resource/SyntaxEng.gf
new file mode 100644
index 000000000..e4787af47
--- /dev/null
+++ b/doc/tutorial/resource/SyntaxEng.gf
@@ -0,0 +1,67 @@
+--# -path=.:prelude
+
+concrete SyntaxEng of Syntax = open Prelude, MorphoEng in {
+
+ lincat
+ S = {s : Str} ;
+ NP = {s : Str ; n : Number} ;
+ CN = {s : Number => Str} ;
+ Det = {s : Str ; n : Number} ;
+ AP = {s : Str} ;
+ AdA = {s : Str} ;
+ VP = {s : Bool => Number => Str} ;
+ V = {s : Number => Str} ;
+ V2 = {s : Number => Str ; c : Str} ;
+
+ lin
+ PosVP np vp = {s = np.s ++ vp.s ! True ! np.n} ;
+ NegVP np vp = {s = np.s ++ vp.s ! False ! np.n} ;
+
+ PredAP ap = {s = \\b,n => copula b n ++ ap.s} ;
+ PredV v = {s = \\b,n => predVerb b n v} ;
+ PredV2 v2 np = {s = \\b,n => predVerb b n v2 ++ v2.c ++ np.s} ;
+
+ DetCN det cn = {s = det.s ++ cn.s ! det.n ; n = det.n} ;
+
+ ModCN ap cn = {s = \\n => ap.s ++ cn.s ! n} ;
+
+ AdAP ada ap = {s = ada.s ++ ap.s} ;
+
+ this_Det = {s = "this" ; n = Sg} ;
+ that_Det = {s = "that" ; n = Sg} ;
+ these_Det = {s = "these" ; n = Pl} ;
+ those_Det = {s = "those" ; n = Pl} ;
+ every_Det = {s = "every" ; n = Sg} ;
+ theSg_Det = {s = "the" ; n = Sg} ;
+ thePl_Det = {s = "the" ; n = Pl} ;
+ a_Det = {s = artIndef ; n = Sg} ;
+ plur_Det = {s = [] ; n = Pl} ;
+ two_Det = {s = "two" ; n = Pl} ;
+
+ very_AdA = {s = "very"} ;
+ too_AdA = {s = "too"} ;
+
+
+ oper
+ copula : Bool -> Number -> Str = \b,n -> case n of {
+ Sg => posneg b "is" ;
+ Pl => posneg b "are"
+ } ;
+
+ predVerb : Bool -> Number -> Verb -> Str = \b,n,verb ->
+ let inf = verb.s ! Sg in
+ case b of {
+ True => verb.s ! n ;
+ False => posneg b ((regVerb "do").s ! n) ++ inf
+ } ;
+
+ posneg : Bool -> Str -> Str = \b,do -> case b of {
+ True => do ;
+ False => do + "n't"
+ } ;
+
+ artIndef : Str =
+ pre {"a" ; "an" / strs {"a" ; "e" ; "i" ; "o"}} ;
+
+
+}
diff --git a/doc/tutorial/resource/SyntaxIta.gf b/doc/tutorial/resource/SyntaxIta.gf
new file mode 100644
index 000000000..1633ac5f8
--- /dev/null
+++ b/doc/tutorial/resource/SyntaxIta.gf
@@ -0,0 +1,81 @@
+--# -path=.:prelude
+
+concrete SyntaxIta of Syntax = open Prelude, MorphoIta in {
+
+ lincat
+ S = {s : Str} ;
+ NP = {s : Str ; g : Gender ; n : Number} ;
+ CN = {s : Number => Str ; g : Gender} ;
+ Det = {s : Gender => Str ; n : Number} ;
+ AP = {s : Gender => Number => Str} ;
+ AdA = {s : Str} ;
+ VP = {s : Bool => Gender => Number => Str} ;
+ V = {s : Number => Str} ;
+ V2 = {s : Number => Str ; c : Str} ;
+
+ lin
+ PosVP np vp = {s = np.s ++ vp.s ! True ! np.g ! np.n} ;
+ NegVP np vp = {s = np.s ++ vp.s ! False ! np.g ! np.n} ;
+
+ PredAP ap = {s = \\b,g,n => posneg b ++ copula n ++ ap.s ! g ! n} ;
+ PredV v = {s = \\b,_,n => posneg b ++ v.s ! n} ;
+ PredV2 v2 np = {s = \\b,_,n => posneg b ++ v2.s ! n ++ v2.c ++ np.s} ;
+
+ DetCN det cn = {s = det.s ! cn.g ++ cn.s ! det.n ; g = cn.g ; n = det.n} ;
+
+ ModCN ap cn = {s = \\n => cn.s ! n ++ ap.s ! cn.g ! n ; g = cn.g} ;
+
+ AdAP ada ap = {s = \\n,g => ada.s ++ ap.s ! n ! g} ;
+
+ this_Det = mkDet Sg (regAdjective "questo") ;
+ that_Det = mkDet Sg (regAdjective "quello") ;
+ these_Det = mkDet Pl (regAdjective "questo") ;
+ those_Det = mkDet Pl (regAdjective "quello") ;
+ every_Det = {s = \\_ => "ogni" ; n = Sg} ;
+ theSg_Det = {s = artDef Sg ; n = Sg} ;
+ thePl_Det = {s = artDef Pl ; n = Pl} ;
+ a_Det = {s = artIndef ; n = Pl} ;
+ plur_Det = {s = \\_ => [] ; n = Pl} ;
+ two_Det = {s = \\_ => "due" ; n = Pl} ;
+
+ very_AdA = {s = "molto"} ;
+ too_AdA = {s = "troppo"} ;
+
+
+ oper
+ copula : Number -> Str = \n -> case n of {
+ Sg => "è" ;
+ Pl => "sono"
+ } ;
+
+ posneg : Bool -> Str = \b -> case b of {
+ True => [] ;
+ False => "non"
+ } ;
+
+ mkDet : Number -> Adjective -> Det = \n,adj -> {
+ s = \\g => adj.s ! g ! n ;
+ n = n ;
+ lock_Det = <>
+ } ;
+
+ artDef : Number -> Gender => Str = \n -> case n of {
+ Sg => table {
+ Masc => pre {"il" ; "lo" / sImpuro} ;
+ Fem => "la"
+ } ;
+ Pl => table {
+ Masc => pre {"i" ; "gli" / sImpuro ; "gli" / vowel} ;
+ Fem => "le"
+ }
+ } ;
+
+ artIndef : Gender => Str = table {
+ Masc => pre {"un" ; "uno" / sImpuro} ;
+ Fem => pre {"una" ; "un'" / vowel}
+ } ;
+
+ sImpuro : Strs = strs {"sb" ; "sp" ; "sy" ; "z"} ;
+ vowel : Strs = strs {"a" ; "e" ; "i" ; "o" ; "u"} ;
+
+}