protected function setUp() { $gram = new ChomskyNormalForm(); $gram->addRule(new RewriteRule("DET", "le")); $gram->addRule(new RewriteRule("DET", "la")); $gram->addRule(new RewriteRule("SN", "chat")); $gram->addRule(new RewriteRule("SN", "souris")); $gram->addRule(new RewriteRule("V", "mange")); $gram->addRule(new RewriteRule("GV", "V", "GN")); $gram->addRule(new RewriteRule("GN", "DET", "SN")); $gram->addRule(new RewriteRule("PH", "GN", "GV")); $this->algorithm = new CYKAlgorithm($gram); }
public function main() { // 1. Instanciate a generic ChomskyNormalForm $grammar = new ChomskyNormalForm(); // 2. Configure the grammar $rules = array(new RewriteRule("DET", "le"), new RewriteRule("DET", "la"), new RewriteRule("SN", "chat"), new RewriteRule("SN", "souris"), new RewriteRule("V", "mange"), new RewriteRule("GN", "DET", "SN"), new RewriteRule("GV", "V", "GN"), new RewriteRule("PH", "GN", "GV")); foreach ($rules as $rule) { $grammar->addRule($rule); } // 3. Instanciate a CYK algorithm matrix $cyk = new CYKAlgorithm($grammar); // 4. Load a phrase in the matrix $cyk->load(array('le', 'chat', 'mange', 'la', 'souris')); // 5. Output the matrix $this->outputCYKMatrix($cyk->matrix); // new line $this->output->outputLine(); }