worthwelle/alphonic

A library for converting strings into and from phonetic spellings for use over the phone, a radio or other unclear communications channels. Alphonic provides these conversions not only using the standard NATO alphabet, but also various other phonetic alphabets, making it perfect for easily convertin

v0.1.0 2020-01-03 20:39 UTC

This package is auto-updated.

Last update: 2024-10-29 06:18:29 UTC


README

Build Status Latest Stable Version Total Downloads

A library for converting strings into and from phonetic spellings for use over the phone, a radio or other unclear communications channels. Alphonic provides these conversions not only using the standard NATO alphabet, but also various other phonetic alphabets, making it perfect for easily converting strings with historical accuracy.

Important note

The alphabets in this library are provided not only as-is, but also as-were. That is, these alphabets are provided as they were originally defined. This means that the characters supported by each alphabet differ. Some alphabets cover only the classical Latin alphabet, some include numbers, some include language-specific Latin characters (such as the various letters with diacritical marks), and some include punctuation and figure-specific characters.

These limitations can be overcome using the add_symbol function, which allows adding characters to a particular alphabet on a one-time-only basis. To fill in only missing symbols in multiple alphabets, the add_symbol or add_symbols functions can be used with $overwrite set to false. This will, naturally, be a non-standard use of the alphabet.

More information on creating custom alphabets will be available in the near future.

Installation

Library

git clone https://github.com/worthwelle/alphonic.git

Composer

Install PHP Composer

composer require worthwelle/alphonic

Usage

Load pre-configured alphabets

<?php

$alphonic = new Alphonic();
$alphonic->load_alphabets();
$alphonic->alphabet("NATO")->add_symbol(" ","|");
$alphonic->alphabet("NATO")->add_symbol(",","Comma");
$alphonic->alphabet("NATO")->add_symbol("!","Exclamation");

echo $output = $alphonic->phonetify("Holy alphabets, Batman!", "NATO");
// Hotel Oscar Lima Yankee | Alfa Lima Papa Hotel Alfa Bravo Echo Tango Sierra Comma | Bravo Alfa Tango Mike Alfa November Exclamation
echo $alphonic->unphonetify($output, "NATO");
// HOLY ALPHABETS, BATMAN!

Load a custom alphabet

<?php

$alphonic = new Alphonic();
$alphonic->load_alphabet_from_file('myalphabet.json');
$alphonic->load_alphabet_from_json(file_get_contents('myotheralphabet.json');

// The second argument allows Alphonic to skip alphabets that don't pass validation.
// This defaults to false.
$alphonic2 = new Alphonic('directory/full/of/alphabets', true);

Configuration Options

Known Issues

  • Localizations are currently not supported and alphabets require titles and symbols utilizing the "en" localization.
  • During early development the JSON schema is likely to change without notice. Once v1.0 is formalized, this will become the standard going forward.

Running the tests

composer test                            # run all unit tests
composer test-timing                     # report the runtime of each test into an XML file
composer coverage                        # run unit tests and report code coverage
composer coverage-report                 # run unit tests and provide a thorough code coverage report
composer testOnly TestClass              # run specific unit test class
composer testOnly TestClass::testMethod  # run specific unit test method
composer style-check                     # check code style for errors
composer style-fix                       # automatically fix code style errors

Contributing

Alphabets

Currently supported alphabets: