hollodotme/cologne-phonetic
Composer 安装命令:
composer require hollodotme/cologne-phonetic
包简介
PHP OOP Implementation of the 'Kölner Phonetic Index' - a soundex like algorithm for german language
README 文档
README
ColognePhonetic
A PHP OOP implementation of the "Kölner Phonetik Index".
This is an adaption of Andy Theiler's precedural implementation with some fixes and unit tests.
Requirements
- "PHP" >= "5.5"
- "ext-iconv" "*"
Installation
composer require "hollodotme/cologne-phonetic" "~1.0.0"
Basic usage
<?php use hollodotme\ColognePhonetic\ColognePhonetic; $inputCharset = 'UTF-8'; $colognePhonetic = new ColognePhonetic( $inputCharset ); # Retrieve index for a single word $wordIndex = $colognePhonetic->getWordIndex( 'Wort' ); var_dump( $wordIndex ); # Retrieve index for a phrase (multiple words) # Phrase is split into words, returns an assoc. array with [ "word" => "index" ] $phraseIndex = $colognePhonetic->getPhraseIndex( 'Ein Satz mit mehreren Wörtern' ); var_dump( $phraseIndex );
Output:
string(3) "072"
array(5) {
'Ein' =>
string(2) "06"
'Satz' =>
string(1) "8"
'mit' =>
string(2) "62"
'mehreren' =>
string(3) "676"
'Wortern' =>
string(5) "07276"
}
Algorithm
The "Kölner Phonetik" transliterates every character of a word to a numeric code between "0" und "8", considering at most one adjacent character as context. Some rules apply especially to the beginning of a word (initial sound). This way similar phonems get mapped to the same numeric code. For example the caracters "W" and "V" are both transliterated to "3". The phonetic code of "Wikipedia" is "3412". In contrast to the "Soundex-Code" the length of the "Kölner Phonetik Index" is not restricted.
| Character | Context | Code |
|---|---|---|
| A, E, I, J, O, U, Y | 0 | |
| H | - | |
| B | 1 | |
| P | not before H | 1 |
| D, T | not before C, S, Z | 2 |
| F, V, W | 3 | |
| P | before H | 3 |
| G, K, Q | 4 | |
| C | initial sound before A, H, K, L, O, Q, R, U, X | 4 |
| C | before A, H, K, O, Q, U, X but not after S, Z | 4 |
| X | not after C, K, Q | 48 |
| L | 5 | |
| M, N | 6 | |
| R | 7 | |
| S, Z | 8 | |
| C | after S, Z | 8 |
| C | initial sound but not before A, H, K, L, O, Q, R, U, X | 8 |
| C | not before A, H, K, O, Q, U, X | 8 |
| D, T | before C, S, Z | 8 |
| X | after C, K, Q | 8 |
The fact that "SC" has priority before "CH" is explained in the addition "but not after" on line 10 in the table above. This rule was not explicitly part of the official publication, but can be deduced implicitly from the published examples.
The transliteration happens in 3 steps:
- Transliteration of characters from left to right like described in the table above.
- Removing all duplicate codes.
- Removing of all "0" codes except at the beginning.
hollodotme/cologne-phonetic 适用场景与选型建议
hollodotme/cologne-phonetic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.66k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 hollodotme/cologne-phonetic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hollodotme/cologne-phonetic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 27.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-07