mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-11 20:22:51 -06:00
index and tutorial
This commit is contained in:
@@ -12,20 +12,27 @@
|
|||||||
<h2>Version 2.1</h2>
|
<h2>Version 2.1</h2>
|
||||||
|
|
||||||
November 8, 2004.
|
November 8, 2004.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<b>Version 2.2 scheduled to be released May 16, 2005!</b> See
|
||||||
|
<a href="doc/gf2.2-highlights.html">highlights</a>.
|
||||||
|
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
</p><h2>News</h2>
|
</p><h2>News</h2>
|
||||||
|
|
||||||
<!--
|
|
||||||
<i>May 9, 2005</i>. Version 2.2 coming soon. Here is a
|
|
||||||
<a href="download-2.2/GF-2.2.tgz">preliminary source release</a>.
|
|
||||||
Here are the <a href="doc/gf2.2-highlights.html">highlights</a>.
|
|
||||||
|
|
||||||
|
<i>May 12, 2005</i>. GF now has a mailing list, to which you can register
|
||||||
|
<a href="https://lists.sourceforge.net/lists/listinfo/gf-tools-users">here</a>.
|
||||||
|
GF also has a project page on SourceForge,
|
||||||
|
<a
|
||||||
|
href="https://sourceforge.net/projects/gf-tools">https://sourceforge.net/projects/gf-tools</a>,
|
||||||
|
but this page does not yet have much content.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
-->
|
|
||||||
|
|
||||||
<i>May 9, 2005</i>.
|
<i>May 9, 2005</i>.
|
||||||
PhD Thesis by
|
PhD Thesis by
|
||||||
|
|||||||
4
doc/tutorial/Fish.gf
Normal file
4
doc/tutorial/Fish.gf
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
abstract Fish = {
|
||||||
|
cat Fish ;
|
||||||
|
fun Salmon, Perch : Fish ;
|
||||||
|
}
|
||||||
5
doc/tutorial/FishEng.gf
Normal file
5
doc/tutorial/FishEng.gf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
concrete FishEng of Fish = {
|
||||||
|
lin
|
||||||
|
Salmon = {s = "salmon"} ;
|
||||||
|
Perch = {s = "perch"} ;
|
||||||
|
}
|
||||||
5
doc/tutorial/Gatherer.gf
Normal file
5
doc/tutorial/Gatherer.gf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
abstract Gatherer = Paleolithic, Fish, Mushrooms ** {
|
||||||
|
fun
|
||||||
|
UseFish : Fish -> CN ;
|
||||||
|
UseMushroom : Mushroom -> CN ;
|
||||||
|
}
|
||||||
BIN
doc/tutorial/Gatherer.gif
Normal file
BIN
doc/tutorial/Gatherer.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
5
doc/tutorial/GathererEng.gf
Normal file
5
doc/tutorial/GathererEng.gf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
concrete GathererEng of Gatherer = PaleolithicEng, FishEng, MushroomsEng ** {
|
||||||
|
lin
|
||||||
|
UseFish x = x ;
|
||||||
|
UseMushroom x = x ;
|
||||||
|
}
|
||||||
4
doc/tutorial/Mushrooms.gf
Normal file
4
doc/tutorial/Mushrooms.gf
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
abstract Mushrooms = {
|
||||||
|
cat Mushroom ;
|
||||||
|
fun Cep, Agaric : Mushroom ;
|
||||||
|
}
|
||||||
5
doc/tutorial/MushroomsEng.gf
Normal file
5
doc/tutorial/MushroomsEng.gf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
concrete MushroomsEng of Mushrooms = {
|
||||||
|
lin
|
||||||
|
Cep = {s = "cep"} ;
|
||||||
|
Agaric = {s = "agaric"} ;
|
||||||
|
}
|
||||||
5
doc/tutorial/Neolithic.gf
Normal file
5
doc/tutorial/Neolithic.gf
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
abstract Neolithic = Paleolithic ** {
|
||||||
|
fun
|
||||||
|
Fire, Wheel : CN ;
|
||||||
|
Think : V ;
|
||||||
|
}
|
||||||
6
doc/tutorial/NeolithicEng.gf
Normal file
6
doc/tutorial/NeolithicEng.gf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
concrete NeolithicEng of Neolithic = PaleolithicEng ** {
|
||||||
|
lin
|
||||||
|
Fire = {s = "fire"} ;
|
||||||
|
Wheel = {s = "wheel"} ;
|
||||||
|
Think = {s = "thinks"} ;
|
||||||
|
}
|
||||||
@@ -11,15 +11,18 @@
|
|||||||
|
|
||||||
<b>3rd Edition, for GF version 2.2 or later</b>
|
<b>3rd Edition, for GF version 2.2 or later</b>
|
||||||
|
|
||||||
</p><p>
|
<p>
|
||||||
|
|
||||||
<a href="http://www.cs.chalmers.se/~aarne">Aarne Ranta</a>
|
<a href="http://www.cs.chalmers.se/~aarne">Aarne Ranta</a>
|
||||||
|
|
||||||
</p>
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<tt>aarne@cs.chalmers.se</tt>
|
<tt>aarne@cs.chalmers.se</tt>
|
||||||
</p></center>
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
12 May 2005
|
||||||
|
</center>
|
||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
@@ -29,12 +32,13 @@ The term GF is used for different things:
|
|||||||
<ul>
|
<ul>
|
||||||
<li> a <b>program</b> used for working with grammars
|
<li> a <b>program</b> used for working with grammars
|
||||||
<li> a <b>programming language</b> in which grammars can be written
|
<li> a <b>programming language</b> in which grammars can be written
|
||||||
<li> a <b>theory</b> about the concepts of grammars and languages
|
<li> a <b>theory</b> about grammars and languages
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
This tutorial is about the GF program and the GF programming language.
|
This tutorial is primarily about the GF program and
|
||||||
|
the GF programming language.
|
||||||
It will guide you
|
It will guide you
|
||||||
<ul>
|
<ul>
|
||||||
<li> to use the GF program
|
<li> to use the GF program
|
||||||
@@ -43,8 +47,9 @@ It will guide you
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
<h3>The GF program</h3>
|
<h3>Getting the GF program</h3>
|
||||||
|
|
||||||
The program is open-source free software, which you can download from the
|
The program is open-source free software, which you can download from the
|
||||||
GF Homepage:<br>
|
GF Homepage:<br>
|
||||||
@@ -60,8 +65,8 @@ There you can download
|
|||||||
<li> grammar libraries and examples
|
<li> grammar libraries and examples
|
||||||
</ul>
|
</ul>
|
||||||
If you want to compile GF from source, you need Haskell and Java
|
If you want to compile GF from source, you need Haskell and Java
|
||||||
compilers. But normally you don't have to compile, and you don't
|
compilers. But normally you don't have to compile, and you definitely
|
||||||
need to know Haskell or Java to use GF.
|
don't need to know Haskell or Java to use GF.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
@@ -127,7 +132,7 @@ you imported. Try parsing something else, and you fail
|
|||||||
> p "hello world"
|
> p "hello world"
|
||||||
No success in cf parsing
|
No success in cf parsing
|
||||||
no tree found
|
no tree found
|
||||||
<pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
@@ -183,6 +188,7 @@ generate ten strings with one and the same command:
|
|||||||
To generate <i>all</i> sentence that a grammar
|
To generate <i>all</i> sentence that a grammar
|
||||||
can generate, use the command <tt>generate_trees = gt</tt>.
|
can generate, use the command <tt>generate_trees = gt</tt>.
|
||||||
<pre>
|
<pre>
|
||||||
|
> generate_trees | l
|
||||||
this louse laughs
|
this louse laughs
|
||||||
this louse sleeps
|
this louse sleeps
|
||||||
this louse swims
|
this louse swims
|
||||||
@@ -197,12 +203,13 @@ You get quite a few trees but not all of them: only up to a given
|
|||||||
<b>depth</b> of trees. To see how you can get more, use the
|
<b>depth</b> of trees. To see how you can get more, use the
|
||||||
<tt>help = h</tt> command,
|
<tt>help = h</tt> command,
|
||||||
<pre>
|
<pre>
|
||||||
h gr
|
help gr
|
||||||
</pre>
|
</pre>
|
||||||
<b>Quiz</b>. If the command <tt>gt</tt> generated all
|
<b>Quiz</b>. If the command <tt>gt</tt> generated all
|
||||||
trees in your grammar, it would never terminate. Why?
|
trees in your grammar, it would never terminate. Why?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
<h3>More on pipes; tracing</h3>
|
<h3>More on pipes; tracing</h3>
|
||||||
|
|
||||||
@@ -509,10 +516,38 @@ Each module is compiled into a <tt>.gfc</tt> file.
|
|||||||
|
|
||||||
Import <tt>PaleolithicEng.gf</tt> and try what happens
|
Import <tt>PaleolithicEng.gf</tt> and try what happens
|
||||||
<pre>
|
<pre>
|
||||||
|
> i PaleolithicEng.gf
|
||||||
</pre>
|
</pre>
|
||||||
Nothing more than before, except that the GFC files
|
The GF program does not only read the file
|
||||||
are generated.
|
<tt>PaleolithicEng.gf</tt>, but also all other files that it
|
||||||
|
depends on - in this case, <tt>Paleolithic.gf</tt>.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
For each file that is compiles, a <tt>.gfc</tt> file
|
||||||
|
is generated. The GFC format (="GF Canonical") is the
|
||||||
|
"machine code" of GF, which is faster to process than
|
||||||
|
GF source files. When reading a module, GF knows whether
|
||||||
|
to use an existing <tt>.gfc</tt> file or to generate
|
||||||
|
a new one, by looking at modification times.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- NEW -->
|
||||||
|
<h4>Multilingual grammar</h4>
|
||||||
|
|
||||||
|
The main advantage of separating abstract from concrete syntax is that
|
||||||
|
one abstract syntax can be equipped with many concrete syntaxes.
|
||||||
|
A system with this property is called a <b>multilingual grammar</b>.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
Multilingual grammars can be used for applications such as
|
||||||
|
translation. Let us buid an Italian concrete syntax for
|
||||||
|
<tt>Paleolithic</tt> and then test the resulting
|
||||||
|
multilingual grammar.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
@@ -554,17 +589,39 @@ lin
|
|||||||
|
|
||||||
Import without first emptying
|
Import without first emptying
|
||||||
<pre>
|
<pre>
|
||||||
|
> i PaleolithicEng.gf
|
||||||
|
> i PaleolithicIta.gf
|
||||||
</pre>
|
</pre>
|
||||||
Try generation now:
|
Try generation now:
|
||||||
<pre>
|
<pre>
|
||||||
|
> gr | l
|
||||||
|
un pidocchio uccide questo ragazzo
|
||||||
|
|
||||||
|
> gr | l -lang=PaleolithicEng
|
||||||
|
that louse eats a louse
|
||||||
</pre>
|
</pre>
|
||||||
Translate by using a pipe:
|
Translate by using a pipe:
|
||||||
<pre>
|
<pre>
|
||||||
|
> p -lang=PaleolithicEng "the boy eats the snake" | l -lang=PaleolithicIta
|
||||||
|
il ragazzo mangia il serpente
|
||||||
</pre>
|
</pre>
|
||||||
Inspect the shell state (<tt>print_options = po</tt>):
|
|
||||||
|
|
||||||
|
<!-- NEW -->
|
||||||
|
<h4>The multilingual shell state</h4>
|
||||||
|
|
||||||
|
A GF shell is at any time in a state, which
|
||||||
|
contains a multilingual grammar. One of the concrete
|
||||||
|
syntaxes is the "main" one, which means that parsing and linearization
|
||||||
|
are performed by using it. By default, the main concrete syntax is the
|
||||||
|
last-imported one. As we saw on previous slide, the <tt>lang</tt> flag
|
||||||
|
can be used to change the linearization and parsing grammar.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
To see what the multilingual grammar is (as well as some other
|
||||||
|
things), you can use the command
|
||||||
|
<tt>print_options = po</tt>:
|
||||||
<pre>
|
<pre>
|
||||||
> print_options
|
> print_options
|
||||||
main abstract : Paleolithic
|
main abstract : Paleolithic
|
||||||
@@ -574,11 +631,86 @@ Inspect the shell state (<tt>print_options = po</tt>):
|
|||||||
|
|
||||||
|
|
||||||
<!-- NEW -->
|
<!-- NEW -->
|
||||||
<h4>Extending the grammar</h4>
|
<h4>Extending a grammar</h4>
|
||||||
|
|
||||||
Neolithic: fire, wheel, think,...
|
The module system of GF makes it possible to <b>extend</b> a
|
||||||
|
grammar in different ways. The syntax of extension is
|
||||||
|
shown by the following example.
|
||||||
|
<pre>
|
||||||
|
abstract Neolithic = Paleolithic ** {
|
||||||
|
fun
|
||||||
|
Fire, Wheel : CN ;
|
||||||
|
Think : V ;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
Parallel to the abstract syntax, extensions can
|
||||||
|
be built for concrete syntaxes:
|
||||||
|
<pre>
|
||||||
|
concrete NeolithicEng of Neolithic = PaleolithicEng ** {
|
||||||
|
lin
|
||||||
|
Fire = {s = "fire"} ;
|
||||||
|
Wheel = {s = "wheel"} ;
|
||||||
|
Think = {s = "thinks"} ;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
The effect of extension is that all of the contents of the extended
|
||||||
|
and extending module are put together.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- NEW -->
|
||||||
|
<h4>Multiple inheritance</h4>
|
||||||
|
|
||||||
|
Specialized vocabularies can be represented as small grammars that
|
||||||
|
only do "one thing" each, e.g.
|
||||||
|
<pre>
|
||||||
|
abstract Fish = {
|
||||||
|
cat Fish ;
|
||||||
|
fun Salmon, Perch : Fish ;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract Mushrooms = {
|
||||||
|
cat Mushroom ;
|
||||||
|
fun Cep, Agaric : Mushroom ;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
They can afterwards be combined in bigger grammars by using
|
||||||
|
<b>multiple inheritance</b>, i.e. extension of several grammars at the
|
||||||
|
same time:
|
||||||
|
<pre>
|
||||||
|
abstract Gatherer = Paleolithic, Fish, Mushrooms ** {
|
||||||
|
fun
|
||||||
|
UseFish : Fish -> CN ;
|
||||||
|
UseMushroom : Mushroom -> CN ;
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- NEW -->
|
||||||
|
<h4>Visualizing module structure</h4>
|
||||||
|
|
||||||
|
When you have created all the abstract syntaxes and
|
||||||
|
one set of concrete syntaxes needed for <tt>Gatherer</tt>,
|
||||||
|
your grammar consists of eight GF modules. To see how their
|
||||||
|
dependences look like, you can use the command
|
||||||
|
<tt>visualize_graph = vg</tt>,
|
||||||
|
<pre>
|
||||||
|
> visualize_graph
|
||||||
|
</pre>
|
||||||
|
and the graph will pop up in a separate window. It can also
|
||||||
|
be printed out into a file, e.g. a <tt>.gif</tt> file that
|
||||||
|
can be included in an HTML document
|
||||||
|
<pre>
|
||||||
|
> pm -printer=graph | wf Gatherer.dot
|
||||||
|
> ! dot -Tgif Gatherer.dot > Gatherer.gif
|
||||||
|
</pre>
|
||||||
|
The latter command is a Unix command, issued from GF by using the
|
||||||
|
shell escape symbol <tt>!</tt>. The resulting graph is shown below.
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<img src="Gatherer.gif">
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user