Skip to content

Instantly share code, notes, and snippets.

@inariksit
Created February 16, 2023 23:32
Show Gist options
  • Save inariksit/f3f89ab108d9b523d522ff7107225d4d to your computer and use it in GitHub Desktop.
Save inariksit/f3f89ab108d9b523d522ff7107225d4d to your computer and use it in GitHub Desktop.
Accepting variants in omitting particles
abstract OmitParticles =
Grammar [ -- "Embedded DSL" on top of some RGL categories
N, CN, NP, UseN, MassNP
, V2
, S, Cl, Temp, Pol, Tense, Ant
, UseCl, PPos, PNeg, TTAnt, TPres, TPast, ASimul
]
, Lexicon -- to get some lexicon
** {
flags startcat = S ;
cat
-- Our custom version of RGL's VP, to allow variants (omitted particles)
-- Because we don't want to introduce variation deep in the RGL functions
-- That can cause serious blowup and mysterious bugs
Action ;
fun
Topic : NP -> Action -> Cl ;
-- These functions will have optionally omitted particle
AddSubject : NP -> V2 -> Action ;
AddObject : NP -> V2 -> Action ;
}
concrete OmitParticlesJpn of OmitParticles =
GrammarJpn [
N, CN, NP, UseN, MassNP
, V2
, S, Cl, Temp, Pol, Tense, Ant
, UseCl, PPos, PNeg, TTAnt, TPres, TPast, ASimul
]
, LexiconJpn
** open
SyntaxJpn -- the standard multilingual RGL API
in {
lincat
-- NB. No need to prefix everything with SyntaxJpn,
-- I'm doing it so you see where the opers come from.
Action = SyntaxJpn.VP ;
MyUtt = SyntaxJpn.Phr ;
lin
-- : NP -> Action -> Cl ;
Topic topic action = SyntaxJpn.mkCl topic action ;
-- : NP -> V2 -> Action ;
AddSubject = optionalParticle "が" ;
AddObject = optionalParticle "を" ;
oper
optionalParticle : Str -> NP -> V2 -> SyntaxJpn.VP ;
optionalParticle ga neko taberu =
-- We construct a normal VP with the RGL API (safe)
let vp : SyntaxJpn.VP = SyntaxJpn.mkVP taberu neko
-- Now we touch its raw fields: unsafe if internals of Japanese resource grammar change
-- See https://inariksit.github.io/gf/2019/02/17/beyond-API.html for more on the topic
in vp ** { prep = ga | [] } ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment