Skip to content

Instantly share code, notes, and snippets.

@inariksit
Last active January 13, 2019 21:14
Show Gist options
  • Save inariksit/31934b42e03d472fa1b3eb658ee66810 to your computer and use it in GitHub Desktop.
Save inariksit/31934b42e03d472fa1b3eb658ee66810 to your computer and use it in GitHub Desktop.
abstract My = Numeral -- Extending Numeral grammar from RGL, see http://www.grammaticalframework.org/doc/tutorial/gf-tutorial.html#toc43
** {
flags startcat = Clause ;
cat
Kind ;
Clause ;
-- The categories Int, Float and String are present in all grammars
-- The categories Dig and Digits come from Numeral, which this grammar extends.
fun
NItemsLiteral : Int -> Kind -> Clause ;
NItemsDig : Digits -> Kind -> Clause ;
Car : Kind ;
} ;
concrete MyEng of My = NumeralEng -- English linearisations of Digits, IIDig, IDig
** open -- Opening the following helper modules:
SyntaxEng, -- for CN, S, mkS, mkCl, mkNP, mkCN, mkDet, aPl_Det
ParadigmsEng, -- for mkN
SymbolicEng -- for symb
in {
lincat
Kind = CN;
Clause = S;
lin
-- Hacky, and produces "1 cars"
NItemsLiteral int kind =
let sym : NP = symb int ;
item : NP = mkNP aPl_Det kind ; -- indefinite plural
symItem : NP = item ** {s = \\c => sym.s ! c ++ item.s ! c} ;
in mkS (mkCl symItem) ;
-- Comes from the RGL, produces "1 car"
NItemsDig num kind = mkS (mkCl (mkNP (mkDet num) kind)) ;
Car = mkCN (mkN "car") ;
}
-- Examples and comments
{-
My> l NItemsDig (IDig D_1) Car
there is 1 car
My> l NItemsLiteral 1 Car
there are 1 cars
My> p "there are 2 cars"
NItemsDig (IDig D_2) Car
NItemsLiteral 2 Car
With Digits, the numbers are bound together by the BIND token. If you
linearise without the flag -bind in the normal GF shell, you get &+ in
between.
My> l NItemsDig (IIDig D_9 (IIDig D_9 (IDig D_9))) Car
there are 9 &+ 9 &+ 9 cars
0 msec
My> l -bind NItemsDig (IIDig D_9 (IIDig D_9 (IDig D_9))) Car
there are 999 cars
Furthermore, parsing doesn't work if you don't insert the &+ tokens:
My> p "there are 999 cars"
NItemsLiteral 999 Car
This is because the standard GF shell uses the Haskell runtime, which
doesn't add the &+s automatically. The newer C runtime supports it,
and there are bindings from it to several programming languages, if
you want to use a GF grammar which uses BIND tokens in an application.
If your GF is compiled with C runtime support, then you can start the GF
shell with the flag -cshell, and open your grammar in a PGF format. This
is already included in the binary versions, except for Windows.
Follow these steps:
```
$ gf -make MyEng.gf -- this creates My.pgf
$ gf -cshell -- open GF with -cshell flag
> i My.pgf -- import My.pgf
My> p "there are 999 cars"
NItemsLiteral 999 Car
NItemsDig (IIDig D_9 (IIDig D_9 (IDig D_9))) Car
```
More information about BIND token: https://www.aclweb.org/anthology/W/W15/W15-3305.pdf
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment