npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

earley-node

v0.0.3

Published

### An implementation of the a Context Free Grammar (CFG) using the Earley algorithm in Node.JS

Downloads

3

Readme

Earley Node

An implementation of the a Context Free Grammar (CFG) using the Earley algorithm in Node.JS

Earley is a small program that, given a well-formatted context-free grammar, and an input sentence that has already been passed through a part-of-speech tagger program, can tell you whether or not the sentence is valid in this grammar, and if so, output all possible parse trees in a nice format.

This project is a direct port of Earley Bird, origionally written in Python by Sagie Maoz.

Usage

npm install earley-node

Input

To use Earley Bird, one needs two things.

  • Context-free grammar: A set of production rules in the form of V -> w, where V is a single nonterminal symbol, and w is a list of strings of terminals and/or nonterminals. At least one rule with left-hand side S (for sentence) must exist in order for sentences to be valid. An item in w can be empty, to represent epsilon productions. For info, see CFG description in Wikipedia. Earley bird reads a grammar from a text file where every line comprises of such rule. Comments are supported, prefixed by #. Example: S -> NP VP | VP NP -> D N | N | N NP VP -> V | V NP | V PP | V NP PP PP -> P NP For other examples of CFG, see sample.cfg in the project directory.

  • Sentence: Earley Bird expects an input of a sentence string with words already parsed for possible parts of speech. The input should be formatted using the Apertium stream format, with each word followed by groups of a lemma and a list of tags, e.g. time/time<N> flies/fly<N>/fly<V> like/like<V>/like<P> an/a<D> arrow/arrow<N>

Output

The first line in the standard output would be the result of the validity check. i.e. either ==> Sentence is valid., or ==> Sentence is invalid.

If the sentence was found invalid using the provided grammar, tough beans, that's it.

If it's valid, you'll also get a list of valid parse trees. ==> Sentence is valid. Valid parse trees: Parse tree #1: [.GAMMA [.S [.NP [.N [.time ] ] ] [.VP [.V [.flies ] ] [.PP [.P [.like ] ] [.NP [.D [.an ] ] [.N [.arrow ] ] ] ] ] ] ] </Parse Trees>

Each tree is printed in the Qtree format, and you can then use several tools to use them in documents or generated images from them. phpSyntaxTree is a recommended tree image generation tool.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Known Issues

  1. Sentence input should be inside ^...$ to comply with the Apertium stream format.
  2. There is a bug in creating the trees list in ParseTrees, causing all possible parse trees creates as branches of the same tree, instead of duplicating the head to different alternatives.
  3. Some ambiguities are not represented, but this should be checked only after the trees creation is fixed.
  4. Generated trees should be filtered and only ones that are long enough (as long as the sentence) should be returned.