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.
21 22 23 |
# File 'lib/phronomy/splitter/base.rb', line 21 def split(document) raise NotImplementedError, "#{self.class}#split is not implemented" end |
#split_all(documents) ⇒ Array<Hash>
Convenience method: split an array of documents.
29 30 31 |
# File 'lib/phronomy/splitter/base.rb', line 29 def split_all(documents) documents.flat_map { |doc| split(doc) } end |