Files
fil/docs/snippets/swift/plugins/word_count_processor.md

50 lines
1.1 KiB
Markdown
Raw Normal View History

2026-06-01 23:40:55 +02:00
```swift title="Swift"
import Kreuzberg
final class WordCountProcessor: PostProcessor {
func name() -> String {
"word_count"
}
func version() -> String {
"1.0.0"
}
func processingStage() -> String {
"early"
}
func priority() -> Int32 {
50
}
func process(result: ExtractionResult, config: ExtractionConfig) -> String {
let content = result.content()
let words = content.split(separator: " ").count
// Metadata is not directly mutable via the FFI, so store in logs or use
// a side-channel approach. For now, just track that processing happened.
return "{\"ok\": null}"
}
func shouldProcess(result: ExtractionResult, config: ExtractionConfig) -> Bool {
!result.content().isEmpty
}
func estimatedDurationMs(result: ExtractionResult) -> UInt64 {
5
}
func initialize() -> String {
"{\"ok\": null}"
}
func shutdown() -> String {
"{\"ok\": null}"
}
}
let processor = WordCountProcessor()
try Kreuzberg.registerPostProcessor(processor)
```