PHP code example of nlgen / nlgen
1. Go to this page and download the library: Download nlgen/nlgen library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nlgen / nlgen example snippets
use NLGen\Grammars\Availability\AvailabilityGenerator;
$gen = new AvailabilityGenerator();
$busyList = [
[3, [16, 30], [17, 30] ],
[6, [ 6, 55], [11, 41] ],
[6, [14, 32], [22, 05] ]
];
$fullRanges = [];
foreach(range(0, 6) as $dow) {
$fullRanges[$dow] = [ [6, 0], [24, 0] ];
}
echo $gen->generateAvailability($busyList, $fullRanges, AvailabilityGenerator::BASE, null);
class BasicGenerator extends Generator {
var $agents = array('Juan','Pedro','The helpdesk operator');
var $events = array('started','is','finished');
var $actions = array('working on','coding','doing QA on');
var $themes = array('Component ABC','Item 25','the delivery subsystem');
protected function top($data){
return
$this->person($data[0]). " " .
$this->action($data[1], $data[2]). " " .
$this->item($data[3]);
}
protected function person($agt){ return $this->agents[$agt]; }
protected function action($evt, $act){ return $this->events[$evt]." ".$this->actions[$act]; }
protected function item($thm) { return $this->themes[$thm]; }
}
global $argv,$argc;
$gen = BasicGenerator::NewSealed();
print $gen->generate(array_splice($argv,1) /*,array("debug"=>1)*/)."\n";