コード例 #1
0
 public function testUnvalidate()
 {
     $phrase = array('le', 'chat', 'mange', 'souris');
     $this->algorithm->load($phrase);
     $ok = $this->algorithm->validate('PH');
     $this->assertFalse($ok);
 }
コード例 #2
0
ファイル: Console.php プロジェクト: charlycoste/nlphp
 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();
 }