Giter Site home page Giter Site logo

contextfreegrammar_gen's Introduction

contextfreegrammar_gen

This is a text generator based on context free grammars encoded in BNF.

Productions can be added either directly or using an input file. Check the following snippet for an example of direct addition of productions:

from cfg import ContextFreeGrammar, cleanup

grammar = ContextFreeGrammar()
grammar.add_production('S', 'NP VP')
grammar.add_production('NP', 'Det N | Det N')
grammar.add_production('NP', 'I | he | she | Joe')
grammar.add_production('VP', 'V NP | VP')
grammar.add_production('Det', 'a | the | my | his')
grammar.add_production('N', 'elephant | cat | jeans | suit')
grammar.add_production('V', 'kicked | followed | shot')

Once productions are added, a sentence based on the productions can be generated as follows:

for i in xrange(10):
    print cleanup(grammar.gen_random_convergent('S')) 

This generates ten sentences such as:

I followed Joe.
I followed she.
I followed he.
My cat kicked Joe.
Joe shot she.
Joe shot the elephant.
She followed my suit.
I shot she.
He shot Joe.
His jeans followed she.

Reading from an input BNF productions is pretty simple:

grammar = ContextFreeGrammar()
grammar.add_productions_from_file('./grammars/spout.cfg')
for i in xrange(10):
    s = cleanup(grammar.gen_random_convergent('spout'))
    print s

Which when run gives something like:

Show that the T U- matrix of 9 is uncomputable.
Show that the inverse determinant of 5 9 1 is 5. Include Feynman diagrams.
Are maximal trees S-complete? Discuss. Be sure to refer to Fermat 's Theorem in your answer.
Show that the R- path of { 9 6 } is uncomputable. Be sure to refer to Plutonium Atom Totality in your answer.
Express { 2 4 0 9 } in canonical form.
Are inverse matrices R E-complete? Discuss.
Show that the inverse matrix of 5 5 is infinity. Be sure to refer to Fermat 's Theorem in your answer.
Show that the Q- closure of 1 7 is the null set.
Express 2 in the epsilon domain. Include flowcharts.
Is maximal factorisation T-complete? Discuss.

There are 8 grammars in the ./grammars directory to poke arround with.

##Installation Clone repository.

##Dependencies None

contextfreegrammar_gen's People

Contributors

rabihkodeih avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.