wikimedia/ipa-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

wikimedia/ipa-validator

最新稳定版本:v1.1.1

Composer 安装命令:

composer require wikimedia/ipa-validator

包简介

Composer package for validating and normalizing IPA

README 文档

README

Basic usage

// Load composer's autoloader
require_once __DIR__ . '/vendor/autoload.php';

// Load the validator
use Wikimedia\IPAValidator\Validator;

/*
* Create a new validator with the options:
*  - Remove delimiters (defaults to true)
*  - Normalize IPA (defaults to false)
*  - Normalize to Google TTS standard (defaults to false)
*/
$validator = new Validator( '/pʰə̥ˈkj̊uːliɚ/', true, true, true );

// Check if the IPA is valid
echo $validator->valid;  # true

// Get the normalized IPA
echo $validator->normalizedIPA;  # phəˈkjuːliɚ

// Get the original IPA
echo $validator->originalIPA;  # /pʰə̥ˈkj̊uːliɚ/

Options

When constructing a new Validator, you can set the following options:

/**
 * Constructor
 *
 * @param string $ipa IPA to validate
 * @param bool $strip Remove delimiters
 * @param bool $normalize Normalize IPA
 * @param bool $google Normalize IPA for Google TTS
 */
public function __construct( $ipa, $strip = true, $normalize = false, $google = false )

Remove delimiters

This option will remove some delimiters from the IPA — currently /.../ and [...]

Normalize IPA

When $google is false, this option will normalize the IPA and remove commonly mistaken unicode characters (for example, using : instead of ː in a word such as tenoːt͡ʃˈtit͡ɬan).

Normalize IPA for Google TTS

As part of a work project, we're feeding IPA to Google's TTS engine — Google is a little opinionated about things like diacritics. For example, the IPA ˈɔːfɫ̩ would not render correctly in Google TTS. A custom charmap is used to normalize certain characters:

$charmap = [
    [ '(', '' ],
    [ ')', '' ],
    // 207F
    [ '', 'n' ],
    // 02B0
    [ 'ʰ', 'h' ],
    // 026B
    [ 'ɫ', 'l' ],
    // 02E1
    [ 'ˡ', 'l' ],
    // 02B2
    [ 'ʲ', 'j' ],
];

Setting $google to true also removes all diacritics from the IPA string.

The Regex

^[().a-z|æçðøħŋœǀ-ǃɐ-ɻɽɾʀ-ʄʈ-ʒʔʕʘʙʛ-ʝʟʡʢʰʲʷʼˀˈˌːˑ˞ˠˡˤ-˩̴̘̙̜̝̞̟̠̤̥̩̪̬̯̰̹̺̻̼̀́̂̃̄̆̈̊̋̌̏̽̚͜͡βθχ᷄᷅᷈‖‿ⁿⱱ]+$

I've also placed it at https://regex101.com/r/f2Qhuk if you think you can improve it... (please do!)

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 22
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固