mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-22 11:19:32 -06:00
started a subdir for the book
This commit is contained in:
33
book/examples/chapter6/Aggregation.gf
Normal file
33
book/examples/chapter6/Aggregation.gf
Normal file
@@ -0,0 +1,33 @@
|
||||
abstract Aggregation = {
|
||||
cat S ; NP ; VP ;
|
||||
data
|
||||
PredVP : NP -> VP -> S ;
|
||||
ConjS : S -> S -> S ;
|
||||
ConjVP : VP -> VP -> VP ;
|
||||
ConjNP : NP -> NP -> NP ;
|
||||
Run, Walk : VP ;
|
||||
John, Mary : NP ;
|
||||
|
||||
fun aggr : S -> S ; -- main aggregation function
|
||||
def aggr (ConjS (PredVP x X) (PredVP y Y)) =
|
||||
ifS (eqNP x y)
|
||||
(PredVP x (ConjVP X Y))
|
||||
(ifS (eqVP X Y)
|
||||
(PredVP (ConjNP x y) X)
|
||||
(ConjS (PredVP x X) (PredVP y Y))) ;
|
||||
fun ifS : Bool -> S -> S -> S ; -- if b then x else y
|
||||
def
|
||||
ifS True x _ = x ;
|
||||
ifS False _ y = y ;
|
||||
fun eqNP : NP -> NP -> Bool ; -- x == y
|
||||
def
|
||||
eqNP John John = True ;
|
||||
eqNP Mary Mary = True ;
|
||||
eqNP _ _ = False ;
|
||||
fun eqVP : VP -> VP -> Bool ; -- X == Y
|
||||
def
|
||||
eqVP Run Run = True ;
|
||||
eqVP Walk Walk = True ;
|
||||
eqVP _ _ = False ;
|
||||
cat Bool ; data True, False : Bool ;
|
||||
}
|
||||
17
book/examples/chapter6/AggregationEng.gf
Normal file
17
book/examples/chapter6/AggregationEng.gf
Normal file
@@ -0,0 +1,17 @@
|
||||
concrete AggregationEng of Aggregation = {
|
||||
|
||||
lincat S, NP, VP = Str ;
|
||||
|
||||
lin
|
||||
PredVP x y = x ++ y ;
|
||||
ConjS a b = a ++ "or" ++ b ;
|
||||
ConjVP a b = a ++ "or" ++ b ;
|
||||
ConjNP a b = a ++ "or" ++ b ;
|
||||
|
||||
Run = "runs" ;
|
||||
Walk = "walks" ;
|
||||
John = "John" ;
|
||||
Mary = "Mary" ;
|
||||
|
||||
}
|
||||
|
||||
50
book/examples/chapter6/Bin.gf
Normal file
50
book/examples/chapter6/Bin.gf
Normal file
@@ -0,0 +1,50 @@
|
||||
abstract Bin = {
|
||||
|
||||
cat Nat ; Bin ; Pos ;
|
||||
|
||||
data
|
||||
Zero : Nat ;
|
||||
Succ : Nat -> Nat ;
|
||||
|
||||
BZero : Bin ; -- 0
|
||||
BPos : Pos -> Bin ; -- p
|
||||
BOne : Pos ; -- 1
|
||||
AZero : Pos -> Pos ; -- p0
|
||||
AOne : Pos -> Pos ; -- p1
|
||||
|
||||
fun
|
||||
bin2nat : Bin -> Nat ;
|
||||
def
|
||||
bin2nat BZero = Zero ;
|
||||
bin2nat (BPos p) = pos2nat p ;
|
||||
fun
|
||||
pos2nat : Pos -> Nat ;
|
||||
def
|
||||
pos2nat BOne = one ;
|
||||
pos2nat (AZero p) = twice (pos2nat p) ;
|
||||
pos2nat (AOne p) = Succ (twice (pos2nat p)) ;
|
||||
fun one : Nat ;
|
||||
def one = Succ Zero ;
|
||||
fun twice : Nat -> Nat ;
|
||||
def
|
||||
twice Zero = Zero ;
|
||||
twice (Succ n) = Succ (Succ (twice n)) ;
|
||||
|
||||
fun
|
||||
nat2bin : Nat -> Bin ;
|
||||
def
|
||||
nat2bin Zero = BZero ;
|
||||
nat2bin (Succ n) = bSucc (nat2bin n) ;
|
||||
fun
|
||||
bSucc : Bin -> Bin ;
|
||||
def
|
||||
bSucc BZero = BPos BOne ;
|
||||
bSucc (BPos p) = BPos (pSucc p) ;
|
||||
fun
|
||||
pSucc : Pos -> Pos ;
|
||||
def
|
||||
pSucc BOne = AZero BOne ;
|
||||
pSucc (AZero p) = AOne p ;
|
||||
pSucc (AOne p) = AZero (pSucc p) ;
|
||||
|
||||
}
|
||||
28
book/examples/chapter6/Classes.gf
Normal file
28
book/examples/chapter6/Classes.gf
Normal file
@@ -0,0 +1,28 @@
|
||||
abstract Classes = {
|
||||
|
||||
flags
|
||||
startcat = Command ;
|
||||
|
||||
cat
|
||||
Command ;
|
||||
Kind ;
|
||||
Class ;
|
||||
Instance Class Kind ;
|
||||
Action Class ;
|
||||
Device Kind ;
|
||||
|
||||
fun
|
||||
Act : (c : Class) -> (k : Kind) -> Instance c k -> Action c -> Device k -> Command ;
|
||||
The : (k : Kind) -> Device k ;
|
||||
|
||||
Light, Fan : Kind ;
|
||||
Switchable, Dimmable : Class ;
|
||||
|
||||
SwitchOn, SwitchOff : Action Switchable ;
|
||||
Dim : Action Dimmable ;
|
||||
|
||||
switchable_Light : Instance Switchable Light ;
|
||||
switchable_Fan : Instance Switchable Fan ;
|
||||
dimmable_Light : Instance Dimmable Light ;
|
||||
|
||||
}
|
||||
29
book/examples/chapter6/ClassesEng.gf
Normal file
29
book/examples/chapter6/ClassesEng.gf
Normal file
@@ -0,0 +1,29 @@
|
||||
--# -path=.:present
|
||||
|
||||
concrete ClassesEng of Classes = open SyntaxEng, ParadigmsEng in {
|
||||
|
||||
lincat
|
||||
Command = Utt ;
|
||||
Kind = CN ;
|
||||
Class = {} ;
|
||||
Instance = {} ;
|
||||
Action = V2 ;
|
||||
Device = NP ;
|
||||
|
||||
lin
|
||||
Act _ _ _ a d = mkUtt (mkImp a d) ;
|
||||
The k = mkNP the_Det k ;
|
||||
|
||||
Light = mkCN (mkN "light") ;
|
||||
Fan = mkCN (mkN "fan") ;
|
||||
Switchable, Dimmable = <> ;
|
||||
|
||||
SwitchOn = mkV2 (mkV "on" (mkV "switch")) ;
|
||||
SwitchOff = mkV2 (mkV "off" (mkV "switch")) ;
|
||||
Dim = mkV2 (mkV "dim") ;
|
||||
|
||||
switchable_Light = <> ;
|
||||
switchable_Fan = <> ;
|
||||
dimmable_Light = <> ;
|
||||
|
||||
}
|
||||
24
book/examples/chapter6/DShopping.gf
Normal file
24
book/examples/chapter6/DShopping.gf
Normal file
@@ -0,0 +1,24 @@
|
||||
abstract DShopping = {
|
||||
flags startcat = Comment ;
|
||||
cat
|
||||
Comment ;
|
||||
Dom ;
|
||||
Item Dom ;
|
||||
Kind Dom ;
|
||||
Quality Dom ;
|
||||
fun
|
||||
DFood, DCloth : Dom ;
|
||||
|
||||
Pred : (d : Dom) -> Item d -> Quality d -> Comment ;
|
||||
This, That : (d : Dom) -> Kind d -> Item d ;
|
||||
Mod : (d : Dom) -> Quality d -> Kind d -> Kind d ;
|
||||
Wine, Cheese, Fish : Kind DFood ;
|
||||
Very : (d : Dom) -> Quality d -> Quality d ;
|
||||
Fresh, Warm, Delicious, Boring : Quality DFood ;
|
||||
|
||||
Shirt, Jacket : Kind DCloth ;
|
||||
Comfortable : Quality DCloth ;
|
||||
|
||||
Italian, Expensive, Elegant : (d : Dom) -> Quality d ;
|
||||
|
||||
}
|
||||
33
book/examples/chapter6/DShoppingEng.gf
Normal file
33
book/examples/chapter6/DShoppingEng.gf
Normal file
@@ -0,0 +1,33 @@
|
||||
--# -path=.:present
|
||||
|
||||
concrete DShoppingEng of DShopping = open SyntaxEng, ParadigmsEng in {
|
||||
|
||||
lincat
|
||||
Comment = Cl ;
|
||||
Item = NP ;
|
||||
Kind = CN ;
|
||||
Quality = AP ;
|
||||
lin
|
||||
Pred _ item quality = mkCl item quality ;
|
||||
This _ kind = mkNP this_QuantSg kind ;
|
||||
That _ kind = mkNP that_QuantSg kind ;
|
||||
Mod _ quality kind = mkCN quality kind ;
|
||||
Very _ quality = mkAP very_AdA quality ;
|
||||
|
||||
Shirt = mkCN (mkN "shirt") ;
|
||||
Jacket = mkCN (mkN "jacket") ;
|
||||
Wine = mkCN (mkN "wine") ;
|
||||
Cheese = mkCN (mkN "cheese") ;
|
||||
Fish = mkCN (mkN "fish" "fish") ;
|
||||
Fresh = mkAP (mkA "fresh") ;
|
||||
Warm = mkAP (mkA "warm") ;
|
||||
Italian _ = mkAP (mkA "Italian") ;
|
||||
Expensive _ = mkAP (mkA "expensive") ;
|
||||
Elegant _ = mkAP (mkA "elegant") ;
|
||||
Delicious = mkAP (mkA "delicious") ;
|
||||
Boring = mkAP (mkA "boring") ;
|
||||
Comfortable = mkAP (mkA "comfortable") ;
|
||||
|
||||
DFood, DCloth = {s = []} ;
|
||||
|
||||
}
|
||||
22
book/examples/chapter6/Nat.gf
Normal file
22
book/examples/chapter6/Nat.gf
Normal file
@@ -0,0 +1,22 @@
|
||||
abstract Nat = {
|
||||
cat
|
||||
Prop ; -- proposition
|
||||
Nat ; -- natural number
|
||||
data
|
||||
Zero : Nat ; -- 0
|
||||
Succ : Nat -> Nat ; -- the successor of x
|
||||
fun
|
||||
Even : Nat -> Prop ; -- x is even
|
||||
And : Prop -> Prop -> Prop ; -- A and B
|
||||
|
||||
fun one : Nat ;
|
||||
def one = Succ Zero ;
|
||||
|
||||
fun twice : Nat -> Nat ;
|
||||
def twice x = plus x x ;
|
||||
|
||||
fun plus : Nat -> Nat -> Nat ;
|
||||
def
|
||||
plus x Zero = x ;
|
||||
plus x (Succ y) = Succ (plus x y) ;
|
||||
}
|
||||
22
book/examples/chapter6/Verbs.gf
Normal file
22
book/examples/chapter6/Verbs.gf
Normal file
@@ -0,0 +1,22 @@
|
||||
abstract Verbs = {
|
||||
|
||||
cat
|
||||
S ; NP ; Subcat ; V Subcat ; Args Subcat ;
|
||||
|
||||
fun
|
||||
cIntr : Subcat ;
|
||||
cTr : Subcat ;
|
||||
cS : Subcat ;
|
||||
|
||||
aIntr : NP -> Args cIntr ;
|
||||
aTr : NP -> NP -> Args cTr ;
|
||||
aS : NP -> S -> Args cS ;
|
||||
|
||||
pred : (s : Subcat) -> V s -> Args s -> S ;
|
||||
|
||||
john, mary : NP ;
|
||||
walk : V cIntr ;
|
||||
love : V cTr ;
|
||||
know : V cS ;
|
||||
|
||||
}
|
||||
22
book/examples/chapter6/VerbsEng.gf
Normal file
22
book/examples/chapter6/VerbsEng.gf
Normal file
@@ -0,0 +1,22 @@
|
||||
concrete VerbsEng of Verbs = {
|
||||
|
||||
lincat
|
||||
S, NP, Subcat, V = Str ; Args = Str * Str ;
|
||||
|
||||
lin
|
||||
cIntr = [] ;
|
||||
cTr = [] ;
|
||||
cS = [] ;
|
||||
|
||||
aIntr su = <su,[]> ;
|
||||
aTr su ob = <su,ob> ;
|
||||
aS su s = <su,"that" ++ s> ;
|
||||
|
||||
pred _ v xs = xs.p1 ++ v ++ xs.p2 ;
|
||||
|
||||
john = "John" ; mary = "Mary" ;
|
||||
walk = "walks" ;
|
||||
love = "loves" ;
|
||||
know = "knows" ;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user