feat: add EntryWarnings and VocabularyBuilder

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 15:11:48 +02:00
co-authored by Claude Sonnet 5.5
parent 93bf59e090
commit fe24292279
4 changed files with 165 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import Foundation
/// The short word list handed to the speech engine as context.
public enum VocabularyBuilder {
/// Terms first (file order), then the unique right-hand sides of correction pairs; at most `maxTerms` words.
public static func build(from entries: [DictionaryEntry], maxTerms: Int = 24) -> [String] {
var out: [String] = []
var seen = Set<String>()
func add(_ word: String) {
let key = word.lowercased()
guard !word.isEmpty, !seen.contains(key) else { return }
seen.insert(key)
out.append(word)
}
for entry in entries { if case .term(let term) = entry.kind { add(term) } }
for entry in entries { if case .correction(_, let wrote) = entry.kind { add(wrote) } }
return Array(out.prefix(maxTerms))
}
}