kalexmills / stochrammar

Stochastic grammar library implemented in Java.
GNU Affero General Public License v3.0
0 stars 0 forks source link
context-free-grammar grammar-rules stochastic-process

stochrammar

Stochrammar is an abstract Stochastic grammar library implemented in Java. If you are willing to bring your own code, you can use it to procedurally generate "anything" without having to worry (much) about the correctness of the generation algorithm as part of the process. At the moment, stochrammar can only be used to generate entities from context-free grammars (CFGs), but work on context-sensitive grammars (CSGs) and semi-thue systems are also on the roadmap.

Since grammars involving strings are easy to understand, design, implement, and reason about, this library separates the procedural generation problem into two phases. In the token generation phase, a collection of GroundTokens are generated by applying production rules to replace GrammarTokens. Next, in the entity construction phase, the tokens act on a blank entity in an order determined by a GrammarRunner.

GrammarTokens are responsible for defining the means by which they are replaced with other GrammarTokens, and the means by which they act on entities.

At the moment, the library is not flexible enough to be used without subclassing GrammarToken GroundToken and StochasticGrammar, but if you do that properly, then the classes in com.nifty.stochrammar.runner should all work. If you find that they do not, open an issue (this software is still young).

See WeightedGrammar.java for an example implementation.

Brief History

An earlier, proprietary version of this library was used in the development of Tweeter in Chief. The copyright holder released an updated version of the library under the AGPL on November 3rd, 2018.