Public
Edited
Dec 23, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { N,D,A,Pro,V,Adv,P,C,Q,DT,NO, // Terminal constructors
S,SP,CP,VP,NP,AP,AdvP, // Phrase constructors
root,subj,det,mod,comp,coord, // Dependent constructors
oneOf, // Random choice
getLemma,getLanguage,addToLexicon,updateLexicon // lexicon Access
} from "@lapalme/jsrealb-en"
Insert cell
Insert cell
Insert cell
N("cat")
Insert cell
Insert cell
Insert cell
realize(N("cat"),
N("dog"))
Insert cell
Insert cell
realize(D("a"),
N("cat"))
Insert cell
Insert cell
realize(V("love"))
Insert cell
Insert cell
realize(Pro("I"))
Insert cell
Insert cell
realize(A("good"),
Adv("so"),
P("of"),
C("or"),
Q("Wow!!"))
Insert cell
Insert cell
realize(DT("2020/12/25"),
DT())
Insert cell
Insert cell
realize(NO(123),
NO(45678))
Insert cell
Insert cell
realize(D("a").n("p"), // empty string when plural...
N("cat").n("p"),
Pro("I").g("n"))
Insert cell
Insert cell
realize(V("finish").t("f").n("p"))
Insert cell
Insert cell
realize(DT().dOpt({hour:false,minute:false,second:false,nat:true}),
DT("2020/12/25").dOpt({hour:false,minute:false,second:false,nat:false}))
Insert cell
Insert cell
realize(NO(123).dOpt({nat:true}),
NO(15).dOpt({ord:true}),
NO(3.141592).dOpt({mprecision:4}),
NO(2378).dOpt({rom:true}))
Insert cell
Insert cell
html`${realize(D('a').tag("b"),
A("grey").tag("i"),
N("cat").tag("a",
{href:"https://en.wikipedia.org/wiki/Cat",
target:"_blank"}))}`
Insert cell
Insert cell
Insert cell
np1 = NP(D("the"),
N("cat").n("p"),
A("small"),
A("black"))

Insert cell
np2 = NP(D("a"),
N("mouse").n("p"))
Insert cell
s = S(np1,
VP(V("eat").t("f"),
np2))
Insert cell
Insert cell
realize(np1,np2,s)
Insert cell
Insert cell
realize(S(np1,
VP(V("eat").t("ps"),
np2)).typ({"neg":true,"pas":true}))
Insert cell
Insert cell
function np1_f(n){
return NP(D("the"),
N("cat").n(n ?? "s"),
A("small"),
A("black"))
}
Insert cell
Insert cell
realize(np1_f("p"),np1_f())
Insert cell
Insert cell
np2_f = (n)=>NP(D("a"),N("cheese").n(n ?? "s"))
Insert cell
s_f = (n) => S(np1_f(n),VP(V("eat"),np2_f(n)))
Insert cell
realize(s_f("p"),s_f().typ({"neg":true,"pas":true}))
Insert cell
Insert cell
function show(ph_f,modTyp){
return ph_f().typ(modTyp ?? {}).realize();
}
Insert cell
Insert cell
show(s_f)
Insert cell
Insert cell
show(s_f,{neg:true})
Insert cell
Insert cell
show(s_f,{neg:true, pas:true})
Insert cell
Insert cell
show(s_f,{int:"wos"})
Insert cell
Insert cell
show(s_f,{int:"wad"})
Insert cell
Insert cell
sp_f = ()=>S(np2_f()
.add(SP(Pro("that"),
np1_f(),
VP(V("eat").t("ps"))).typ({perf:true,prog:true,mod:"nece"})),
VP(V("be"),
A("white")).t("ps"))
Insert cell
Insert cell
Insert cell
show(sp_f)
Insert cell
Insert cell
show(sp_f,{neg:true})
Insert cell
Insert cell
cp_f = () => CP(C("and"),
NP(D("the"),N("cat")),
NP(D("the"),N("mouse")),
NP(D("a"),N("rabbit")))
Insert cell
Insert cell
show(()=>S(cp_f(),
VP(V("come").t("ps"))))
Insert cell
Insert cell
show(()=>S(cp_f().add(NP(NO(25).nat(true),N("dog"))),
VP(V("come").t("ps"))))
Insert cell
Insert cell
man_f = (n) => NP(D("the"), N("man").n(n ?? "s"),A("pretty"))

Insert cell
woman_f = (n) => NP(D("a"),N("woman").n(n ?? "s"),A("bright"))
Insert cell
Insert cell
show(()=>S(man_f("p"),
VP(V("love"),
woman_f("p"))))
Insert cell
Insert cell
show(()=>S(man_f().pro(),
VP(V("love"),
woman_f())))
Insert cell
Insert cell
show(()=>S(man_f().pro(),
VP(V("love"),
woman_f().pro())))
Insert cell
Insert cell
show(()=>root(V("eat").t("p"),
subj(N("cat").n("p"),
det(D("a"))),
comp(N("mouse"),
det(D("the")),
mod(A("white")))))
Insert cell
Insert cell
show(()=>root(V("eat"),
coord(C("and"),
subj(N("boy"),det(D("the"))),
subj(N("girl"),det(D("the")))),
coord(C("or"),
comp(N("soup"),
mod(N("vegetable")).pos("pre")),
comp(N("pork").n("s")),
comp(N("chicken")))),
{pas:true})
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more