Skip to main content

Parsetron - A natural language semantic parser

https://travis-ci.org/Kitt-AI/parsetron.svg?branch=develop https://coveralls.io/repos/Kitt-AI/parsetron/badge.svg?branch=develop Documentation Status

A natural language semantic parser

Installation

pip install parsetron

Parsetron is tested under Python 2.7 and Pypy. It doesn’t support Python 3 yet.

Quick Start

The following is a grammar that parses natural language instruction on lights:

from parsetron import Set, Regex, Optional, OneOrMore, Grammar, RobustParser

class LightGrammar(Grammar):

    action = Set(['change', 'flash', 'set', 'blink'])
    light = Set(['top', 'middle', 'bottom'])
    color = Regex(r'(red|yellow|blue|orange|purple|...)')
    times = Set(['once', 'twice', 'three times']) | Regex(r'\d+ times')
    one_parse = action + light + Optional(times) + color
    GOAL = OneOrMore(one_parse)

    @staticmethod
    def test():
        parser = RobustParser((LightGrammar()))
        sents = [
            "set my top light to red",
            "set my top light to red and change middle light to yellow",
            "set my top light to red and change middle light to yellow and "
            "flash bottom light twice in blue"
        ]
        for sent in sents:
            tree, result = parser.parse(sent)
            assert result.one_parse[0].color == 'red'

            print '"%s"' % sent
            print "parse tree:"
            print tree
            print "parse result:"
            print result
            print

Dependencies

None. Parsetron is a single parsetron.py file.

Parsetron is inspired by pyparsing.

Grammar Modules

Parsetron supports modularized grammars: each grammar focuses on an individual small domain and can be imported via, for instance:

from parsetron.grammars.colors import ColorsGrammar

class YourCustomizedGrammar(Grammar):
    color = ColorsGrammar.GOAL

You are welcome to contribute your own grammar here (under parsetron.grammars). Send us a pull request!

Development

  1. fork this repository

  2. install dev-specific packages:

    pip install -r requirements.txt
  3. then make your changes and follow the Makefile.

TODO

  • [ ] Python 3 compatible

  • [ ] Unicode support

Documentation

The full documentation is at http://parsetron.rtfd.org.

History

0.1.1 (2015-08-24)

  • ParseResult now supports lex_span() method.

0.1.0 (2015-06-19)

  • First release on PyPI.

Metadata

Release files for parsetron 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parsetron 0.1.1
File Size Uploaded Provenance Actions
parsetron-0.1.1.tar.gz 41.0 kB Without provenance Details for parsetron-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parsetron 0.1.1
File Interpreter ABI Platform Actions
parsetron-0.1.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for parsetron-0.1.1-py2.py3-none-any.whl

Total release size: 76.5 kB

Release files / parsetron-0.1.1.tar.gz

Download URL parsetron-0.1.1.tar.gz
Size 41.0 kB
Tags Source
SHA-256 checksum
How to use checksums
97324cec1bfc011e0728640fe16d46ee2cf064253863c7174aa5a8d329ffa980
BLAKE2b-256 checksum
How to use checksums
5d85aa5a6c53471386f6d7a8502d6a172e146807cccd3026825d374a1f4f4888
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / parsetron-0.1.1-py2.py3-none-any.whl

Download URL parsetron-0.1.1-py2.py3-none-any.whl
Size 35.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
769c21a4d3ae3434bdb5b74b82da4d9f87fe76f9e967830100ceddf946ae2b33
BLAKE2b-256 checksum
How to use checksums
8e1274a09e3a6bb03d8f926e2f58302276adfb23a9fe3def0d527021f0f22ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for parsetron 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page