This commit is contained in:
30
docs/snippets/python/plugins/word_count_processor.md
Normal file
30
docs/snippets/python/plugins/word_count_processor.md
Normal file
@@ -0,0 +1,30 @@
|
||||
```python title="Python"
|
||||
from kreuzberg import register_post_processor, ExtractionResult
|
||||
|
||||
class WordCountProcessor:
|
||||
def name(self) -> str:
|
||||
return "word_count"
|
||||
|
||||
def version(self) -> str:
|
||||
return "1.0.0"
|
||||
|
||||
def processing_stage(self) -> str:
|
||||
return "early"
|
||||
|
||||
def process(self, result: ExtractionResult) -> ExtractionResult:
|
||||
word_count: int = len(result.content.split())
|
||||
result.metadata["word_count"] = word_count
|
||||
return result
|
||||
|
||||
def should_process(self, result: ExtractionResult) -> bool:
|
||||
return bool(result.content)
|
||||
|
||||
def initialize(self) -> None:
|
||||
pass
|
||||
|
||||
def shutdown(self) -> None:
|
||||
pass
|
||||
|
||||
processor: WordCountProcessor = WordCountProcessor()
|
||||
register_post_processor(processor)
|
||||
```
|
||||
Reference in New Issue
Block a user