uttrflow / uttrflow/uttrflow-swift

Leading quotes change dictionary sound keys and hide otherwise matching entries

Open
#784 0 comments 0 reactions 0 assignees View on GitHub
area:dictation bug P2
Dominant language
Swift
Stars
4
Forks
17
Avg merge
3h 32m
Merged PRs (30d)
277

Description

## Problem

Double Metaphone's initial-vowel and silent-opening rules use the original character offsets. Punctuation is skipped later without adjusting those offsets. As a result, a word beginning with a quotation mark or bracket receives a different phonetic key from the same word without that punctuation.

The dictionary index passes the heard text directly to this encoder. The correction engine's uncertain spans retain the recognizer's punctuation, so an otherwise eligible dictionary entry can disappear from candidate lookup when the recognizer surrounds the word with quotes. This is candidate loss; no claim is made that every such word would have passed the subsequent correction-evidence checks.

## Reproduction

Against unchanged production source in an isolated Swift release test, create one added `DictionaryEntry(word: "Uttrflow", ...)` and a `PhoneticIndex` containing it.

- `candidates(soundingLike: "utterflow")` returns the entry. Its code is `ATRFL`.
- `candidates(soundingLike: "\"utterflow\"")` returns no entries. Its code is `TRFL`.

The same vowel is now at offset 1, so the encoder drops it as though it were an internal vowel. A leading mark also prevents the silent-opening rules from seeing the start of the word.

## Source

Reviewed main at `8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d`.

- [Encoder retains punctuation in its character array](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowDictionary/DoubleMetaphone.swift#L65)
- [Opening rules and vowel offset](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowDictionary/DoubleMetaphone.swift#L130)
- [Index lookup](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowDictionary/PhoneticIndex.swift#L47)
- [Correction candidate lookup](https://github.com/uttrflow/uttrflow-swift/blob/8d93f5b8574f3c7b8c30086d9c817bf7f5d4827d/Sources/UttrflowAI/CorrectionEngine.swift#L40)

## Acceptance criteria

- Make surrounding punctuation irrelevant to phonetic lookup while preserving the original text and marks for output.
- Cover quoted/bracketed vowel-initial words and silent-opening words, checking actual index candidates alongside keys.
- Preserve existing identifier, multiword pronunciation, punctuation-only and numeric fallback behavior. Avoid indiscriminately stripping internal punctuation without defining its effect on those existing cases.

## Existing work checked

#220 covers spellings for which the English encoder emits no sound. Here both forms emit nonempty but inconsistent English keys. #709 concerns Hindi script and normalization. Neither covers surrounding punctuation changing English opening rules.

Contributor guide

Open the contributing guide

Research direction

Start with DoubleMetaphone.swift around lines 65 and 130, then inspect PhoneticIndex.swift line 47 and CorrectionEngine.swift line 40. Run the isolated Swift release reproduction with quoted and bracketed vowel-initial and silent-opening words, checking both phonetic keys and index candidates. Done means surrounding punctuation no longer changes lookup while original text, punctuation, and existing fallback behaviors remain intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
search
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.