mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
section on agreement
This commit is contained in:
@@ -1268,7 +1268,7 @@ concise than GF proper, but also more restricted in expressive power.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
==Using resource modules==
|
==Using operations and resource modules==
|
||||||
|
|
||||||
===The golden rule of functional programming===
|
===The golden rule of functional programming===
|
||||||
|
|
||||||
@@ -1731,54 +1731,160 @@ comprise morphology. This will permit a more radical
|
|||||||
variation between languages (e.g. English and Italian)
|
variation between languages (e.g. English and Italian)
|
||||||
then just the use of different words. In general,
|
then just the use of different words. In general,
|
||||||
parameters and linearization types are different in
|
parameters and linearization types are different in
|
||||||
different languages - but this does not prevent the
|
different languages - but this has no effect on
|
||||||
use of a common abstract syntax.
|
the common abstract syntax.
|
||||||
|
|
||||||
|
We consider a grammar ``Foods``, which is similar to
|
||||||
|
``Food``, with the addition of two plural determiners,
|
||||||
|
```
|
||||||
|
fun These, Those : Kind -> Item ;
|
||||||
|
```
|
||||||
|
and a noun which in Italian has the feminine case; all noun in
|
||||||
|
``Food`` were carefully chosen to be masculine!
|
||||||
|
```
|
||||||
|
fun Pizza : Kind ;
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%--!
|
%--!
|
||||||
===Parametric vs. inherent features, agreement===
|
===Agreement===
|
||||||
|
|
||||||
The rule of subject-verb agreement in English says that the verb
|
In the English ``Foods`` grammar, we need just one type of parameters:
|
||||||
phrase must be inflected in the number of the subject. This
|
``Number`` as defined above. The phrase-forming rule
|
||||||
means that a noun phrase (functioning as a subject), inherently
|
|
||||||
has a number, which it passes 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} ;
|
Is : Item -> Quality -> Phr ;
|
||||||
lincat VP = {s : Number => Str} ;
|
|
||||||
```
|
```
|
||||||
We say that the number of ``NP`` is an **inherent feature**,
|
is affected by the number because of **subject-verb agreement**.
|
||||||
whereas the number of ``NP`` is a **variable feature** (or a
|
In English, agreement says that the verb of a sentence
|
||||||
**parametric feature**).
|
must be inflected in the number of the subject. Thus we will linearize
|
||||||
|
|
||||||
The agreement rule itself is expressed in the linearization rule of
|
|
||||||
the predication function:
|
|
||||||
```
|
```
|
||||||
lin PredVP np vp = {s = np.s ++ vp.s ! np.n} ;
|
Is (This Pizza) Warm >> "this pizza is warm"
|
||||||
|
Is (These Pizza) Warm >> "these pizzas are warm"
|
||||||
```
|
```
|
||||||
The following section will present
|
It is the **copula**, i.e. the verb //be// that is affected. We can define
|
||||||
``FoodsEng``, assuming the abstract syntax ``Foods``
|
the copula as the operation
|
||||||
that is similar to ``Food`` but also has the
|
```
|
||||||
plural determiners ``These`` and ``Those``.
|
oper copula : Number => Str =
|
||||||
The reader is invited to inspect the way in which agreement works in
|
table {
|
||||||
the formation of sentences.
|
Sg => "is" ;
|
||||||
|
Pl => "are"
|
||||||
|
} ;
|
||||||
%--!
|
```
|
||||||
===English concrete syntax with parameters===
|
The form of the copula depends on the subject of the sentence, i.e. the item
|
||||||
|
that is qualified. This means that an item must have such a number to provide.
|
||||||
The grammar uses both
|
In other words, the linearization of an ``Item`` must provide a number. The
|
||||||
[``Prelude`` ../../lib/prelude/Prelude.gf] and
|
simplest way to guarantee this is by putting a number as a field in
|
||||||
[``MorphoEng`` resource/MorphoEng].
|
the linearization type:
|
||||||
We will later see how to make the grammar even
|
```
|
||||||
more high-level by using a resource grammar library
|
lincat Item = {s : Str ; n : Number} ;
|
||||||
and parametrized modules.
|
```
|
||||||
|
Now we can write precisely the ``Is`` rule that expresses agreement:
|
||||||
|
```
|
||||||
|
lin Is item qual = {s = item.s ++ copula ! item.n ++ qual.s} ;
|
||||||
```
|
```
|
||||||
--# -path=.:resource:prelude
|
|
||||||
|
|
||||||
concrete FoodsEng of Foods = open Prelude, MorphoEng in {
|
===Government===
|
||||||
|
|
||||||
|
Let us turn to ``Item`` subjects and see how they receive their
|
||||||
|
numbers. The two rules
|
||||||
|
```
|
||||||
|
fun This, These : Kind -> Item ;
|
||||||
|
```
|
||||||
|
require different numbers of their ``Kind`` arguments: ``This``
|
||||||
|
requires the singular (//this pizza//) and ``These`` the plural
|
||||||
|
(//these pizzas//). The ``Kind`` is the same in both cases: ``Pizza``.
|
||||||
|
Thus we must require that a ``Kind`` has both singular and plural forms.
|
||||||
|
The simplest way to express this is by using a table:
|
||||||
|
```
|
||||||
|
lincat Kind = {s : Number => Str} ;
|
||||||
|
```
|
||||||
|
The linearization rules for ``This`` and ``These`` can now be written
|
||||||
|
```
|
||||||
|
lin This kind = {
|
||||||
|
s = "this" ++ kind.s ! Sg ;
|
||||||
|
n = Sg
|
||||||
|
} ;
|
||||||
|
|
||||||
|
lin These kind = {
|
||||||
|
s = "these" ++ kind.s ! Pl ;
|
||||||
|
n = Pl
|
||||||
|
} ;
|
||||||
|
```
|
||||||
|
The grammatical relation between the determiner and the noun is similar to
|
||||||
|
agreement, but yet different; it is usually called **government**.
|
||||||
|
Since the same pattern is used four times in the ``FoodsEng`` grammar,
|
||||||
|
we codify it as an operation,
|
||||||
|
```
|
||||||
|
oper det : Str -> Number -> {s : Number => Str} -> {s : Str ; n : Number} =
|
||||||
|
\det,n,kind -> {
|
||||||
|
s = det ++ kind.s ! n ;
|
||||||
|
n = n
|
||||||
|
} ;
|
||||||
|
```
|
||||||
|
In a more linguistically motivated grammar, determiners will be made to a
|
||||||
|
category of their own and have a number.
|
||||||
|
|
||||||
|
|
||||||
|
===Parametric vs. inherent features===
|
||||||
|
|
||||||
|
``Kind``s, as in general common nouns in English, have both singular
|
||||||
|
and plural forms; what form is chosen is determined by the construction
|
||||||
|
in which the noun is used. We say that the number is a
|
||||||
|
**parametric feature** of nouns. In GF, parametric features
|
||||||
|
appear as argument types to tables in linearization types.
|
||||||
|
|
||||||
|
``Item``s, as in general noun phrases functioning as subjects, don't
|
||||||
|
have variation in number. The number is rather an **inherent feature**,
|
||||||
|
which the noun phrase passes to the verb. In GF, inherent features
|
||||||
|
appear as record fields in linearization types.
|
||||||
|
|
||||||
|
A category can have both parametric and inherent features. As we will see
|
||||||
|
in the Italian ``Foods`` grammar, nouns have parametric number and
|
||||||
|
inherent gender:
|
||||||
|
```
|
||||||
|
lincat Kind = {s : Number => Str ; g : Gender} ;
|
||||||
|
```
|
||||||
|
Formally, nothing prevents the same parameter type from appearing both
|
||||||
|
as parametric and inherent feature, or the appearance of several inherent
|
||||||
|
features of the same type, etc. Determining the linearization types
|
||||||
|
of categories is one of the most crucial steps in the design of a GF
|
||||||
|
grammar. Two conditions must be in balance:
|
||||||
|
- existence: what forms are possible to build by morphological and
|
||||||
|
other means?
|
||||||
|
- need: what features are expected via agreement or government?
|
||||||
|
|
||||||
|
|
||||||
|
Grammar books and dictionaries give good advice on existence; for instance,
|
||||||
|
an Italian dictionary has entries such as
|
||||||
|
|
||||||
|
**uomo**, pl. //uomini//, n.m. "man"
|
||||||
|
|
||||||
|
which tells that //uomo// is a masculine noun with the plural form //uomini//.
|
||||||
|
From this alone, or with a couple more examples, we can generalize to the type
|
||||||
|
for all nouns in Italian: they have both singular and plural forms and thus
|
||||||
|
a parametric number, and they have an inherent gender.
|
||||||
|
|
||||||
|
Sometimes the puzzle of making agreement and government work in a grammar has
|
||||||
|
several solutions. For instance, //precedence// in programming languages can
|
||||||
|
be equivalently described by a parametric or an inherent feature (see below).
|
||||||
|
However, in natural language applications using the resource grammar library,
|
||||||
|
all parameters are hidden from the user, who thereby does not need to bother
|
||||||
|
about them.
|
||||||
|
|
||||||
|
|
||||||
|
==An English concrete syntax for Foods with parameters==
|
||||||
|
|
||||||
|
We repeat some of the rules above by showing the entire
|
||||||
|
module ``FoodsEng``, equipped with parameters. The parameters and
|
||||||
|
operations are, for the sake of brevity, included in the same module
|
||||||
|
and not in a separate ``resource``. However, some string operations
|
||||||
|
from the library [``Prelude`` ../../lib/prelude/Prelude.gf]
|
||||||
|
are used.
|
||||||
|
```
|
||||||
|
--# -path=.:prelude
|
||||||
|
|
||||||
|
concrete FoodsEng of Foods = open Prelude in {
|
||||||
|
|
||||||
lincat
|
lincat
|
||||||
S, Quality = SS ;
|
S, Quality = SS ;
|
||||||
@@ -1786,8 +1892,7 @@ concrete FoodsEng of Foods = open Prelude, MorphoEng in {
|
|||||||
Item = {s : Str ; n : Number} ;
|
Item = {s : Str ; n : Number} ;
|
||||||
|
|
||||||
lin
|
lin
|
||||||
Is item quality =
|
Is item quality = ss (item.s ++ copula item.n ++ quality.s) ;
|
||||||
ss (item.s ++ (mkVerb "are" "is").s ! item.n ++ quality.s) ;
|
|
||||||
This = det Sg "this" ;
|
This = det Sg "this" ;
|
||||||
That = det Sg "that" ;
|
That = det Sg "that" ;
|
||||||
These = det Pl "these" ;
|
These = det Pl "these" ;
|
||||||
@@ -1795,7 +1900,8 @@ concrete FoodsEng of Foods = open Prelude, MorphoEng in {
|
|||||||
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
|
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
|
||||||
Wine = regNoun "wine" ;
|
Wine = regNoun "wine" ;
|
||||||
Cheese = regNoun "cheese" ;
|
Cheese = regNoun "cheese" ;
|
||||||
Fish = mkNoun "fish" "fish" ;
|
Fish = noun "fish" "fish" ;
|
||||||
|
Pizza = regNoun "pizza" ;
|
||||||
Very = prefixSS "very" ;
|
Very = prefixSS "very" ;
|
||||||
Fresh = ss "fresh" ;
|
Fresh = ss "fresh" ;
|
||||||
Warm = ss "warm" ;
|
Warm = ss "warm" ;
|
||||||
@@ -1804,13 +1910,29 @@ concrete FoodsEng of Foods = open Prelude, MorphoEng in {
|
|||||||
Delicious = ss "delicious" ;
|
Delicious = ss "delicious" ;
|
||||||
Boring = ss "boring" ;
|
Boring = ss "boring" ;
|
||||||
|
|
||||||
|
param
|
||||||
|
Number = Sg | Pl ;
|
||||||
|
|
||||||
oper
|
oper
|
||||||
det : Number -> Str -> Noun -> {s : Str ; n : Number} =
|
det : Number -> Str -> {s : Number => Str} -> {s : Str ; n : Number} =
|
||||||
\n,d,cn -> {
|
\n,d,cn -> {
|
||||||
s = d ++ cn.s ! n ;
|
s = d ++ cn.s ! n ;
|
||||||
n = n
|
n = n
|
||||||
|
} ;
|
||||||
|
noun : Str -> Str -> {s : Number => Str} =
|
||||||
|
\man,men -> {s = table {
|
||||||
|
Sg => man ;
|
||||||
|
Pl => men
|
||||||
|
}
|
||||||
|
} ;
|
||||||
|
regNoun : Str -> {s : Number => Str} =
|
||||||
|
\car -> noun car (car + "s") ;
|
||||||
|
copula : Number -> Str =
|
||||||
|
\n -> case n of {
|
||||||
|
Sg => "is" ;
|
||||||
|
Pl => "are"
|
||||||
} ;
|
} ;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -1844,6 +1966,10 @@ Thus we could rewrite the above rule
|
|||||||
```
|
```
|
||||||
lin Fish = {s = \\_ => "fish"} ;
|
lin Fish = {s = \\_ => "fish"} ;
|
||||||
```
|
```
|
||||||
|
An example binding a variable was shown in ``FoodEng``:
|
||||||
|
```
|
||||||
|
lin QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
|
||||||
|
```
|
||||||
Finally, the ``case`` expressions common in functional
|
Finally, the ``case`` expressions common in functional
|
||||||
programming languages are syntactic sugar for table selections:
|
programming languages are syntactic sugar for table selections:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
abstract Foods = {
|
abstract Foods = {
|
||||||
|
|
||||||
|
flags startcat=Phr ;
|
||||||
|
|
||||||
cat
|
cat
|
||||||
S ; Item ; Kind ; Quality ;
|
Phr ; Item ; Kind ; Quality ;
|
||||||
|
|
||||||
fun
|
fun
|
||||||
Is : Item -> Quality -> S ;
|
Is : Item -> Quality -> Phr ;
|
||||||
This, That, These, Those : Kind -> Item ;
|
This, That, These, Those : Kind -> Item ;
|
||||||
QKind : Quality -> Kind -> Kind ;
|
QKind : Quality -> Kind -> Kind ;
|
||||||
Wine, Cheese, Fish, Pizza : Kind ;
|
Wine, Cheese, Fish, Pizza : Kind ;
|
||||||
Very : Quality -> Quality ;
|
Very : Quality -> Quality ;
|
||||||
Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ;
|
Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,23 @@
|
|||||||
--# -path=.:resource:prelude
|
--# -path=.:prelude
|
||||||
|
|
||||||
concrete FoodsEng of Foods = open Prelude in {
|
concrete FoodsEng of Foods = open Prelude in {
|
||||||
|
|
||||||
lincat
|
lincat
|
||||||
S, Quality = SS ;
|
Phr, Quality = SS ;
|
||||||
Kind = {s : Number => Str} ;
|
Kind = {s : Number => Str} ;
|
||||||
Item = {s : Str ; n : Number} ;
|
Item = {s : Str ; n : Number} ;
|
||||||
|
|
||||||
lin
|
lin
|
||||||
Is item quality = ss (item.s ++ copula item.n ++ quality.s) ;
|
Is item quality = ss (item.s ++ copula ! item.n ++ quality.s) ;
|
||||||
This = det Sg "this" ;
|
This = det Sg "this" ;
|
||||||
That = det Sg "that" ;
|
That = det Sg "that" ;
|
||||||
These = det Pl "these" ;
|
These = det Pl "these" ;
|
||||||
Those = det Pl "those" ;
|
Those = det Pl "those" ;
|
||||||
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
|
QKind quality kind = {s = \\n => quality.s ++ kind.s ! n} ;
|
||||||
Wine = noun "wine" "wines" ;
|
Wine = regNoun "wine" ;
|
||||||
Cheese = noun "cheese" "cheeses" ;
|
Cheese = regNoun "cheese" ;
|
||||||
Fish = noun "fish" "fish" ;
|
Fish = noun "fish" "fish" ;
|
||||||
Pizza = noun "pizza" "pizzas" ;
|
Pizza = regNoun "pizza" ;
|
||||||
Very = prefixSS "very" ;
|
Very = prefixSS "very" ;
|
||||||
Fresh = ss "fresh" ;
|
Fresh = ss "fresh" ;
|
||||||
Warm = ss "warm" ;
|
Warm = ss "warm" ;
|
||||||
@@ -41,8 +41,10 @@ concrete FoodsEng of Foods = open Prelude in {
|
|||||||
Pl => men
|
Pl => men
|
||||||
}
|
}
|
||||||
} ;
|
} ;
|
||||||
copula : Number -> Str =
|
regNoun : Str -> {s : Number => Str} =
|
||||||
\n -> case n of {
|
\car -> noun car (car + "s") ;
|
||||||
|
copula : Number => Str =
|
||||||
|
table {
|
||||||
Sg => "is" ;
|
Sg => "is" ;
|
||||||
Pl => "are"
|
Pl => "are"
|
||||||
} ;
|
} ;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
--# -path=.:resource:prelude
|
--# -path=.:prelude
|
||||||
|
|
||||||
concrete FoodsIta of Foods = open Prelude in {
|
concrete FoodsIta of Foods = open Prelude in {
|
||||||
|
|
||||||
lincat
|
lincat
|
||||||
S = SS ;
|
Phr = SS ;
|
||||||
Quality = {s : Gender => Number => Str} ;
|
Quality = {s : Gender => Number => Str} ;
|
||||||
Kind = {s : Number => Str ; g : Gender} ;
|
Kind = {s : Number => Str ; g : Gender} ;
|
||||||
Item = {s : Str ; g : Gender ; n : Number} ;
|
Item = {s : Str ; g : Gender ; n : Number} ;
|
||||||
@@ -74,4 +74,3 @@ concrete FoodsIta of Foods = open Prelude in {
|
|||||||
Pl => "sono"
|
Pl => "sono"
|
||||||
} ;
|
} ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user