feat: add EntryWarnings and VocabularyBuilder
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user