From 486eed70c57ac584f16abdd07da012aa8b1d4b0b Mon Sep 17 00:00:00 2001 From: aarne Date: Sun, 15 May 2005 19:14:15 +0000 Subject: [PATCH] on resource --- doc/tutorial/gf-tutorial2.html | 241 ++++++++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 2 deletions(-) diff --git a/doc/tutorial/gf-tutorial2.html b/doc/tutorial/gf-tutorial2.html index cc3f6f3d8..22cf7a38e 100644 --- a/doc/tutorial/gf-tutorial2.html +++ b/doc/tutorial/gf-tutorial2.html @@ -732,12 +732,249 @@ The graph uses -

Topics still to be written

+

Resource modules

-Resource modules, parameter, linearization types, operations +Suppose we want to say, with the vocabulary included in +Paleolithic.gf, things like +
+  the boy eats two snakes
+  all boys sleep  
+
+The new grammatical facility we need are the plural forms +of nouns and verbs (boys, sleep), as opposed to their +singular forms.

+The introduction of plural forms requires two things: +

+Different languages have different rules of inflection and agreement. +For instance, Italian has also agreement in gender (masculine vs. feminine). +We want to be able to ignore such differences in the abstract +syntax. + +

+ +To be able to do all this, we need a couple of new judgement forms, +a new module form, and a more powerful way of expressing linearization +rules. + + + +

Parameters and tables

+ +We define the parameter type of number in Englisn by +using a new form of judgement: +
+  param Number = Sg | Pl ;
+
+To express that nouns in English have a linearization +depending on number, we replace the linearization type {s : Str} +with a type where the s field is a table depending on number: +
+  lincat CN = {s : Number => Str} ;
+
+The table type Number => Str is in many respects similar to +a function type (Number -> Str). The main restriction is that the +argument type of a table type must always be a parameter type. This means +that the argument-value pairs can be listed in a finite table. The following +example shows such a table: +
+  lin Boy = {s = table {
+    Sg => "boy" ;
+    Pl => "boys"
+    }
+  } ;
+
+The application of a table to a parameter is done by the selection +operator !. For instance, +
+  Boy.s ! Pl
+
+is a selection, whose value is "boys". + + + +

Inflection tables, paradigms, and oper definitions

+ +All English common nouns are inflected in number, most of them in the +same way: the plural form is formed from the singular form by adding the +ending s. This rule is an example of +a paradigm - a formula telling how the inflection +forms of a word are formed. + +

+ +From GF point of view, a paradigm is a function that takes a lemma - +a string also known as a dictionary form - and returns an inflection +table of desired type. Paradigms are not functions in the sense of the +fun judgements of abstract syntax (which operate on trees and not +on strings). Thus we call them operations for the sake of clarity, +introduce one one form of judgement, with the keyword oper. As an +example, the following operation defines the regular noun paradigm of English: +

+  oper regNoun : Str -> {s : Number => Str} = \x -> {
+    s = table {
+      Sg => x ;
+      Pl => x + "s"
+      }
+    } ;
+
+Thus an oper judgement includes the name of the defined operation, +its type, and an expression defining it. As for the syntax of the defining +expression, notice the lambda abstraction form \x -> t of +the function, and the glueing operator + telling that +the string held in the variable x and the ending "s" +are written together to form one token. + + + +

The resource module type

+ +Parameter and operator definitions do not belong to the abstract syntax. +They can be used when defining concrete syntax - but they are not +tied to a particular set of linearization rules. +The proper way to see them is as auxiliary concepts, as resources +usable in many concrete syntaxes. + +

+ +The resource module type thus consists of +param and oper definitions. Here is an +example. +

+  resource MorphoEng = {
+    param
+      Number = Sg | Pl ;
+    oper
+      Noun  : Type = {s : Number => Str} ;
+      regNoun : Str -> Noun = \x -> {
+        s = table {
+          Sg => x ;
+          Pl => x + "s"
+          }
+        } ;
+  }
+
+Resource modules can extend other resource modules, in the +same way as modules of other types can extend modules of the +same type. + + + + +

Opening a resource

+ +Any number of resource modules can be +opened in a concrete syntax, which +makes the parameter and operation definitions contained +in the resource usable in the concrete syntax. Here is +an example, where the resource MorphoEng is +open in (the fragment of) a new version of PaleolithicEng. +
+concrete PaleolithicEng of Paleolithic = open MorphoEng in {
+  lincat 
+    CN = Noun ;
+  lin
+    Boy   = regNoun "boy" ;
+    Snake = regNoun "snake" ;
+    Worm  = regNoun "worm" ;
+  }
+
+Notice that, just like in abstract syntax, function application +is written by juxtaposition of the function and the argument. + +

+ +Using operations defined in resource modules is clearly a concise +way of giving e.g. inflection tables and other repeated patterns +of expression. In addition, it enables a new kind of modularity +and division of labour in grammar writing: grammarians familiar with +the linguistic details of a language can put this knowledge +available through resource grammars, whose users only need +to pick the right operations and not to know their implementation +details. + + + + +

Worst-case macros and data abstraction

+ +Some English nouns, such as louse, are so irregular that +it makes little sense to see them as instances of a paradigm. Even +then, it is useful to perform data abstraction from the +definition of the type Noun, and introduce a constructor +operation, a worst-case macro for nouns: +
+  oper mkNoun : Str -> Str -> Noun = \x,y -> {
+    s = table {
+      Sg => x ;
+      Pl => y
+      }
+    } ;
+
+Thus we define +
+  lin Louse = mkNoun "louse" "lice" ;
+
+instead of writing the inflection table explicitly. + +

+ +The grammar engineering advantage of worst-case macros is that +the author of the resource module may change the definitions of +Noun and mkNoun, and still retain the +interface (i.e. the system of type signatures) that makes it +correct to use these functions in concrete modules. In programming +terms, Noun is then treated as an abstract datatype. + + + + +

A system of paradigms using Prelude operations

+ +The regular noun paradigm regNoun can - and should - of course be defined +by the worst-case macro mkNoun. In addition, some more noun paradigms +could be defined, for instance, +
+  regNoun : Str -> Noun = \snake -> mkNoun snake (snake + "s") ;
+  sNoun   : Str -> Noun = \kiss  -> mkNoun kiss  (kiss  + "es") ;
+
+What about nouns like fly, with the plural flies? The already +available solution is to use the so-called "technical stem" fl as +argument, and define +
+  yNoun   : Str -> Noun = \fl -> mkNoun (fl  + "y") (fl  + "ies") ;
+
+But this paradigm would be very unintuitive to use, because the "technical stem" +is not even an existing form of the word. A better solution is to use +the string operator init, which returns the initial segment (i.e. +all characters but the last) of a string: +
+  yNoun   : Str -> Noun = \fly -> mkNoun fly (init fly  + "ies") ;  
+
+The operator init belongs to a set of operations in the +resource module Prelude, which therefore has to be +opened so that init can be used. + + + + +

An intelligent noun paradigm using case expressions

+ + + + + + + +

Topics still to be written

+ + Morpho and translation quiz