Class: Phronomy::Splitter::Base
- Inherits:
-
Object
- Object
- Phronomy::Splitter::Base
- Defined in:
- lib/phronomy/splitter/base.rb
Overview
Abstract base class for text splitters.
A splitter takes a single document hash (or plain text) and returns an array of smaller chunk documents:
[{ text: String, metadata: Hash }, ...]
Subclasses must implement #split.
Direct Known Subclasses
Instance Method Summary collapse
-
#split(document) ⇒ Array<Hash>
Split +document+ into an array of chunk documents.
-
#split_all(documents) ⇒ Array<Hash>
Convenience method: split an array of documents.
Instance Method Details
#split(document) ⇒ Array<Hash>
Split +document+ into an array of chunk documents.
22 23 24 |
# File 'lib/phronomy/splitter/base.rb', line 22 def split(document) raise NotImplementedError, "#{self.class}#split is not implemented" end |
#split_all(documents) ⇒ Array<Hash>
Convenience method: split an array of documents.
31 32 33 |
# File 'lib/phronomy/splitter/base.rb', line 31 def split_all(documents) documents.flat_map { |doc| split(doc) } end |