From f00d44b57d8c07f69de049418bb4e4df9597cd61 Mon Sep 17 00:00:00 2001 From: aarne Date: Mon, 16 May 2005 16:07:18 +0000 Subject: [PATCH] more in tutorial --- doc/tutorial/gf-tutorial2.html | 156 ++++++++++++++++++++++++++++++++- src/tools/Htmls.hs | 5 +- 2 files changed, 158 insertions(+), 3 deletions(-) diff --git a/doc/tutorial/gf-tutorial2.html b/doc/tutorial/gf-tutorial2.html index 22cf7a38e..edf7d66c5 100644 --- a/doc/tutorial/gf-tutorial2.html +++ b/doc/tutorial/gf-tutorial2.html @@ -607,6 +607,38 @@ Translate by using a pipe: + + +

Translation quiz

+ +This is a simple kind of language exercises that can be automatically +generated from a multilingual grammar. The system generates a set of +random sentence, displays them in one language, and checks the user's +answer given in another language. The command translation_quiz = tq +makes this in a subshell of GF. +
+  > translation_quiz PaleolithicEng PaleolithicIta
+
+  Welcome to GF Translation Quiz.
+  The quiz is over when you have done at least 10 examples
+  with at least 75 % success.
+  You can interrupt the quiz by entering a line consisting of a dot ('.').
+
+  a green boy washes the louse
+  un ragazzo verde lava il gatto
+
+  No, not un ragazzo verde lava il gatto, but
+  un ragazzo verde lava il pidocchio
+  Score 0/1
+
+You can also generate a list of translation exercises and save it in a +file for later use, by the command translation_list = tl +
+  > translation_list PaleolithicEng PaleolithicIta 25
+
+(The number 25 is the number of sentences generated.) + +

The multilingual shell state

@@ -966,16 +998,138 @@ resource module Prelude, which therefore has to be

An intelligent noun paradigm using case expressions

+It may be hard for the user of a resource morphology to pick the right +inflection paradigm. A way to help this is to define a more intelligent +paradigms, which chooses the ending by first analysing the lemma. +The following variant for English regular nouns puts together all the +previously shown paradigms, and chooses one of them on the basis of +the final letter of the lemma. +
+  regNoun : Str -> Noun = \s -> case last s of {
+    "s" | "z" => mkNoun s (s + "es") ;
+    "y"       => mkNoun s (init s + "ies") ;
+    _         => mkNoun s (s + "s")
+    } ;
+
+This definition displays many GF expression forms not shown befores; +these forms are explained in the following section. + +

+ +The paradigms regNoun does not give the correct forms for +all nouns. For instance, louse - lice and +fish - fish must be given by using mkNoun. +Also the word boy would be inflected incorrectly; to prevent +this, either use mkNoun or modify +regNoun so that the "y" case does not +apply if the second-last character is a vowel. + +

Pattern matching

+ +Expressions of the table form are built from lists of +argument-value pairs. These pairs are called the branches +of the table. In addition to constants introduced in +param definitions, the left-hand side of a branch can more +generally be a pattern, and the computation of selection is +then performed by pattern matching: +
    +
  • a variable pattern (identifier other than constant parameter) matches anything +
  • the wild card _ matches anything +
  • a string literal pattern, e.g. "s", matches the same string +
  • a disjunctive pattern P | ... | Q matches anything that + one of the disjuncts matches +
+Pattern matching is performed in the order in which the branches +appear in the table. + +

+ +As syntactic sugar, one-branch tables can be written concisely, +

+  \\P,...,Q => t  ===  table {P => ... table {Q => t} ...}
+
+Finally, the case expressions common in functional +programming languages are syntactic sugar for table selections: +
+  case e of {...} ===  table {...} ! e
+
+ + + + +

Parametric vs. inherent features, agreement

+ +The rule of subject-verb agreement in English says that the verb +phrase must be inflected in the number of the subject. This +means that a noun phrase (functioning as a subject), in some sense +has a number, which it "sends" to the verb. The verb does not +have a number, but must be able to receive whatever number the +subject has. This distinction is nicely represented by the +different linearization types of noun phrases and verb phrases: +
+  lincat NP = {s : Str ; n : Number} ;
+  lincat VP = {s : Number => Str} ;
+
+We say that the number of NP is an inherent feature, +whereas the number of NP is parametric. + +

+ +The agreement rule itself is expressed in the linearization rule of +the predication structure: +

+  lin PredVP np vp = {s = np.s ++ vp.s ! np.n} ;
+
+The following page will present a new version of +PaleolithingEng, assuming an abstract syntax +xextended with All and Two. +It also assumes that MorphoEng has a paradigm +regVerb for regular verbs (which need only be +regular only in the present tensse). +The reader is invited to inspect the way in which agreement works in +the formation of noun phrases and verb phrases. + + + + +

English concrete syntax with parameters

+ +
+concrete PaleolithicEng of Paleolithic = open MorphoEng in {
+lincat 
+  S, A          = {s : Str} ; 
+  VP, CN, V, TV = {s : Number => Str} ; 
+  NP            = {s : Str ; n : Number} ; 
+lin
+  PredVP np vp  = {s = np.s ++ vp.s ! np.n} ;
+  UseV   v      = v ;
+  ComplTV tv np = {s = \\n => tv.s ! n ++ np.s} ;
+  UseA   a   = {s = \\n => case n of {Sg => "is" ; Pl => "are"} ++ a.s} ;
+  This  cn   = {s = "this" ++ cn.s ! Sg } ; 
+  Indef cn   = {s = "a" ++ cn.s ! Sg} ; 
+  All   cn   = {s = "all" ++ cn.s ! Pl} ; 
+  Two   cn   = {s = "two" ++ cn.s ! Pl} ; 
+  ModA  a cn = {s = \\n => a.s ++ cn.s ! n} ;
+  Louse  = mkNoun "louse" "lice" ;
+  Snake  = regNoun "snake" ;
+  Green  = {s = "green"} ;
+  Warm   = {s = "warm"} ;
+  Laugh  = regVerb "laugh" ;
+  Sleep  = regVerb "sleep" ;
+  Kill   = regVerb "kill" ;
+}
+
+

Topics still to be written

-Morpho and translation quiz +Morpho quiz

diff --git a/src/tools/Htmls.hs b/src/tools/Htmls.hs index 08c18c907..ce0b3bb28 100644 --- a/src/tools/Htmls.hs +++ b/src/tools/Htmls.hs @@ -4,9 +4,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/14 08:38:55 $ +-- > CVS $Date: 2005/05/16 17:07:18 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.10 $ +-- > CVS $Revision: 1.11 $ -- -- chop an HTML file into separate files, each linked to the next and previous. -- the names of the files are n-file, with n = 01,02,... @@ -19,6 +19,7 @@ module Main (main) where import System +import Char main :: IO () main = do