Repository navigation
Releases
Releases · iliaal/phonetic
0.5.0
Added
- Prebuilt PHP 8.6 binaries attached to releases: Linux (glibc x86_64 and arm64), macOS (arm64), and Windows DLLs (x64 and x86, TS and NTS).
Fixed
- BMPM preserves the combining dot when lowercasing Turkish capital
İ, matching Commons Codec rule contexts and encodings (for example,İhsan).bmpm_match()uses the corrected encoding; DM Soundex is unchanged.
Performance
- BMPM extends phonemes in place for rules with one alternative and no language restriction, reuses one builder across each final pass, finds ASCII rule buckets and rulesets through tables built at startup, and sorts final sets of up to 32 phonemes by insertion.
bmpm()andbmpm_match()take 10-23% less time on a list of Latin-script surnames (Linux x86-64; GCC 12 and 14, Clang 18). Encodings, matches, and budget errors are unchanged. - BMPM rule contexts are classified and parsed once at startup instead of on every candidate rule match, and language guessing tests a rule's required letters with one bitmask check.
bmpm()andbmpm_match()take about 10-20% less time on Latin-script surnames. Matching rules are unchanged;tests/bmpm_corpus_digest.phptpins the encodings of a generated corpus for each name type and accuracy, and for each named forced language at approximate accuracy. - BMPM language guessing skips rules whose required non-ASCII letters are absent from the input, as it already did for ASCII letters.
bmpm()runs 15-25% faster on Latin-script surnames and 40-55% faster on accented and Cyrillic names; encoded output is unchanged. - Daitch-Mokotoff Soundex orders each first-byte rule bucket longest-first at startup, allowing encoding to stop at the first matching pattern. Encoded codes, branch order, matching behavior, and resource limits are unchanged.
- Daitch-Mokotoff Soundex compares rule patterns inline after the bucket's first byte, and compares and hashes branch codes as one zero-padded 8-byte word instead of with
strcmp()and a per-byte FNV-1a hash.dm_soundex()anddm_soundex_match()take about 13-20% less time on name lists. Codes, branch order, matches, work-budget errors, the input byte cap, and the 128-branch cap are unchanged;tests/dm_soundex_corpus_digest.phptpins the codes and matches of a generated corpus. - Daitch-Mokotoff Soundex keeps the cleaned input in a 256-byte stack buffer and each branch set's first 8 branches inline, and tracks code-alternative lengths instead of calling
strlen(),memcmp(), andstrcmp()on replacements of at most 3 characters.dm_soundex()anddm_soundex_match()take about 15-21% less time on name lists. Longer cleaned inputs and larger sets move to heap storage. Codes, branch order, matches, work-budget errors, the input byte cap, and the 128-branch cap are unchanged;tests/dm_soundex_corpus_digest.phptpins the codes and matches of a generated corpus. - NYSIIS uses stack scratch space for inputs shorter than 128 bytes, avoiding a temporary heap allocation in both
nysiis()andnysiis_match(). Longer inputs keep the heap-backed path; encoded keys and length limits are unchanged. bmpm_match()compares a single indexed phonetic token directly instead of building a hash table, avoiding temporary table and token-key allocations. Grouped output and exact token boundaries retain the same matching behavior.- Double Metaphone folds input and builds both codes in 128-byte stack buffers that move to the heap only when they fill, and
double_metaphone()inserts itsprimaryandalternatekeys as strings interned at startup.double_metaphone()anddouble_metaphone_match()take about 42-45% less time on name lists. Codes and match results are unchanged;tests/double_metaphone_corpus_digest.phptpins them for a generated corpus at several code lengths.
0.4.6
Fixed
- The 0.4.5 prebuilt Linux and macOS binaries failed on PHP 8.4 releases before 8.4.27 and PHP 8.5 releases before 8.5.12 with
undefined symbol: smart_str_ferealloc, because they were compiled against newer PHP headers. Prebuilt binaries are now compiled against the oldest patch release of each PHP minor (8.4.1 and 8.5.0), and the release workflow rejects a binary that imports a symbol that release does not export or that fails to load and run on the oldest and newest patch. Source builds were unaffected.
0.4.5
Performance
- Double Metaphone encodes directly from its padded folding buffer instead of allocating a second full-input copy. Both the encoder and match helper retain their existing keys, matching rules, and folded-input limit.
Fixed
bmpm_match()no longer treats identical prefixed inputs as a match when their encoding contains only empty prefix groups, with no phonetic tokens. Regression coverage:tests/bmpm_match_empty_prefix.phpt.- CI test guards preserve failing runner exit statuses in ASAN and Windows jobs, including the Windows release build, even after a passing test summary.
0.4.4
Changed
bmpm()/bmpm_match(): resource-budget overruns now throw catchableValueErrorexceptions instead of terminating the request withE_ERROR. Callers can catch the exception and continue; normalfinallyblocks and object cleanup run. Short inputs can still exceed a budget.- Match Rating streams encoding into a six-byte codex, using constant temporary memory even for long inputs in
match_rating()andmatch_rating_compare(). - Daitch-Mokotoff Soundex stops applying rules once every branch has its final six digits, avoiding unnecessary suffix work without changing code order.
- Daitch-Mokotoff Soundex reuses unchanged branch transitions for repeated branching rules, avoiding repeated work while preserving code order and the 4096-byte input limit.
dm_soundex()/dm_soundex_match(): capped executed branch/replacement expansions at 32,768 per encoded operand, excluding reused transitions. Inputs that exceed this budget now throw catchableValueErrorexceptions without returning partial codes. Match operands have independent budgets; in-budget encodings retain their code order and 128-branch cap.- NYSIIS stops transcoding once the requested key prefix is stable, avoiding unnecessary suffix work while preserving final cleanup and unlimited output.
- NYSIIS compacts its key in the existing cleaned-input buffer, avoiding a second input-sized temporary allocation without changing encoded keys.
Fixed
bmpm()/bmpm_match(): capped serialized output at 256 times the original input byte length, including separators and prefix punctuation. Each match operand has its own cap. Oversized output raisesValueErrorwithout returning a partial encoding.- Documented the exact BMPM resource counters and corrected the vendored Hebrew helper-file description: no loaded rule set includes those files.
- The arginfo consistency guard rejects octal, nonliteral, incomplete, or duplicate BMPM accuracy declarations instead of accepting decimal-looking values.
bmpm()/bmpm_match()/dm_soundex()/dm_soundex_match(): fold the Unicode KELVIN SIGN (U+212A) to lowercase ASCIIk, matching Commons Codec.
0.4.3
0.4.2
Changed
bmpm_match(): each operand gets a full per-encode work allowance instead of sharing one budget, so two individually-legal inputs no longer fail together. -dm_soundex()/dm_soundex_match(): branch-set saturation keeps the first 128 distinct codes (deterministic) instead of raisingE_ERROR. - Rule data: Daitch-Mokotoff tables moved fromsrc/bmpm_data.hto generatedsrc/dm_data.h(contents identical); the generator validates language rows. - Oracle parity matrix grows to 684 rows with a forced-language BMPM mode.
Fixed
- CI: warning gate no longer masks
makefailures; Windows job fails closed on all-SKIP;timeout-minuteseverywhere; warnings gated on macOS and Windows. - Parity checker: fixture tests for every fail-closed guard; exact oracle pins in budget tests; golden regen-and-diff runs in CI. - Docs: MRA identical-raw exception, stub@throws/fatal notes, deadJadvance removed fromdouble_metaphone()(no behavior change).
0.4.1
Security
svgTo*()reject caller SVG whose element-count times output-pixels exceeds a render-work budget (CPU exhaustion past the complexity caps).- Dashed strokes with non-finite or float32-frozen segment lengths no longer loop unbounded; a per-path budget caps the dashed clone.
- Curve flattening is bounded per-cubic and per-path, so many non-converging cubics can no longer drive billions of subdivisions.
- A single path
dattribute is capped in element count; the partial prefix still renders (SVG path-data error handling). - The scanline rasterizer no longer truncates the scanline index to 32 bits (out-of-bounds access on path coordinates at multiples of 2^32).
- Decompression-bomb PNGs via
setBackgroundImage()/addIconAt()decode into a fixed IHDR-sized buffer instead of inflating to ~2 GiB. - Scan-less or truncated JPEGs no longer leak recycled worker heap bytes; decoder component planes are zero-initialized.
0.4.0
Changed
- BREAKING:
BMPM_APPROXis now10andBMPM_EXACTis now20(were1and2). The accuracy values are now disjoint from the name-type values (BMPM_GENERIC/BMPM_ASHKENAZI/BMPM_SEPHARDIC=0/1/2), so a misplaced constant such asbmpm($name, BMPM_APPROX)is rejected by argument validation instead of silently running as a name type. Code that uses the constant names is unaffected; only code hard-coding the numeric values1/2for the$accuracyargument needs updating. bmpm()/bmpm_match(): forced$language = "any"now raisesValueError; it is the default ruleset label. Pass an empty string for auto-detect.double_metaphone(): stops encoding once both codes reachmax_length. Same results, less work on long inputs.- Match helpers skip the second encode when the first operand is unencodable or the two operands are identical.
bmpm():BMPM_MAX_PREFIX_DEPTHlowered from 16 to 6, bounding the prefix dual-encode fan-out. Still above realistic name nesting.bmpm()MINIT hard-fails on an oversize generated language list, language bracket, or phoneme alternative list instead of silently clipping it.- Internal BMPM rule-type tokens renamed to
BMPM_RT_APPROX/BMPM_RT_EXACTso they cannot collide with the public accuracy constants. - Shared
PHONETIC_MAX_RULED_INPUT(4096) for BMPM and DM Soundex caps; generatedDMS_CAP_*macros size DM replacement alt buffers. match_rating_compare(): skip second encode when the first cleans to empty.config.w32: require PHP 8.1+ (parity withconfig.m4).- Docs: forced-language API note; Double Metaphone unmapped non-ASCII fold; DM index example queries every non-
000000code; LICENSE Section 2. - CI: PIE smoke pins a false
bmpm_matchand Double Metaphone match strengths; Windows jobs assertphp_phonetic.dllwas produced after the builder step. scripts/check_arginfo.phplocksPH_BMPM_*accuracy ints to the stub; smoke no longer hardcodes the version string; regen_arginfo docs fixed.scripts/regen_arginfo.sh: prefers$HOME/php-install-PHP-8.1/bin/phpwhenPHP_BINis unset; documents tokenizer/gen_stub requirements.
Fixed
double_metaphone(): JOSE/SANJbranch no longer applies the double-J advance (Commons CodechandleJadvances by 1 on that arm only).double_metaphone_match(): a code counts as unencodable only when both the primary and the alternate are empty, so"-EW"(""/"F") still crosses at strength1in either argument order.dm_soundex(): U+0085 is kept, not stripped. Java'sCharacter.isWhitespaceexcludes it, so Commons Codec keeps it too.bmpm()MINIT: zero-initialize ruleset/language indexes so a mid-build abort cannot free garbage pointers on unload.bmpm(): overflow-safe allocation for phoneme-set growth and prefix pair buffers.bmpm(): the final-rule merge sorts once instead of an O(R²) insert-sort, and hashes duplicates only when the phoneme texts are wide enough to pay for it.bmpm(): rule-matching inner loops compare code points inline again; routing 1-3 element compares throughmemcmp()cost 5-6% of encode time.nysiis(): corrected a source comment that claimed parity with Commons Codec'sSoundexUtils.clean; the ASCII-only cleaning is a deliberate restriction.scripts/gen_bmpm_data.php:src/bmpm_data.his written to a temp file and renamed into place, so an interrupted run can't leave a truncated header.- Docs: Cyrillic lowercasing is
bmpm()-only; DM"000000"dual meaning; MRA identity short-circuit; forced-language"any"; NFC vs NFD. - Docs/tests: empty/unencodable match contracts, BMPM validation and accuracy values,
bmpm_matchaccuracy forwarding, and word-finalJalternate space. - Tests: match-helper oracle pins, cleaned-empty identity pins, multi-code
dm_soundex_match, dual-sentinel, MRA first3+last3, SEPHARDIC/anyerrors.
0.3.0
Fixed
double_metaphone(): four rules now follow the published Philips algorithm (thumb0M|TM,high/hughH,joseHS|HS,moochMK).double_metaphone(): leading/trailing whitespace (any byte<= U+0020) is trimmed, so"\tOtto"and"\nKNIGHT"keep their word-start anchors.double_metaphone():-gieruses the French soft-G branch anywhere, not only word-final, sobrigiercodesPRJ|PRJRandangieracodesANJR|ANJR.double_metaphone(): malformed UTF-8 folds byte-wise instead of swallowing the letters after a stray lead byte.- UTF-8 decoding (all encoders): overlong, UTF-16 surrogate, and above-U+10FFFF sequences fold the lead byte to Latin-1 rather than decoding as a code point.
bmpm()anddm_soundex(): U+1E9E (ẞ) folds toß, soSTRAẞEencodes likeStraße.bmpm_match(): token intersection handles the(remainder)-(combined)prefix group syntax, sobmpm_match("van Smith", "Smith")is true.bmpm()/bmpm_match(): a forced$languageis honoured inside the prefix/d'split (deliberate divergence from Commons Codec).bmpm()/bmpm_match(): the invalid-$languageexception preview is binary-safe (non-printables as?) and bounded to 32 bytes.bmpm(): leading/trailing control characters (<= U+0020) are trimmed.dm_soundex_match(): two inputs that match no rule no longer compare equal via the padded"000000"sentinel.- U+0130 (
İ) lower-cases toiinbmpm()anddm_soundex(), soİstanbulmatchesistanbul.
Security
match_rating()andmatch_rating_compare()no longer write past the clean buffer on a bare Latin-10xDFthat expands toSS.bmpm()andbmpm_match()reject input over 4096 bytes with aValueError, matching the Daitch-Mokotoff cap.
Changed
- The five comparison helpers' parameters are named
$a/$b(affects named-argument calls only). composer.jsonlicense is the SPDX expressionBSD-3-Clause AND Apache-2.0(was a disjunctive array).- The README BMPM token-splitting recipe splits on
(,),|,-withPREG_SPLIT_NO_EMPTY, matchingbmpm_match()'s tokenizer. - Performance:
bmpm()decodes input once and pre-parses rules at init; Double Metaphone, Daitch-Mokotoff, and NYSIIS drop per-call allocations.
For contributors
- macOS CI builds with
--enable-phonetic-dev, enforcing the same warning-clean build as Linux. - Generated BMPM table decoding fails module init if a checked-in table exceeds the C buffer caps.
- CI preflights
extension_loaded("phonetic")and fails on any skipped/borked/leaked test, so a silent load failure can't pass green. scripts/pie-smoke.shtreats apie installfailure as fatal (opt out withALLOW_MANUAL_FALLBACK=1).
0.2.0
Added
nysiis(string $string, int $max_length = 6): string. NYSIIS encoder (clean-room), with parity to Apache Commons Codec'sNysiis.$max_length <= 0returns the full, non-truncated key.match_rating(string $string): string. Match Rating Approach codex (clean-room), with parity to Apache Commons Codec.double_metaphone_match(string $a, string $b, int $max_length = 4): int. Double Metaphone match strength:2when the primary keys agree,1when an alternate key crosses,0for no match.bmpm_match(string $a, string $b, int $name_type = BMPM_GENERIC, int $accuracy = BMPM_APPROX, string $language = ""): bool. True when two names share a Beider-Morse phoneme token.dm_soundex_match(string $a, string $b): bool. True when two names share a Daitch-Mokotoff code.nysiis_match(string $a, string $b, int $max_length = 6): bool. True when two names produce the same NYSIIS key.match_rating_compare(string $a, string $b): bool. Match Rating Approach homophone test (isEncodeEquals), applying the length and minimum-rating rules.- Prebuilt binaries attached to releases: Linux (glibc x86_64 and arm64) and macOS (arm64) for PHP 8.4 and 8.5, alongside the existing Windows DLLs.
Fixed
match_rating(): count UTF-8 code points, not bytes, in the trivial-input guard, so a lone multi-byte letter has no code (match_rating("é")is now"").match_rating(): expandßtoSSbefore folding accents, somatch_rating("Straße")returns"STRS".
Security
dm_soundex()anddm_soundex_match(): reject input over 4096 bytes with aValueError, so untrusted long input cannot become a multi-second CPU sink.bmpm(): skip and reject zero-length rule patterns, closing a latent infinite-loop path against a corrupted rule set.
Performance
dm_soundex(): O(1) hashed branch-set dedup for branchy input (threshold-gated so short names keep the linear path), making long input scale linearly.match_rating_compare(): stack scratch buffer in the comparison pass instead of two heap allocations per call.