tutorial in final form

This commit is contained in:
aarne
2007-07-08 16:36:56 +00:00
parent 812be937fd
commit c7e85d60fb
20 changed files with 8678 additions and 3401 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -1,6 +1,8 @@
all: html tex
html: html:
txt2tags -thtml --toc gf-tutorial2_8.txt txt2tags -thtml --toc gf-tutorial2.txt
tex: tex:
txt2tags -ttex --toc gf-tutorial2_8.txt txt2tags -ttex --toc gf-tutorial2.txt
pdflatex gf-tutorial2_8.tex pdflatex gf-tutorial2.tex
pdflatex gf-tutorial2_8.tex pdflatex gf-tutorial2.tex

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
interface Lex = open Grammar in { interface Lex = open Syntax in {
oper oper
even_A : A ; even_A : A ;

View File

@@ -1,8 +1,8 @@
instance LexEng of Lex = open GrammarEng, ParadigmsEng in { instance LexEng of Lex = open SyntaxEng, ParadigmsEng in {
oper oper
even_A = regA "even" ; even_A = mkA "even" ;
odd_A = regA "odd" ; odd_A = mkA "odd" ;
zero_PN = regPN "zero" ; zero_PN = mkPN "zero" ;
} }

View File

@@ -1,8 +1,8 @@
instance LexFre of Lex = open GrammarFre, ParadigmsFre in { instance LexFre of Lex = open SyntaxFre, ParadigmsFre in {
oper oper
even_A = regA "pair" ; even_A = mkA "pair" ;
odd_A = regA "impair" ; odd_A = mkA "impair" ;
zero_PN = regPN "zéro" ; zero_PN = mkPN "zéro" ;
} }

View File

@@ -1,7 +1,5 @@
--# -path=.:api:present:prelude:mathematical --# -path=.:present:prelude
concrete MathEng of Math = MathI with concrete MathEng of Math = MathI with
(Grammar = GrammarEng), (Syntax = SyntaxEng),
(Combinators = CombinatorsEng),
(Predication = PredicationEng),
(Lex = LexEng) ; (Lex = LexEng) ;

View File

@@ -1,7 +1,5 @@
--# -path=.:api:present:prelude:mathematical --# -path=.:present:prelude
concrete MathFre of Math = MathI with concrete MathFre of Math = MathI with
(Grammar = GrammarFre), (Syntax = SyntaxFre),
(Combinators = CombinatorsFre),
(Predication = PredicationFre),
(Lex = LexFre) ; (Lex = LexFre) ;

View File

@@ -1,5 +1,5 @@
incomplete concrete MathI of Math = incomplete concrete MathI of Math =
open Grammar, Combinators, Predication, Lex in { open Syntax, Lex in {
flags startcat = Prop ; flags startcat = Prop ;
@@ -8,9 +8,9 @@ incomplete concrete MathI of Math =
Elem = NP ; Elem = NP ;
lin lin
And x y = coord and_Conj x y ; And x y = mkS and_Conj x y ;
Even x = PosCl (pred even_A x) ; Even x = mkS (mkCl x even_A) ;
Odd x = PosCl (pred odd_A x) ; Odd x = mkS (mkCl x odd_A) ;
Zero = UsePN zero_PN ; Zero = mkNP zero_PN ;
} }

View File

@@ -4,7 +4,7 @@ Aarne Ranta
In this directory, we have a minimal resource grammar We will show how to build a minimal resource grammar
application whose architecture scales up to much application whose architecture scales up to much
larger applications. The application is run from the larger applications. The application is run from the
shell by the command shell by the command
@@ -46,75 +46,68 @@ The system was built in 22 steps explained below.
1. Write ``Math.gf``, which defines what you want to say. 1. Write ``Math.gf``, which defines what you want to say.
``` ```
abstract Math = { abstract Math = {
cat Prop ; Elem ; cat Prop ; Elem ;
fun fun
And : Prop -> Prop -> Prop ; And : Prop -> Prop -> Prop ;
Even : Elem -> Prop ; Even : Elem -> Prop ;
Zero : Elem ; Zero : Elem ;
}
}
``` ```
2. Write ``Lex.gf``, which defines which language-dependent 2. Write ``Lex.gf``, which defines which language-dependent
parts are needed in the concrete syntax. These are mostly parts are needed in the concrete syntax. These are mostly
words (lexicon), but can in fact be any operations. The definitions words (lexicon), but can in fact be any operations. The definitions
only use resource abstract syntax, which is opened. only use resource abstract syntax, which is opened.
``` ```
interface Lex = open Grammar in { interface Lex = open Syntax in {
oper oper
even_A : A ; even_A : A ;
zero_PN : PN ; zero_PN : PN ;
}
}
``` ```
3. Write ``LexEng.gf``, the English implementation of ``Lex.gf`` 3. Write ``LexEng.gf``, the English implementation of ``Lex.gf``
This module uses English resource libraries. This module uses English resource libraries.
``` ```
instance LexEng of Lex = open GrammarEng, ParadigmsEng in { instance LexEng of Lex = open GrammarEng, ParadigmsEng in {
oper oper
even_A = regA "even" ; even_A = regA "even" ;
zero_PN = regPN "zero" ; zero_PN = regPN "zero" ;
} }
``` ```
4. Write ``MathI.gf``, a language-independent concrete syntax of 4. Write ``MathI.gf``, a language-independent concrete syntax of
``Math.gf``. It opens interfaces can resource abstract syntaxes, ``Math.gf``. It opens interfaces.
which makes it an incomplete module, aka. parametrized module, aka. which makes it an incomplete module, aka. parametrized module, aka.
functor. functor.
``` ```
incomplete concrete MathI of Math = incomplete concrete MathI of Math =
open Grammar, Combinators, Predication, Lex in {
open Syntax, Lex in {
flags startcat = Prop ; flags startcat = Prop ;
lincat lincat
Prop = S ; Prop = S ;
Elem = NP ; Elem = NP ;
lin lin
And x y = coord and_Conj x y ; And x y = mkS and_Conj x y ;
Even x = PosCl (pred even_A x) ; Even x = mkS (mkCl x even_A) ;
Zero = UsePN zero_PN ; Zero = mkNP zero_PN ;
} }
``` ```
5. Write ``MathEng.gf``, which is just an instatiation of ``MathI.gf``, 5. Write ``MathEng.gf``, which is just an instatiation of ``MathI.gf``,
replacing the interfaces by their English instances. This is the module replacing the interfaces by their English instances. This is the module
that will be used as a top module in GF, so it contains a path to that will be used as a top module in GF, so it contains a path to
the libraries. the libraries.
``` ```
--# -path=.:api:present:prelude:mathematical instance LexEng of Lex = open SyntaxEng, ParadigmsEng in {
oper
concrete MathEng of Math = MathI with even_A = mkA "even" ;
(Grammar = GrammarEng), zero_PN = mkPN "zero" ;
(Combinators = CombinatorsEng), }
(Predication = PredicationEng),
(Lex = LexEng) ;
``` ```
===Testing=== ===Testing===
6. Test the grammar in GF by random generation and parsing. 6. Test the grammar in GF by random generation and parsing.
@@ -128,39 +121,39 @@ concrete MathEng of Math = MathI with
``` ```
When importing the grammar, you will fail if you haven't When importing the grammar, you will fail if you haven't
- correctly defined your ``GF_LIB_PATH`` as ``GF/lib`` - correctly defined your ``GF_LIB_PATH`` as ``GF/lib``
- compiled the resourcec by ``make`` in ``GF/lib/resource-1.0`` - installed the resource package or
compiled the resource from source by ``make`` in ``GF/lib/resource-1.0``
===Adding a new language=== ===Adding a new language===
7. Now it is time to add a new language. Write a French lexicon ``LexFre.gf``: 7. Now it is time to add a new language. Write a French lexicon ``LexFre.gf``:
``` ```
instance LexFre of Lex = open GrammarFre, ParadigmsFre in { instance LexFre of Lex = open SyntaxFre, ParadigmsFre in {
oper oper
even_A = regA "pair" ; even_A = mkA "pair" ;
zero_PN = regPN "zéro" ; zero_PN = mkPN "zéro" ;
} }
``` ```
8. You also need a French concrete syntax, ``MathFre.gf``: 8. You also need a French concrete syntax, ``MathFre.gf``:
``` ```
--# -path=.:api:present:prelude:mathematical --# -path=.:present:prelude
concrete MathFre of Math = MathI with concrete MathFre of Math = MathI with
(Grammar = GrammarFre), (Syntax = SyntaxFre),
(Combinators = CombinatorsFre), (Lex = LexFre) ;
(Predication = PredicationFre),
(Lex = LexFre) ;
``` ```
9. This time, you can test multilingual generation: 9. This time, you can test multilingual generation:
``` ```
> i MathFre.gf > i MathFre.gf
> gr -tr | l -multi > gr | tb
Even Zero Even Zero
zéro est pair zéro est pair
zero is even zero is even
``` ```
===Extending the language=== ===Extending the language===
10. You want to add a predicate saying that a number is odd. 10. You want to add a predicate saying that a number is odd.
@@ -175,15 +168,15 @@ It is first added to ``Math.gf``:
12. Then you can give a language-independent concrete syntax in 12. Then you can give a language-independent concrete syntax in
``MathI.gf``: ``MathI.gf``:
``` ```
lin Odd x = PosCl (pred odd_A x) ; lin Odd x = mkS (mkCl x odd_A) ;
``` ```
13. The new word is implemented in ``LexEng.gf``. 13. The new word is implemented in ``LexEng.gf``.
``` ```
oper odd_A = regA "odd" ; oper odd_A = mkA "odd" ;
``` ```
14. The new word is implemented in ``LexFre.gf``. 14. The new word is implemented in ``LexFre.gf``.
``` ```
oper odd_A = regA "impair" ; oper odd_A = mkA "impair" ;
``` ```
15. Now you can test with the extended lexicon. First empty 15. Now you can test with the extended lexicon. First empty
the environment to get rid of the old abstract syntax, then the environment to get rid of the old abstract syntax, then
@@ -192,12 +185,13 @@ import the new versions of the grammars.
> e > e
> i MathEng.gf > i MathEng.gf
> i MathFre.gf > i MathFre.gf
> gr -tr | l -multi > gr | tb
And (Odd Zero) (Even Zero) And (Odd Zero) (Even Zero)
zéro est impair et zéro est pair zéro est impair et zéro est pair
zero is odd and zero is even zero is odd and zero is even
``` ```
==Building a user program== ==Building a user program==
===Producing a compiled grammar package=== ===Producing a compiled grammar package===

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

View File

@@ -7,9 +7,18 @@
<P ALIGN="center"><CENTER><H1>GF Resource Grammar Library v. 1.2</H1> <P ALIGN="center"><CENTER><H1>GF Resource Grammar Library v. 1.2</H1>
<FONT SIZE="4"> <FONT SIZE="4">
<I>Author: Aarne Ranta &lt;aarne (at) cs.chalmers.se&gt;</I><BR> <I>Author: Aarne Ranta &lt;aarne (at) cs.chalmers.se&gt;</I><BR>
Last update: Thu Jul 5 23:14:56 2007 Last update: Sun Jul 8 17:07:04 2007
</FONT></CENTER> </FONT></CENTER>
<P>
<center>
</P>
<P>
<IMG ALIGN="middle" SRC="10lang-large.png" BORDER="0" ALT="">
</P>
<P>
</center>
</P>
<P> <P>
The GF Resource Grammar Library defines the basic grammar of The GF Resource Grammar Library defines the basic grammar of
ten languages: ten languages:
@@ -273,8 +282,7 @@ Swedish
</P> </P>
<H2>More reading</H2> <H2>More reading</H2>
<P> <P>
<A HREF="../../../doc/resource.pdf">GF Resource Grammar Library</A> (pdf). <A HREF="synopsis.html">Synopsis</A>. The concise guide to API v. 1.2.
Printable user manual with API documentation.
</P> </P>
<P> <P>
<A HREF="gslt-sem-2006.html">Grammars as Software Libraries</A>. Slides <A HREF="gslt-sem-2006.html">Grammars as Software Libraries</A>. Slides
@@ -302,7 +310,11 @@ Slides showing how linearization rules are written as strings parsable by the re
Slides showing how to use the multimodal resource library. N.B. the library Slides showing how to use the multimodal resource library. N.B. the library
examples are from <CODE>multimodal/old</CODE>, which is a reduced-size API. examples are from <CODE>multimodal/old</CODE>, which is a reduced-size API.
</P> </P>
<P>
<A HREF="../../../doc/resource.pdf">GF Resource Grammar Library</A> (pdf).
Printable user manual with API documentation, for version 1.0.
</P>
<!-- html code generated by txt2tags 2.4 (http://txt2tags.sf.net) --> <!-- html code generated by txt2tags 2.3 (http://txt2tags.sf.net) -->
<!-- cmdline: txt2tags -thtml index.txt --> <!-- cmdline: txt2tags -thtml index.txt -->
</BODY></HTML> </BODY></HTML>

View File

@@ -8,6 +8,16 @@ Last update: %%date(%c)
%!target:html %!target:html
%!postproc(html): #BCEN <center>
%!postproc(html): #ECEN </center>
#BCEN
[10lang-large.png]
#ECEN
The GF Resource Grammar Library defines the basic grammar of The GF Resource Grammar Library defines the basic grammar of
ten languages: ten languages:
@@ -233,8 +243,7 @@ Swedish
==More reading== ==More reading==
[GF Resource Grammar Library ../../../doc/resource.pdf] (pdf). [Synopsis synopsis.html]. The concise guide to API v. 1.2.
Printable user manual with API documentation.
[Grammars as Software Libraries gslt-sem-2006.html]. Slides [Grammars as Software Libraries gslt-sem-2006.html]. Slides
with background and motivation for the resource grammar library. with background and motivation for the resource grammar library.
@@ -256,3 +265,6 @@ Slides showing how linearization rules are written as strings parsable by the re
Slides showing how to use the multimodal resource library. N.B. the library Slides showing how to use the multimodal resource library. N.B. the library
examples are from ``multimodal/old``, which is a reduced-size API. examples are from ``multimodal/old``, which is a reduced-size API.
[GF Resource Grammar Library ../../../doc/resource.pdf] (pdf).
Printable user manual with API documentation, for version 1.0.

View File

@@ -2944,17 +2944,22 @@ source <A HREF="../finnish/ParadigmsFin.gf"><CODE>http://www.cs.chalmers.se/~aar
</TR> </TR>
<TR> <TR>
<TD><CODE>mkV2</CODE></TD> <TD><CODE>mkV2</CODE></TD>
<TD><CODE>V -&gt; Prep -&gt; V2</CODE></TD> <TD><CODE>Str -&gt; V2</CODE></TD>
<TD>-</TD> <TD>-</TD>
</TR> </TR>
<TR> <TR>
<TD><CODE>caseV2</CODE></TD> <TD><CODE>mkV2</CODE></TD>
<TD><CODE>V -&gt; V2</CODE></TD>
<TD>-</TD>
</TR>
<TR>
<TD><CODE>mkV2</CODE></TD>
<TD><CODE>V -&gt; Case -&gt; V2</CODE></TD> <TD><CODE>V -&gt; Case -&gt; V2</CODE></TD>
<TD>-</TD> <TD>-</TD>
</TR> </TR>
<TR> <TR>
<TD><CODE>dirV2</CODE></TD> <TD><CODE>mkV2</CODE></TD>
<TD><CODE>V -&gt; V2</CODE></TD> <TD><CODE>V -&gt; Prep -&gt; V2</CODE></TD>
<TD>-</TD> <TD>-</TD>
</TR> </TR>
<TR> <TR>

View File

@@ -47,7 +47,8 @@ incomplete concrete NounRomance of Noun =
} ; } ;
SgQuant q = {s = q.s ! False ! Sg} ; SgQuant q = {s = q.s ! False ! Sg} ;
PlQuant q = {s = \\b => q.s ! b ! Pl} ; PlQuant q = {s = \\b,g,c => q.s ! b ! Pl ! g ! c} ;
--- part app: cf NounScand. AR 8/7/2007
PossPron p = { PossPron p = {
s = \\_,n,g,c => possCase g n c ++ p.s ! Poss (aagr g n) ---- il mio! s = \\_,n,g,c => possCase g n c ++ p.s ! Poss (aagr g n) ---- il mio!