2017 © Pedro Peláez
 

library abbrev

Create unambiguous abbreviations for words in a list

image

ifcanduela/abbrev

Create unambiguous abbreviations for words in a list

  • Thursday, June 22, 2017
  • by ifcanduela
  • Repository
  • 1 Watchers
  • 0 Stars
  • 57 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

Abbrev

Find unambiguous abbreviations for all words in a list., (*1)

Just like npm's abbrev, which is just like ruby's Abbrev., (*2)

Installation

Use composer:, (*3)

composer install ifcanduela/abbrev

Usage

Feed a word list to the Abbrev constructor and then call one of the three public methods., (*4)

Suggestions and matches are case-insensitive. The constructor accepts any number of strings or arrays of strings, arbitrarily nested. Once you have an instance it's ready to go., (*5)

use ifcanduela\abbrev\Abbrev;

$abbrev = new Abbrev(
        'foo',
        'bar',
        ['baz', 'foobar', ['barbaz']],
    );

Abbrev::match($word)

Get a matching word from the list, or false if the input is ambiguous., (*6)

$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)

Get a list of matching words from the list for an ambiguous or unambiguous input., (*7)

$abbrev = new Abbrev(['ape', 'aperture', 'apprentice'], 'albino', 'append');

$suggestions = $abbrev->suggest('app');
// append
// apprentice

Abbrev::abbreviate()

Retrieve a list of all possible abbreviations., (*8)

$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',
// ]

The Versions

22/06 2017

dev-master

9999999-dev

Create unambiguous abbreviations for words in a list

  Sources   Download

MIT

The Development Requires

by Igor F. Canduela

22/06 2017

1.0.0

1.0.0.0

Create unambiguous abbreviations for words in a list

  Sources   Download

MIT

The Development Requires

by Igor F. Canduela