定制 rb/polygen-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rb/polygen-php

Composer 安装命令:

composer require rb/polygen-php

包简介

A PHP implementation of Polygen - A random sentence generator.

README 文档

README

Polygen is a tool that parses text files containing a grammar definition and generates text according to that definition. Polygen-PHP does the same, but in PHP 5.6+ and is compatible with the same grammar files, so now you can use Polygen on your website even if it's on a shared hosting service.

For example, the following grammar file

S ::= this is Subject and is Quantity Adjective;
Subject ::= a grammar | polygen;
Quantity ::= rather | quite | very;
Adjective ::= interesting | remarkable | dumb;

might result in the following sentences being generated:

  • this is a grammar and is rather dumb
  • this is polygen and is quite remarkable
  • this is a grammar and is very interesting

... and so on.

There are many more features in the language, check out the official Polygen documentation to learn everything about it.

Installation

You can install Polygen-PHP using composer: composer require rb/polygen-php

Usage instructions

<?php
$polygen = new \Polygen\Polygen();
$your_grammar = \GuzzleHttp\Stream\Stream::factory('S ::= hello world;');
$document = $polygen->getDocument($your_grammar);
var_dump($polygen->generate($document)); // Will print "hello world".

Parse once, produce many (POPM)

It's not necessary to parse the source grammar every time a production is wanted: once a Polygen document is obtained, it can be serialize()d to a string and stored as a string constant. This way, the parsing can be done only once at "compile time", then at runtime, it's sufficient to unserialize() the string back to a Polygen document, and it can be used as usual to obtain a production.

Command line usage

There is also a CLI tool that you can use. It's not refined at all, since it is intended for debugging only, but the basics work. If you require this package as a dependency of your project, Composer must have placed the CLI tool in your vendor/bin folder, so you can run it with ./vendor/bin/polygen.php. A small usage will be printed if launched with no parameters (or with -h or --help parameters).

Known issues

Static checking

  • I believe that the static infinite recursion check is broken, but I have not proved this yet. Just try to avoid grammars with circular references between declarations and everything will be fine.
  • Only errors are reported by the static check, no warnings have been implemented.

Running tests

There are two test suites, Unit and Integration you can run both with vendor/bin/phpunit.

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-only
  • 更新时间: 2016-12-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固