earley-cfg
An npm module containing an implementation of the a Context Free Grammar (CFG) using the Earley algorithm. This is my take on this NPM module, with changes to suit my needs.
Example
var earley = ; var grammar = 'grammar.cfg';var parser = grammar; var sentence = 'time/time<N> flies/fly<N>/fly<V> like/like<V>/like<P> an/a<D> arrow/arrow<N>'; var result = parser; ifresultvalid === true console; var trees = result; console;else console;
grammar.cfg
S -> NP VP | VPNP -> D N | N | N NPVP -> V | V NP | V PP | V NP PPPP -> P NP
Download
Install using Node Package Manager (npm
):
npm install earley-cfg