ifcanduela / abbrev
为列表中的单词创建明确的缩写
1.0.0
2017-06-22 06:57 UTC
Requires (Dev)
- phpunit/phpunit: ^6.2
This package is auto-updated.
Last update: 2024-09-12 22:50:25 UTC
README
为列表中的所有单词找到明确的缩写。
类似于npm的abbrev,它类似于ruby的Abbrev。
安装
使用composer
composer install ifcanduela/abbrev
用法
将单词列表提供给Abbrev
构造函数,然后调用三个公共方法之一。
建议和匹配不区分大小写。构造函数接受任意数量的字符串或字符串数组,可以任意嵌套。一旦创建了一个实例,它就准备好使用了。
use ifcanduela\abbrev\Abbrev; $abbrev = new Abbrev( 'foo', 'bar', ['baz', 'foobar', ['barbaz']], );
Abbrev::match($word)
从列表中获取匹配的单词,如果输入不明确,则返回false
。
$abbrev = new Abbrev(['ape', 'aperture', 'apprentice'], 'albino', 'append'); $match = $abbrev->match('ap'); // there is not unambiguous match // => false $match = $abbrev->match('al'); // there is only one possible match // => "albino"
Abbrev::suggest($word)
对于不明确或明确的输入,从列表中获取匹配的单词列表。
$abbrev = new Abbrev(['ape', 'aperture', 'apprentice'], 'albino', 'append'); $suggestions = $abbrev->suggest('app'); // append // apprentice
Abbrev::abbreviate()
检索所有可能的缩写列表。
$abbrev = new Abbrev(['ape', 'aperture', 'apprentice'], 'albino', 'append'); $suggestions = $abbrev->abbreviate(); // [ // 'alb' => 'albino', // 'albi' => 'albino', // 'albin' => 'albino', // 'albino' => 'albino', // 'ape' => 'ape', // 'aper' => 'aperture', // 'apert' => 'aperture', // 'apertu' => 'aperture', // 'apertur' => 'aperture', // 'aperture' => 'aperture', // 'appe' => 'append', // 'appen' => 'append', // 'append' => 'append', // 'appr' => 'apprentice', // 'appre' => 'apprentice', // 'appren' => 'apprentice', // 'apprent' => 'apprentice', // 'apprenti' => 'apprentice', // 'apprentic' => 'apprentice', // 'apprentice' => 'apprentice', // ]