Comments (1)
var cfg = new Grammar(new List<Production>{
CFGParser.Production("<S> → <X>"),
CFGParser.Production("<X> → <X> <X> <X>"),
CFGParser.Production("<X> → 'x'"),
CFGParser.Production("<X> → ε"),
}, Nonterminal.Of("S"));
var cnf = cfg.ToCNF();
Console.WriteLine(cnf.ToCodeString());
The above will print out:
new Grammar(new List<Production>{
CFGParser.Production("<X> → <X> <X_1> [0.57397795223953818]"),
CFGParser.Production("<X_1> → <X> <X> [0.42602204776046193]"),
CFGParser.Production("<X> → <X> <X> [0.14795590447907633]"),
CFGParser.Production("<X_1> → <X> <X_1> [0.13846042410495038]"),
CFGParser.Production("<X_0> → <X> <X_1> [0.21756788155537982]"),
CFGParser.Production("<X_0> → <X> <X> [0.056083082243007]"),
CFGParser.Production("<X> → 'x' [1]"),
CFGParser.Production("<X_1> → 'x' [0.24122951685636643]"),
CFGParser.Production("<X_0> → 'x' [0.37905268086775262]"),
CFGParser.Production("<X_0> → ε [0.34729635533386066]")
}, Nonterminal.Of("X_0"))
which satisfies the rules for CNF, but should generate the same sentences with the same probability as the original grammar. The cnf
object itself is of type CNFGrammar
, which behaves like a typical Grammar
, but can also be used with the CYK algorithm.
If this doesn't answer your question, please be more specific.
from cfglib.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cfglib.