Notes and Exercises to Grammatical FrameworkA Programming Language for Multilingual Grammars and Their Applications by Aarne Ranta September 8, 2010
- When getting errors in every single A, N, or V in grammar, it can be a mismatch of the versions of RGL, wordnet and your grammars. There may be old *.gfo files lying around, even though you'd do make install from the latest gf-rgl. Better to just make everything in my $GF_LIB_PATH and do a fresh install.
- cd into the gf-rgl directory and
git pull
- cd into the gf-wordnet and
git pull
- empty contents in gf_lib_path/
- In gf-rgl:
make install
- In gf-wordnet: if I really want every language, then I can do make install there too, but it is slow. If I only need English, then I do this:
gf --gfo-dir=$GF_LIB_PATH WordNetEng.gf
- << General commands >>
-
i foodsEng.cf or foodsIta.cf or foodsChi.cf
gr
gt
l Pred (This Cheese) Expensive
parse "questo formaggio
e caro"`linearize Pred (This Cheese) Expensive
gr -number=4 | l
gt | l or gt -depth=3 | l
- l Pred (This Cheese) Juicy (NEED TO TWEAK?)
-
i FoodEng.gf FoodIta.gf
p -lang=Ita "quel pesce
e molto caro" | l -lang=Eng`p -lang=Eng "this wine is Italian" | l -lang=Ita
gt -number=4 | l
gr -number=4 | l
linearize Pred (This Cheese) Expensive
gr Pred (This ?) Italian
gr Pred (This ?) Italian | l
gr -number=3 This ?
(-depth=x) is for depth within the bracket
gr -depth=2 -number=2
gt -depth=2 -number=2 Pred (This ?) ?
gt -depth=2 -number=2 Pred (This ?) ?|l
gt -depth=1 Pred ? ?
gt -depth=0 Pred (This (Mod ? ?)) ? | l -treebank
-
after negative predication ex 2.7
gr NPred (This ?) ? | l
-
P60 "it" Pronoun but need an external program to dictate when to use it parse "it is very expensive" after adding to abstract and FoodEng fun Pron : Item -> Item lin Pron r = "it" Choose language by
parse -lang=Eng "it is very expensive"
otherwiseparse "it is very expensive"
-
Ex 2.8 use
ComplexKind
andKind2C
for FoodEng for unambiguous; and FoodsIta Withl Pred (This (Kind2C Cheese)) Expensive
l NPred (This (Kind2C Cheese)) Expensive
gr NPred (This (With ? ?)) Expensive| l
gr NPred (That (With ? ?)) ?| l
parse "this wine with warm cheese is very boring"
gr Pred (This (With Wine (Kind2C (Mod Warm Cheese)))) (Very Boring)| l
gr Pred (This (With ? (Kind2C (Mod ? ?)))) (Very ?)| l
-
Ex 2.6 ticket
gr -number=3 | l -table
to show all the permutation of sentencegr -number=3
-
use a script in terminal outside of gf with
gf < FoodScript.gfs
- << Inflection table, param and oper>>
- Ex 3.1
i -retain BooleanE3.gf
Using i -retain bcos we are using param and opercc ConDisjunct ! True ! True
NB:!
bcos we are using a table so need to select input argumentcc ConDisjunctStr ! True ! True
cc ConDisjuncStrSugarTbl ! True! True
cc ConDisjuncBoolSugarTbl ! False ! True
- Ex 3.2
test inflection table with param and oper
i -retain FoodsEng.gf
thencompute_concrete (regNoun "wine").s ! Pl
compute_concrete (noun "fish" "fish").s ! Pl
cc flynoun "fly"
to see the transformationl -table Wine
gf FoodsEng.gf
- Ex 3.3 DiscontEng.gf need help on ap and wp table -> See comments in DiscontEng and Discont.
- DiscontEng
- Dont need
DeclCW
andQuestClW
bcos nowCompAP
andCompAPW
output a VP which will be arguments forDeclCl
andQuestCl
. - Added
vp.when
toSDecl
andSQuest
forPredVP np vp
- Note the difference between
CompAP
vsCompAPW
regardingwhen
- Dont need
- Discont : Add
Now
,Already
andCompAPW
- Run
gr DeclCl (PredVP John (CompAPW ? ? ))
- DiscontEng
- Cannot
i FoodsIta.gf
even though they are copied from textbook. (Bcos ResIta shows that noun also need a gender. Fixed by addingg = masc
in FoodsIta.gf towine
) - Can we walk thru the oper meaning in ResIta.gf. P90. Dont understand why
(nero,nera,neri,nere : Str) -> Adjective =
can be wildcard since they are used again. (Explanation: ResIta line 24 can be wildcardn1,_,_,n4
or as it is to make it clearer see Function Types with Variable in tutorial but the line 25 should be named.) - desugar of
Very qual
in FoodsIta. correct? (Fixed. need to add another nested table. See extra alternative) - ?Ch 03. other than cc and retain, how can i do "p "these cakes are expensive" or to make use of flyNoun or regNoun opers. (See https://inariksit.github.io/gf/2018/08/28/gf-gotchas.html#:~:text=sense.-,re-export%20rgl%20opers%20in%20application%20grammar,-Here) Solution:
- Run
i -retain ../Chapter03/FoodsEng.gf
thencc -one Pred (These (regNoun "cake with cheese")) (adj "pink")
to get "these cake with cheeses are pink" i -retain FoodsEng.gf
thencc -one Pred (These (flyNoun "candy")) (adj "tasty")
to getthese candies are tasty
- Run
- << Resource Grammar and overload. Prefix and Grammars extension >>
- how should I read ResEng.gf
oper det
. Take 3 arguments and returnThese Fishes
e.g . See the replacement codes and notes. - resEng Mth 1 and Mth 2 correct and concept. (Correct)
- do I need to ensure the same oper name exist for ResEng and ResIta? (Nope dont need. https://inariksit.github.io/gf/2021/02/15/rgl-api-core-extensions.html)
- resEng : what does the
w
andws
inregNoun
stand for. LHS or RHS? . (Explanation:regNoun "boy"
callsmkNoun
function with the arguments.w = "boy"
andws = "boys"
) - With resource FoodsEng, why do I still need a abstract Foods ..comparing agst BooleanE3. (Correct. See Inari rgl-tutorial)
- See
regNounNomGen
forcomplex Noun
in ResEng.gf Should it be 2 or 3 argumentsStr -> Str -> Str -> regNounNomGen
. (Code is now changed and updated. Old is deleted.) - Is my case expression in table for
allVerb
in ResEng.gf correct? if yes, i can get rid of regVerb correct? (Yes.allVerb
is more comprehensive than theregVerb
so keepallVerb
, ridregVerb
) - UmlautE4 syntax error (corrected. Use this instead of gf tutorial one. remove "in umlaut at end... and param" dont need since the string are not called again like in ResEng into other functions. Run command
i -retain UmlautE4.gf
and thencc umlautGalore "boy"
) - OverloadEng - need to take care of all 5 scenarios in
irregVerb
forPresentPl
altho no modification egsing -> sing
since "inworstCaseVerb sings sing singing sang sung ;
" last line has 5 arguments. (Code is updated. Note thatPresentPl
is taken care of/ passed along inworstCaseVerb
. AllPresentSg
andContinous
is taken care of inirregVerb
.i -retain OverloadEng.gf
andcc -trace regVerb "walk"
and 5 argu forworstCaseVerb
) - OverloadEng - syntax error (solved)
- Commands to run to get dependency graph to show module structures
1.
i -retain Shopping.gf
2.dependency_graph
<< or use dg for abbreviation >> 3.! dot -Tpng _gfdepgraph.dot >diamond.png
- more question : p108 4.14
prefix
oper in OverloadEng pre { } why the yellow syntax colour comes on is bcos pre { } is missing type with case pre of etc. (Solved and can load anywhere. Mistaken as Haskell file) - Notes: p109 Tokens can be created in the following ways:
1. quoted string; "foo"
2. gluing: t + s
3. predefiined operations:
init
,tail
,tk
,dp
4. pattern matching over strings:"y" => "ies"
5. prefix-dependent choices: pre { ..} - prefix.gf to discuss Meng question. (Done. need a table of cases)
- << Resource Grammar Library >>
- Read again of the Resource Grammar Library at S5.4 p115, 116 for notes.
-
- ? Should FoodsRGLEng be linked with Ch04 ResEng.gf. (Ans: After all the hardwork to create ResEng.gf. Use
--# -path=../Chapter04/
at top line in FoodsRGLEng.gf) - Ex 5-0 + Ex 5-1 Commands to run
gr
gr Pred ? ? |l
gr That ? |l
gr Mod ? ?
gr Mod
gt | l -treebank
- ? Should FoodsRGLEng be linked with Ch04 ResEng.gf. (Ans: After all the hardwork to create ResEng.gf. Use
- Ex 5-2 FoodsRIta.gf concrete but without flag startcat? (Yes flag startcat is only in abstract files). Run command after import
gr | l -treebank
to see both linearized gr and treebank of a gr. - Ex 5-3 Commands to test Foods grammar with syntax, lexicon and concrete
gf FoodsIChi.gf FoodsIEng.gf FoodsIFin.gf FoodsIGer.gf FoodsIIta.gf
:gr | l -treebank
gt Pred (This Fish) ?
gt Pred ? Delicious
-
- Q Ex 5-4 is it asking me to do the different LexFoodsLangs and FoodsILangs?
- Q Ex 5-5: Not generalizing FoodsI properly for italian pie. Need oper?
- Ex 5-6: linking ok but what commands to test?
- Q Ex 5-7 word alignment test with
p "this Italian wine is very expensive" | aw
- p133-135 good case examples of categories in API e.g Det, CN, VP types.
- Parsing sentences using
import alltenses/LangEng.gfo
and testing the resource API functions with moduleTryL
(-- a union of SyntaxL, LexiconL and ParadigmsL)- Ex 5-8 Commands to run in terminal after gf:
import alltenses/LangEng.gfo (then p "is this wine good"
. see table below)p "is this wine good" | tt
for a tree like formi -retain alltenses/TryEng.gfo
cc -all mkUtt (mkCl this_NP (mkA "cool"))
- ? with the parsed tokens, can we do
cc -all (PhrUtt NoPConj........)
(In theory yes but there is a bug plus "cool" is not in the lexicon. If there was no bug, e.g Dutch, do justl ....
bcos it hasfun/lin
. Solutioni alltenses/LangEng.gfo
andp "this is good"
and finallyl PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetNP (DetQuant this_Quant NumSg)) (UseComp (CompAP (PositA good_A)))))) NoVoc
)
- Ex 5-8 Commands to run in terminal after gf:
parsed phrase with | parsers | |
---|---|---|
1 | p "this wine is good" | PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetCN (DetQuant this_Quant NumSg) (UseN wine_N)) (UseComp (CompAP (PositA good_A)))))) NoVoc |
2 | p "is this wine good" | PhrUtt NoPConj (UttQS (UseQCl (TTAnt TPres ASimul) PPos (QuestCl (PredVP (DetCN (DetQuant this_Quant NumSg) (UseN wine_N)) (UseComp (CompAP (PositA good_A))))))) NoVoc |
3 | p "he says that this wine is good" | PhrUtt NoPConj (UttS (UseCl (TTAnt TPres ASimul) PPos (PredVP (UsePron he_Pron) (ComplVS say_VS (UseCl (TTAnt TPres ASimul) PPos (PredVP (DetCN (DetQuant this_Quant NumSg) (UseN wine_N)) (UseComp (CompAP (PositA good_A))))))))) NoVoc |
- Ex 5-10. See functor exercise solution
- << outdated >>
- ? Ex 6-1 -- error msg "no overload instance of ConstructorsEng.mkCl" (Chapter 6 can be skipped as outdated similar to the Chapter 5 + 6 in tutorial. Attempted and discussed at stackoverflow)
- << Embeddedd grammar in applications >>
- ? Translator: Copied Foods.gf, FoodsEng.gf, FoodsIta.gf from Chapter03
1.
ghc --make -o trans Translator.hs
2.gf -make FoodEng.gf FoodIta.gf
- Query yes no. Application consists of the following:
files | purpose |
---|---|
Makefile (Query.hs) | a makefile |
Query.gf | abstract syntax |
Query???.gf | concrete syntaxes for each language |
Answer.hs | the question-to-answer function |
QuerySystem.hs (Main.hs) | Haskell Main module |
.cabal | update main-is & other-modules in hs |
stack.yaml | to enable stack work |
- continue
- ? Cannot import QuerySystems.hs (renamed Main.hs) properly. (Due to not having global installation of pgf libraries so use a stack build to overcome. See below for steps)
- With Main.hs, Query.gf, Answer.hs in directory from book, type in terminal
gf -make -f haskell Query.gf
to generate a Query.hs - copy both cabal and yaml. Use
wget https://raw.githubusercontent.com/1Regina/GrammaticalFramework_tutorial/master/gf-embedded-grammars-tutorial/stack.yaml
in terminal to copy a file of the same contents and tweak its contents for name and module. To get the url, click raw on github. stack build
- make a concrete QueryEng.gf and note that number can use the library for integer string with
Number int = int.s ;
in line 11. gf -make QueryEng.gf
stack run
- Questions time after stack run by
is 2 prime?
- Whenever QueryEng.gf is edited, do
gf -make QueryEng.gf
again to update the QueryEng.gfo, then dostack run
, then do questionsis 2 prime?
- With Main.hs, Query.gf, Answer.hs in directory from book, type in terminal
- ? Cannot import QuerySystems.hs (renamed Main.hs) properly. (Due to not having global installation of pgf libraries so use a stack build to overcome. See below for steps)
- << Arithmetic and Interface for formal and natural language. Calculator and Unix commands >>
-
?
p "2 + 3 * 4"
andp -cat=Exp "2 + 3 * 4"
did not return parser altho linking ok for Calculator.gf (Need a concrete. With abstract, I can only do gt and gr.import CalculatorC.gf
instead and dop "2 + 3 * 4"
,put_string -lexcode "2 + 3 * 4"
andput_string -lexcode "2 + 3 * 4"|p
). -
CalculatorC.gf
- ? Ex 8-0
infixl
,p = Type Prec
,f = Type Str
,x, y = Type TermPrec
andEPlus ... EInt = Type Str
. (See Prelude Formal to understand how they work) - ? Ex 8-0 Dont we need to know whats
nextPrec
andlessPrec
(See Prelude Formal) - ? Ex 8-1 done with
parenthOpt
(See Prelude Formal) - ? Ex 8-1 with Book Section 6.10
def
in CalculatorC line 27 andParenthOpt
in Calculator but cant test with and without a pipe topt -compute
can try Ch06 P156parse -tr "1 + 1" | put_tree -compute -tr | linearize
(Deprecated compute with pipe in gf alr)
p "foo" | pt -compute -- deprecated pt -compute Foo (Bar (Baz)) -- still in use
- ? Ex 8-0
-
CalculatorEng.gf: Ex 8-2 natural language calculator at Chapter08/CalculatorNumeral/CalculatorEng.gf Read more from about the import NumeralEng and Abstract Numeral
-
? Ex 8-2 Should these be added to Calculator.gf from p194 (Ignore and see next point) Section 8-3 Programs with variables
cat Prog, Var ; fun PEmpty : Prog ; PInit : Exp -> (Var -> Prog) -> Prog ; PAss : Var -> Exp -> Prog -> Prog ; EVar : Var -> Exp ;
-
Working with natural english: cd to Chapter08/CalculatorNumeral to
- Open Module and extend in CalculatorEng.gf
NumeralEng
- Since sum, difference, product are always "integer and integer", we can have a template
oper arith op e1 e2
- Create a unique oper for divide as it is of "integer by integer",
oper divide op_Div e1 e2
. - Statements will be "the sum of e1 and e2" and "the division of e1 by e2" .
- Run these commands to try
p "the sum of two and ten"
gr EDiv ? ? | l
gr | l -treebank
p "ten thousand" | l -treebank
gr EPlus ? ? | l -treebank
- Note the
lin type Numeral -> Exp for EInt numeral = mkNP (mkDet numeral) ; -- mkNP and mkDet from SyntaxEng
-
To work with digits AND natural english: Chapter08/CalculatorDigitNumeral:
open SymbolicEng
and also change
l lin EInt numberal
- Note that CalculatorJ is not relevant.
- Add in CalculatorEng.gf
SymbolicEng instead and lin type Int -> Exp for EInt numeral = symb numeral ; -- Symbolic module, symb : Int -> NP
- Commands:
gf CalculatorC.gf CalculatorEng.gf
gr | l -treebank
p -lang=C "9 * ( 12 - 79 )"
p -lang=C "9 * ( 12 - 79 )" | l -treebank
p -lang=Eng "the sum of 2 and 10"
p -lang=Eng "the division of 2 by 10"
p -lang=Eng "the division of 2 by 10" |l -treebank
- Run
i -retain CalculatorEng.gf
andcc arith sum_N
- Visualise tree is same gf shell
- p "the sum of 12 and 24" | vt | wf -file="mydemo.dot”
- ! dot -Tpng mydemo.dot > mydemo.png | method 2: go to another shell outside gf and
dot -Tpng mydemo.dot > mydemo.png
- ! code mydemo.png | method 2 continue:
code mydemo.png
-
-
? E8-10 Chapter08/UnixCommand
lin directory path
has type error Str vs {s: Str}. How to provide for a string to be whatever is the input like IO -> StdOut? ({s: Str} is a record and note that Str and string are not the same. To get it interactive, use String literals. See unix.gf fun dir under Paths. String, Float and Int are literals cats hidden under the hood. and they have limited generation see String literals-
credit: Maryam
grep, ls , pipe portion
-
I added dir and homedir and cd
-
l cd homedir
returnschange directory to home directory
-
home directory:
l cd homedir | p
returnscd homedir
-
other directory
p "change directory to somedirectory"
returnscd (dir "somedirectory")
-
note
cd (dir "some other directory")
returnscommand not found: cd
bcos of spacing butl cd (dir "some other directory")
can returnschange directory to some other directory
-
l cd (dir "some other directory")|p
also fail bcos of spaces in the s ofdir s
. The only word with space allowable is "home directory", hencel cd (dir "home directory")|p
returncd homedir
. -
Use SS for records in cases where expecting > 1 field for the record e.g {s : Str ; g ; Gender} ie more than just strings. { s = path.s} is also for record in e.g UnixE.gf concrete
lincat Path, Command = SS
-
The definitions SS (a type) and ss from Prelude
SS : Type = {s : Str} ; ss : Str -> SS (as in dir of Unix.gf) Foo : Type = {s : Str ; g ; Gender} ; == Foo : Type = SS ** {g ; Gender} ; getStr : SS -> Str = \ss -> ss.s ;
-
-
p213 Fig 68. variable (is for lhs of equation) and agreement.
-
9.6 Determinants p217. lost with the case and agreement part below fig 76. pls walk me over the lin and lincat esp
lin DetCN det cn = {s = \\c => det.s ! cn.g ! c ++ cn.s ! det.n ! c ;.....
-
? Compare 9.7 modication has
lincat ap.s and cn.s
per the argument, similar to 9.4 Predication and 9.5 Complementation vs 9.5 P216 EXTRA ++. (See comments with -- . Reorganised the features in obvious format.)9.4 p214 lin PredVP np vp ={s = \\t => np.s ! nom ++ vp.s ! t ! np.a} 9.5 p215-216 lin ComplV2 v np = {s = \\t,a => v.s ! t ! a ++ np.s ! v.c} 9.7 p218 lincat AP = {s : Gender => Number => Case => Str } CN = {s : Number => Case => Str ; g : Gender } ; lin -- 3 equivalents -- AdjCN ap cn = {s = \\n,c => cn.s ! n ! c ; g=cn.g} ; --- simplest implementation of cn fn by ignoring the ap part -- AdjCn ap cn = {s = cn.s ; g=cn.g} ; --- simplest implementation of cn fn by ignoring the ap part -- AdjCn ap cn = cn ; --- simplest implementation of cn fn by ignoring the ap part -- note that n! c! order depends on inflexion order in the lincat of AP and CN AdjCN ap cn = {s = \\n,c => ap.s ! cn.g ! n ! c -- the string we choose from AP. Gender of cn will determine the ap.s to choose. ++ cn.s ! n ! c ; -- the string we choose from CN g = cn.g} 9.5 p216 EXTRA ++ lincat V2 ={s : Tense => Agr => Str ; c : Case ; prep : Str} lin ComplV2 v2 vp ={s = \\t,a => v2.s ! t ! a ++ v2.prep ++ np.s ! v2.c}
-
? 9.11 p222 Modiciation and Determination using
oper preOrPost for AdjCN
in Prelude forisPre
feature. (See -- comment comparison and alternative 1 & 2)oper preOrPost : Bool -> Str -> Str = \p,a,b -> case p of { True => a ++ b ; False => b ++ a } lin AdjCN cn ap = { s = \\n => preOrPost ap.isPre (ap.s ! cn.g ! n) (cn.s ! n) ; -- compare with 9.7 above. Similar. g = cn.g } -- in line version of the above without the oper preOrPost (Alternative 1) lin AdjCN cn ap = { s = \\n => case ap.isPre of { True => (ap.s ! cn.g ! n ) ++ (cn.s ! n ) ; False => (cn.s ! n ) ++ ( ap.s ! cn.g ! n ) } ; g = cn.g } -- in line version of the above without the oper preOrPost (Alternative 2) lin AdjCN cn ap = case ap.isPre of { True => {s = \\n => (ap.s ! cn.g ! n ) ++ (cn.s ! n ) ; g = cn.g }; -- think of nesting + inherent feature False => {s = \\n => (cn.s ! n ) ++ ( ap.s ! cn.g ! n ) ; g = cn.g }; -- think of nesting + inherent feature } ; Note: 1. `!` means choose. e.g cn.g!number means need to decide if singular or plural bcos number is the variable as `number =>` would have been on the left hand side. So the inflexion table would have a singular n a plural "option" for this cn.g 2. whereas the `.g` in `cn.g` means gender inherent in the `cn`
- Ex 10.1 Using Food and FoodEng from Chapter 2, undo 2.8 unambigous Kind2C and ComplexKind and recreate, to get 2 trees, do:
-
to get 2 trees
p "this fish with cheese with wine is Italian" Pred (This (With Fish (With Cheese Wine))) Italian Pred (This (With (With Fish Cheese) Wine)) Italian
-
to utilise "it"
l NPred (Pron (That Fish)) Warm it isn't warm
NPred (Pron ?1) Warm it isn't warm
-
? Food1treeEng.gf: How to incorp NPred for item ++ "isn't" ++ quality. (See different tense forms with
mkS (anteriorAnt) (negativePol)
)NPredPast item quality = mkUtt (mkS (pastTense) (anteriorAnt) (negativePol) (mkCl (item) (quality))); NPredPresentParticiple item quality = mkUtt (mkS (anteriorAnt) (negativePol) (mkCl (item) (quality))); NPredPresent item quality = mkUtt (mkS (negativePol) (mkCl (item) (quality)));
-
? syntax error upon importing (fixed. See notes at bottom)
-
Test after import
Food> p "it hasn't been boring" NPredPresentParticiple (Pron ?1) Boring Food> gr NPredPresentParticiple (Pron ?1) ? | l -treebank Food: NPredPresentParticiple (Pron (That Fish)) Expensive Food1treeEng: it hasn't been expensive Food> gr NPredPresent (This (Mod Italian Fish)) (Very Italian) | l this Italian fish isn't very Italian
-
? Food1treeEng.gf cant import after adding disambiguous with kind complexKind. Aim to be able to
p "this delicious fish with cheese is expensive"
ERROR is ** Maybe you gave too many arguments to with_Prep + syntax error. Should i do --2.8 unambiguous" way or the bottom oper way (Fixed for 2.8 unambiguous (Method a) without oper with_ by Abstract This, That, With & Kind2C and Concrete lincat ComplexKind, lin With kind complexKind, oper Kind2C kind and (Method b) Abstract This, That, With & Kind2C and Concrete lincat ComplexKind, lin With = with_ , Kind2C kind using oper with_ ) -
?Ch 03. other than cc and retain, how can i do "p "these cakes are expensive" or to make use of fly. (See https://inariksit.github.io/gf/2018/08/28/gf-gotchas.html#:~:text=sense.-,re-export%20rgl%20opers%20in%20application%20grammar,-Here) Solution:
- Run
i -retain ../Chapter03/FoodsEng.gf
thencc -one Pred (These (regNoun "cake with cheese")) (adj "pink")
to get "these cake with cheeses are pink" i -retain FoodsEng.gf
thencc -one Pred (These (flyNoun "candy")) (adj "tasty")
to getthese candies are tasty
- Run
-
- A.2 ResIta
- ? p250
param Agr = Ag Gender Number Person ;
where is thatAg
coming/lifted from? (It is just a type constructor) NB Agreement is a constituent form that is dependent on other constituents. p259 an inherent feature of one constituent determines a variable feature of another one, e.g.lin Pred np vp = np.s ++ vp.s ! np.n
.(e.g the cats sleep vs the cat sleeps) - ?
=>
for inherent features and case expression? (=>
is for table and case expressions)- p252
oper adjDet : Adj -> Number -> {s : Gender => Case => Str ; n : Number} = ...
: isnt=>
for case expression as inregVerb
above? How/when are=>
normally used.- Ans: (for table and case:
=>
can be used inside or outside a record. For outside then inside .g GFSS reflPron : Agr => Str = table { P1 Sg => "myself" ; P1 PL = "ourselves"};)
- Ans: (for table and case:
- ? p268 and for inherent features
oper regA : Str -> {s : Gender => Number => Str} = ...
- Ans: ( In regA : Str -> {s : Gender => Number => Str} =.. , it would be first the gender table and next the number table determines the Str)
param Gender = Masc | Fem ; oper regA : Str -> {s : Gender => Number => Str} = \fin -> {s = table { Masc => table { Sg => fin ; Pl => fin + "s" } ; Fem => table { Sg => fin + "e" ; Pl => fin + "es" } }} ;
- p252
- ? p257 interface Syntax
oper ... overload
allow for multiple trees for each parser likemkS
,mkCl
. (Yes the overload creates the different paths for creating the opers e.g. 3 for mkS and 5 for mkCl)
- ? p250
- Read them!
-
C2.1 : Read this section P267-268 to know:
-
lincat
-
linearization with lin definition
-
param
-
fun (to give a lin) and cat (to give a lincat)
-
inheritance/ extension
-
resource module with its oper constituting params
-
opening module with
open MorphoFre in {...}
vs qualified via prefix.
e.g. A.a -
interface e.g Lexicon {oper(s)} vs instance e.g. LexiconEng of Lexicon = { oper "more granular"}
-
functors = parametrized modules = incomplete modules for concrete syntax via interface:
incomplete concrete AdjI of Adj = open Lexicon in {lincat..lin..}
- instantiate by providing instances
concrete AdjEng of Adj = AdjI with(Lexicon = LexiconEng) ;
- Also from C2.10 Functor instantiated:
concrete FoodsEng of Foods = CommentsEng ** FoodsI-[Pizza] with (Syntax = SyntaxEng), (LexFoods = LexFoodsEng) open SyntaxEng, ParadigmsEng in { lin Pizza = mkCN (mkA "Italian") (mkN "pie") ; }
-
-
? C2.1: to confirm Branching order with muliple fetures:
oper regA : Str -> {s : Gender => Number => Str} =\fin -> {s = table { Masc => table {Sg => fin ; Pl => fin + "s"} ; Fem => table {Sg => fin + "e" ; Pl => fin + "es"} }} ; (Ans: 1st decide the gender then 2nd the Sg / Pl )
-
C2.5: Modules and their extends and opens types
module type | extends | opens | body |
---|---|---|---|
abstract | abstract | - | cat, fun, def, data |
concrete of abstr | concrete | resource* | lin*, oper, param |
resource | resource* | resource* | oper, param |
interface | resource+ | resource* | oper, param |
instance of interf | resource* | resource* | oper, param |
incomplete concrete | concrete+ | resource+ | lin*, oper, param |
- resource* : resource, instance, concrete
- resource+ : resource*, interface, abstract
- concrete+ : concrete, incomplete concrete
- lin* : lin, lincat, lindef, printname cat, printname fun
-
C2.7: Inheritance: inherits a, b, c from M1, and all names but d from M2
N = M1 [a,b,c], M2-[d]
-
C2.10: Completeness requirement across the different modules, interface , instances etc.
- Interface need not be complete.
- Instance can complete the interface!
interface Pos = { param Case ; -- no definition param Number = Sg | Pl ; -- definition given oper Noun : Type = { -- relative definition given s : Number => Case => Str } ; oper regNoun : Str -> Noun ; -- no definition } instance PosEng of Pos = { param Case = Nom | Gen ; -- definition of Case -- Number and Noun inherited oper regNoun = \dog -> { -- type of regNoun inherited s = table { -- definition of regNoun Sg => table { Nom => dog -- etc } } ; oper house_N : Noun = -- new definition regNoun "house" ; }
-
? C3.1 What are flags? (flags are commonly included in grammars:
- coding - defining the character encoding of Unicode string literals (in any module containing string literals)
- startcat - define the default target category of parsing (in an abstract module))
-
? C3.6 We dont really use data constructor declaration correct? Data f: A -> A1 -> A2
-
? C3.7 Abstract syntax that we have always been using is primitive/constructor/defined?
-
C4.2 Table of precedences of GF expressions -- See and compare
-
? C4.4 Conversion : had not seen them in my gf exercises so far. How to read the down arrow
-
C4.9 : String literals. Expressions of type Str have the following canonical forms:
- tokens, i.e. string literals, in double quotes, e.g."foo"
- the empty token list,[]
- concatenation,s++t, where s, t: Str
- prefix-dependent choice, pre { p1 => s1; . . . ; pn => sn ; _ =>s }, where
- s1, . . . , sn, s: Str
- p1, . . . , pn are patterns of type Str
#gluing: there are no empty tokens, but the expression[]can be usedin a context requiring a token, in particular in gluing expression: s + t, where s, t: Str "foo" + "bar" ⇓ "foobar" t + [] ⇓ t [] + t ⇓ t e.g: "one two three" ≡≡ "one" ++ "two" ++ "three"
-
C4.9 Gluing = concatenation
s + (t + u) ⇓ s + t + u s ++ (t ++ u) ⇓ s ++ t ++ u
-
C4.9 prefix dependency
pre {"a" | "e" | "i" | "o" => "an" ; _ => "a"}
then gluingpre{p1 => s1; . . . ; pn => sn; => s} ++ t ⇓
. See Chapter 4 prefix. -
C4.10 records:
- Record form :
{r1 : A1;. . .; rn : An}
- Record to denote combo of its features:
{r1 = a1;. . .; rn = an}
- The fields of a record are of the form
r = a
, also called value assignments. Value assignments may optionally indicate the type, as inr : A = a
. - Order of fields is unimpt so long as values assignments are all type-correct.
- Label
ss : Str -> {s : Str} = \s -> {s = s} ;
- Projection
t.r
where t must be a record and r must be a label defined in it. The computation rule for projection returns the value assigned to that field:{. . .; r = a;. . .}.r ⇓ a
- Record extension with R ** S produces a record with union of fields of R and S. It requires:
- both R and S are either records or record types
- the labels in R and S are distinct.
- Record form :
-
C4.11 Subtyping and Lock Fields being hidden fields in compiler that we don't see.
A is a subtype of B means that a : A implies a : B.covariance: if A is a subtype of B, then C -> A is a subtype of C -> B.contravariance: if A is a subtype of B, then B -> C is a subtype of A -> Ctransitive: if A is a subtype of B and B is a subtype of C, then A is a subtype of C.- Example with Andreas: A is a subtype of B written as
A <: B
if A can be converted to B ie. this means you can upcast: A -> B. Another way to look at it is A is more narrowly-defined than B + has more than all the properties of B
A = {a , b ,c} -- where A is defined by properties a , b and c B = { a, c} This means we can upcast {a, b, c} = {a, c}
- On the other hand, A' is NOT a subtype of B' as B' has more properties than A' eg the
d
.
A' = { a, b, c} B' = { a, c, d}
- subtype relations hold between Det ⁇ Idet and NP ⁇ IP (other than =)?
lin -- : Det -> CN -> NP -- the songs DetCN det cn = {- actual implementation here -} ; -- : IDet -> CN -> IP ; -- which five songs IdetCN = DetCN ;
We can give an Idet as an argument to DetCN, which expects a Det. Thus Idet has to have more fields than Det. We can return an NP as the result of IdetCN, which expects to return an IP. Thus NP has to have more fields than IP. Here we have the answer: IDet <: Det (ie. IDet is a subType of Det) and NP <: IP (ie. NP is a subtype of IP).
-
C4.12 Tables aka finite functions because could finitely enumerate all argument-value pairs.
- V1,. . . ,Vn is the complete list of the parameter values of the argument type P, and each ti is an expression of the value type T.
table { V1 => t1; . . . ;Vn => tn}
- Support patterns matching where p1,. . . .,pm is a list of patterns that covers all values of type P. Each pattern pi may bind some variables, on which the expression ti may depend.
table{p1=> t1; . . . ;pm => tm}
- Selection operator
!
, applied to a table t and to an expression v of its argument typet!v
returns the first pattern matching result from t with v. - Case expression syntactic sugar below. Note type of e can be not just Str, but also a record (or a tuple) with Str and parameter type components.
case e of {. . .} ≡≡ table {. . .} ! e
- V1,. . . ,Vn is the complete list of the parameter values of the argument type P, and each ti is an expression of the value type T.
-
C4.13 Pattern matching p295 for
-
types:
- Integer and Str
- Str
- Ints n
-
record pattern matching can use partial records:
{g = Fem} => t in a table of type {g : Gender ; n : Number} => T means the same as {g = Fem ; n = _} => t
-
Pattern macros = opers of type patternT with operator #. Using #as a switch.
oper vowel : pattern Str = #("a" | "e" | "i" | "o")
pre {#vowel => "an" ;_ => "a"} #as a switch
-
-
C4.15 Local Definition. See "piece_of_cake" in Calculator CalculatorEng.gf. Compression of several local definitions:
-
let x : T = t ; y : U = u in e is the same as let x : T = t in let y : U = u in e
-
-
C4.17 Reusing grammars as resources:
- if
t : T then lin C t : lincat C T
The typelincat C T
is a subtype of T, which makes the above translation of lin judgements type-correct. - The constructs lincat C T and lin C t are implemented internally by using lock fields, which are record labels of form lock C of the dummy type {} added to the record type T. By using the lin C construct,lock fields can, and should, be avoided altogether in the source code.
- if
-
C4.18 Predefined concrete syntax types:
- Types:
- Str, the type of tokens and token lists (defined in Section C.4.9)
- Integer, the type of nonnegative integers
- Ints n, the type of integers from 0 to n
- Type, the type of (concrete syntax) types -- user-written
- PType, the type of parameter types -- user-written for param
- Str and Integer (Concrete Syntax Types) vs String and Int (Abstract Syntax Categories/Types)
- Types:
-
C5.2 Compiler pragmas to search through file
- search through the current directory (.) and the directories present and /home/aarne/GF/tmp, in this order.
--# -path=.:present:/home/aarne/GF/tmp
- $(GFLIBPATH)/DIR is searched. The default path list is .:prelude, and the directory prelude is automatically included in all path lists.
-
C6.1 Literals - Double precision float literals: 〈digit〉+‘.’〈digit〉+ (‘e’‘-’?〈digit〉+)? i.e. two sequences of digits separated by a decimal point, optionally followed by an unsigned or negative exponent
- D.1 Catgegory System
Category | Explanation | Example (default) |
---|---|---|
Ant | anteriority. | simultaneous, anterior. |
CAdv | comparative adverb | more |
CN. | common noun (without determiner) | red house |
Card | cardinal number | seven |
Cl | declarative clause, with all tenses | she looks at this |
ClSlash | clause missing noun phrase | she looks at |
Comp | complement of copula, such asAP | very warm |
Conj | conjunction | and |
Det. | determiner phrase | those seven |
Digits. | cardinal or ordinal in digits | 1,000/1,000th |
IAdv | interrogative adverb | why |
IComp | interrogative complement of copula | where |
IDet. | interrogative determiner | how many |
IP | interrogative pronoun | who |
Imp. | imperative | look at this |
NP. | noun phrase (subject or object) | the red house |
Num | number determining element. | seven, singular, plural |
Numeral | cardinal or ordinal in words | five/fifth |
Ord. | ordinal number (used inDet) | seventh |
PConj | phrase-beginning conjunction | therefore, no pconj |
Phr | phrase in a text | but be quiet please |
Pol | polarity | positive, negative |
Predet | predeterminer (prefixedQuant) | all |
Prep. | preposition, or just case | in |
Pron. | personal pronoun | she |
QCl | question clause, with all tenses. | why does she walk |
QS | question | where did she live |
Quant. | quantifier (’nucleus’ of Det). | this/these |
RCl. | relative clause, with all tenses. | in which she lives |
RP | relative pronounin | which |
RS | relative sentence | in which she lived |
S | declarative sentence | she looked at him. |
SC | embedded sentence or question. | that it rains |
SSlash | sentence missing noun phrase. | she looked at |
Subj. | subjunction | if |
Temp | temporal and aspectual features | past anterior |
Tense. | tense | present, past, future |
Text | text consisting of several phrases. | He is here. Why? |
Utt. | utterance: sentence, question. . . | be quiet |
VPverb | phrase | is very warm |
VPSlash. | verb phrase missing noun phrase | look at |
Voc | vocative | my darling, no voc |
[C] | list of categoryC=Adv,AP,NP,RS,S. | X, Y, Z |
<< Syntax Trees>> 2. D2.3 Clause level predication and complementation on combo of uses of Cl, VP, Comp, SC. 3. D2.4 Extraction: SSlash, ClSlash, VPSlash combo: e.g mkVPSlash ( VV VPSlash ) for "want to use (it)" 4. D2.5 Question and relative clause formation . QCl and RCl 5. D2.6 Interrogative and relative pronouns for IP, IDet, IAdv, IComp (e.g where or who (is it)), RP 6. D2.7 Noun phrases and determiners for NP, Det, Quant, Num, Card, Ord 7. D2.8 Numbers and values 8. D2.9 Common noun, adjective and adverbs : CN, AP, AdN, AdA, Adv 9. D2.10 Coordination joining for C = Adv, AP, NP, RS, S 1. Conj [C] gives X, Y and Z 2. C C gives Y, Z 3. C [C] gives X, Y, Z
- D3 Lexical Paradigms
- Functions and their types
- For regular words, P315 it is just Str -> Type e.g mkN : Str -> N; mkV : Str -> V etc
- For subcategories P316 there are:
- mkV2 : V -> V2
- mkV2 : V -> Prep -> V2
- mkV3 : V -> V3
- mkV3 : V -> Prep -> Prep -> V3
- mkVQ : V -> VQ
- mkV2Q: V -> Prep -> V2Q
- mkN2 : N -> Prep -> N2
- mkN3 : N -> Prep -> Prep -> N3
- ..etc more on p316
- Functions and their types
- D4 Prelude module for common utilies functions like SS, ss, andB, init, if ..then..else, Bool, optStr
Oper | Type | Explanation |
---|---|---|
SS | Type | the type{s : Str} |
ss. | Str -> SS | record from string |
nonExist. | Str | missing form |
optStr | Str -> Str | optional string |
bothWays. | (x,y : Str) ->Str. | either x ++ y or y ++ x |
Bool | PType values | True and False |
andB. | (,: Bool) -> Bool | conjunction. |
orB. | (,: Bool) -> Bool | disjunction |
notB | Bool ->Bool | negation |
if then else | (A:Type) -> Bool -> A -> A ->A | conditional. |
init | Str -> Str | drop last character |
last | Str -> Str | return last character |
glue | Str -> Str -> Str | glue tokens together. |
- D4.2 Formal module for maths precedence, parentheses for subexpressions infixl , usePrec, Prec
- D4.3 Symbolic module for functions to change symbols to natural language
- mksymb : Str -> Symb e.g x
- symb : Str -> NP e.g x
- symb : Int -> NP e.g 23
- symb : Det -> N+ -> Numeral -> NP the level four
- symb : Symb -> Card n(number)
- ..etc more on p317
- D4.4 Combinator comule for predicates and function expressions regardless of resource languages.
- pred : A -> NP -> NP -> Cl e.g x and y are equal
- pred : A2 -> NP -> NP -> Cl e.g x is divisible by y
- pred : N -> NP -> NP -> Cl e.g x and y are inverses
- more pred in p317
- app : N2 -> NP -> CN e.g divisor of x
- app: N3 -> NP -> NP -> CN path from x to y
- more app in p317
-
P320 worthwhile to glance again. run help in gf shell to get a full list of commands and explanations.
-
? p320 gr -probs=FILE -- generate with bias
-
? p320 i -v LangEng.gf LangSwe.gf -- import Eng and Swe, be verbose
-
E2 GF Batch Compiler: to run GF from a script, use redirection
- $ gf <script.gfs
-
? ++ vs +
- ++ in FoodsEng.gf lin pred quality , lin Mod quality kind and lin very a
-
- in ResEng.gf oper flynoun and oper regnoun and OverloadEng.gf oper regVerb and irregVerb
gr -cat=Cl | l -all -treebank
give linearizations n treebanks of all Cat = Cl- For tense and polarity sensitive sentences. Chapter10/Food1treeEng.gf FROM RGL: mkS (Tense) -> (Ant) -> (Pol) -> Cl -> S
- Pred item quality = mkUtt (mkCl (item) (quality)); -- dont need to mkNP item and mkAP quality as item and quality are alr NP and AP per lincat
- after making opers e.g wine = mkN "wine" ; i still need to tackle linearization in lin section by Wine = mkCN wine ie Wine = mkCN (mkN "wine")
abstract_info VP
gives all the fun that produce a VP. similarai eat_V2
for eat and its probabilityl -all i_Pron
to see all the inflextion table contents in i_Pron- forming phrases by extracting the inherent features of different arg to make things coherent
lincat ChangingCat = { beforeChangingPart , afterChangingPart : Str ; changingPart: Foo => Bar => Str }; lin -- fix : ChangingCat -> AffectingCat -> FixedCat fix ch af = { s = ch.beforeChangingPart ++ ch.changingingPart!af.foo!af.bar ++ ch.afterChangingPart };
l -all eat_V2
to get all linearization of eat ie eat eats eat.l -all ReflV2 love_V2
- test
gf --run < corpus.gfs
where corpus.gfs contains the commandsgf --run < corpus.gfs > corpus.GOLD
which contains the results of the commands in corpus.gfsgf --run < corpus.gfs | diff -u - corpus.GOLD
to compare results
- In code/GFSummerSchool/Singlish/Version0/SinglishEngOrg.gf hack to change a subcategory V2 to a V to use the RGL.
(mkVP <action : V> )
-- : Actor -> Action -> Pred ;
PersonAction actor action = mkS(mkCl (mkNP actor) (mkVP <action : V> )) ; -- hack to force a sub-category action: V2 into a higher category
```