{"id":22355259,"url":"https://github.com/drdub/php-nlgen","last_synced_at":"2025-07-20T15:04:27.698Z","repository":{"id":45558495,"uuid":"2173065","full_name":"DrDub/php-nlgen","owner":"DrDub","description":"NLGen: a library for creating recursive-descent natural language generators","archived":false,"fork":false,"pushed_at":"2024-02-26T19:38:12.000Z","size":310,"stargazers_count":55,"open_issues_count":4,"forks_count":12,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-14T13:33:26.012Z","etag":null,"topics":["ai","artificial-intelligence","chatbot","grammar","natural-language-generation","nlg","nlp","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/nlgen/nlgen","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DrDub.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"ROADMAP","authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2011-08-08T12:08:52.000Z","updated_at":"2024-09-21T01:51:31.000Z","dependencies_parsed_at":"2025-01-16T09:16:01.609Z","dependency_job_id":"93041360-6d61-46ae-9141-c65df0ef7910","html_url":"https://github.com/DrDub/php-nlgen","commit_stats":{"total_commits":64,"total_committers":5,"mean_commits":12.8,"dds":0.140625,"last_synced_commit":"3afc191b0a2a006a4c2c66d459163757a0a95205"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/DrDub/php-nlgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrDub%2Fphp-nlgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrDub%2Fphp-nlgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrDub%2Fphp-nlgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrDub%2Fphp-nlgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DrDub","download_url":"https://codeload.github.com/DrDub/php-nlgen/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DrDub%2Fphp-nlgen/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266143941,"owners_count":23883069,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","chatbot","grammar","natural-language-generation","nlg","nlp","php"],"created_at":"2024-12-04T13:17:26.682Z","updated_at":"2025-07-20T15:04:27.651Z","avatar_url":"https://github.com/DrDub.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](http://poser.pugx.org/nlgen/nlgen/v)](https://packagist.org/packages/nlgen/nlgen) [![Total Downloads](http://poser.pugx.org/nlgen/nlgen/downloads)](https://packagist.org/packages/nlgen/nlgen) [![Latest Unstable Version](http://poser.pugx.org/nlgen/nlgen/v/unstable)](https://packagist.org/packages/nlgen/nlgen) [![License](http://poser.pugx.org/nlgen/nlgen/license)](https://packagist.org/packages/nlgen/nlgen)\n\n# NLGen: a library for creating recursive-descent natural language generators\n\nThese are pure PHP helper classes to implement recursive-descent\nnatural language generators [1].  The classes provided are an abstract\ngenerator, an ontology container and a lexicon container.\n\nThese classes should help build simple to mid-level generators,\nspeaking about their complexity.  Emphasis has been made in keeping\nmore advanced features out of the way for simpler cases (i.e., if\nthere is no need to use the ontology or the lexicon, they can be\nskipped).\n\nThe generator keeps track of semantic annotations on the generated\ntext, so as to enable further generation functions to reason about the\ntext.  A global context blackboard is also available.\n\nFor details on the multilingual example see the Make Web Not War talk. [2]\n\nThis is work in progress, see the ROADMAP for some insights in future\ndevelopment.\n\n* [1] http://duboue.net/blog5.html\n* [2] http://duboue.net/papers/makewebnotwar20111128.html\n\n\n## Available Generation Grammars\n\nNLGen ships with a generation grammar ready to use, that constructs\ntext descriptions for weekly schedules. The grammar is accessible by\nimporting `\\NLGen\\Grammars\\Availability\\AvailabilityGenerator`.\n\nThe method `generateAvailability` receives a list of \"busy times\" in\nthe form of\n\n`[ day-of-week, [ start hour, start minute ], [ end hour, end minute ] ]`\n\na list of ranges indicating when the scheduled day starts and ends (in\nthe form of `[ day-of-week =\u003e [ start hour, start minute ], [ end\nhour, end minute ] ]`) and a constant indicating how \"coarse\" should\nbe the text (one liner summarizing or very detailed).\n\nSee `examples/availability` and `tests/Availability/AvailabilityTest`.\n\nExample:\n\n```php\nuse NLGen\\Grammars\\Availability\\AvailabilityGenerator;\n\n$gen = new AvailabilityGenerator();\n$busyList = [\n  [3, [16, 30], [17, 30] ],\n  [6, [ 6, 55], [11, 41] ],\n  [6, [14, 32], [22, 05] ]\n];\n$fullRanges = [];\nforeach(range(0, 6) as $dow) {\n $fullRanges[$dow] = [ [6, 0], [24, 0] ];\n}\necho $gen-\u003egenerateAvailability($busyList, $fullRanges, AvailabilityGenerator::BASE, null);\n```\n\nProduces _All week is mostly free all day. Sunday is busy from late 6 AM to late 11 AM, and from half past 14 PM to 22 PM; the rest is free._\n\n\n## Using it in your own projects\n\nLook at the `examples/` folder, but in a nutshell, subclass the\n`NLGen\\Generator` class and implemented a function named `top`. This\nfunction can return either a string or an array with a `text` and\n`sem` for semantic annotations on the returned text.\n\nIf you want to use other functions to assemble the text use\n`$this-\u003egen('name_of_the_function',\n$data_array_input_to_the_function)` to call it (instead of\n`$this-\u003ename_of_the_function($data_array_input_to_the_function)`. Or\nyou can define your functions as *protected* and use function\ninterposition, described below. The generator abstract class keeps\ntrack of the semantic annotations for you and other goodies.\n\nIf the functions that implement the grammar are *protected*, a dynamic\nclass can be created with the `NewSealed` class method. This dynamic\nclass will have function interception so you can call\n`$this-\u003ename_of_function` as usual but actually `$this-\u003egen` will be\ncalled.\n\nEither way you use it, to call the class, if your instantiated\nsubclass is `$my_gen` then `$my_gen-\u003egenerate($input_data_as_an_array)`\nwill return the generated strings. If you want to access the semantic\nannotations, use `$my_gen-\u003esemantics()` afterward.\n\nFor different use cases, see the `examples/` folder.\n\n\n## Most basic example\n\nThis example is grafted from the `examples/basic` folder. To be\ninvoked command-line with `php basic.php 0 0 0 0` (it produces _Juan\nstarted working on Component ABC_).\n\n```php\nclass BasicGenerator extends Generator {\n\n  var $agents = array('Juan','Pedro','The helpdesk operator');\n  var $events = array('started','is','finished');\n  var $actions = array('working on','coding','doing QA on');\n  var $themes = array('Component ABC','Item 25','the delivery subsystem');\n\n  protected function top($data){\n    return\n      $this-\u003eperson($data[0]). \" \" .\n      $this-\u003eaction($data[1], $data[2]). \" \" .\n      $this-\u003eitem($data[3]);\n  }\n\n  protected function person($agt){ return $this-\u003eagents[$agt]; }\n  protected function action($evt, $act){ return $this-\u003eevents[$evt].\" \".$this-\u003eactions[$act]; }\n  protected function item($thm) { return $this-\u003ethemes[$thm];  }\n}\n\nglobal $argv,$argc;\n$gen = BasicGenerator::NewSealed();\nprint $gen-\u003egenerate(array_splice($argv,1) /*,array(\"debug\"=\u003e1)*/).\"\\n\";\n```\n\n\n## Learning more about NLG\n\nI highly recommend Building Natural Language Generation Systems (2000)\nby Reiter and Dale.\n\nThe SIGGEN site [2] has plenty of good resources. You might also want\nto look at the NLG portal at the Association for Computational\nLinguistics wiki [3].\n\nLast but not least, you might be interested in the author's blog [4]\nand the class notes of his recent NLG course [5].\n\n\n* [2] http://www.siggen.org/\n* [3] http://aclweb.org/aclwiki/index.php?title=Natural_Language_Generation_Portal\n* [4] http://duboue.net/blog.html\n* [5] http://wiki.duboue.net/index.php/2011_FaMAF_Intro_to_NLG\n\n## Integrations\n* https://doc.tiki.org/Natural-Language-Generation\n\n\n## Sponsorship\n\nWork on NLGen is sponsored by [Textualization Software Ltd.](https://textualization.com).\n\n\n## License\n\nThis library is licensed under the MIT License - See the [LICENSE](LICENSE) file for details.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrdub%2Fphp-nlgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrdub%2Fphp-nlgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrdub%2Fphp-nlgen/lists"}