Skip to content
A natural language semantic parser
Python Makefile Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs v0.1.1 Aug 5, 2015
parsetron
test pushed in v0.1.1, added lexical span support Aug 5, 2015
.gitignore docs compile Jun 9, 2015
.travis.yml added coveralls Jun 19, 2015
AUTHORS.rst updated tutorial Jun 18, 2015
CONTRIBUTING.rst project setup Jun 9, 2015
HISTORY.rst
LICENSE project setup Jun 9, 2015
MANIFEST.in project setup Jun 9, 2015
Makefile added source addr in docs Jul 7, 2015
README.rst added doc addr in README Jul 7, 2015
requirements.txt changed theme, added ico Jun 19, 2015
setup.cfg project setup Jun 9, 2015
setup.py uploaded to pypi Jun 19, 2015
tox.ini lint passed Jun 18, 2015

README.rst

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.

Documentation and Tutorial

http://parsetron.kitt.ai

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
You can’t perform that action at this time.