Class: FactDb::Extractors::Base Abstract
- Inherits:
-
Object
- Object
- FactDb::Extractors::Base
- Defined in:
- lib/fact_db/extractors/base.rb
Overview
Subclass and override #extract and #extract_entities to implement.
Abstract base class for fact extractors
Provides common interface and helper methods for extracting facts and entities from text. Subclasses must implement #extract and #extract_entities.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ FactDb::Config
readonly
The configuration object.
Class Method Summary collapse
-
.available_types ⇒ Array<Symbol>
Returns list of available extractor types.
-
.for(type, config = FactDb.config) ⇒ Base
Factory method to create an extractor by type.
Instance Method Summary collapse
-
#extract(text, context = {}) ⇒ Array<Hash>
abstract
Extracts facts from text.
-
#extract_entities(text) ⇒ Array<Hash>
abstract
Extracts entities from text.
-
#extraction_method ⇒ String
Returns the extraction method name derived from class name.
-
#initialize(config = FactDb.config) ⇒ Base
constructor
Initializes a new extractor.
Constructor Details
Instance Attribute Details
#config ⇒ FactDb::Config (readonly)
Returns the configuration object.
25 26 27 |
# File 'lib/fact_db/extractors/base.rb', line 25 def config @config end |
Class Method Details
.available_types ⇒ Array<Symbol>
Returns list of available extractor types
88 89 90 |
# File 'lib/fact_db/extractors/base.rb', line 88 def available_types %i[manual llm rule_based] end |
.for(type, config = FactDb.config) ⇒ Base
Factory method to create an extractor by type
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fact_db/extractors/base.rb', line 72 def for(type, config = FactDb.config) case type.to_sym when :manual ManualExtractor.new(config) when :llm LLMExtractor.new(config) when :rule_based RuleBasedExtractor.new(config) else raise ArgumentError, "Unknown extractor type: #{type}" end end |
Instance Method Details
#extract(text, context = {}) ⇒ Array<Hash>
Subclass and override this method
Extracts facts from text
41 42 43 |
# File 'lib/fact_db/extractors/base.rb', line 41 def extract(text, context = {}) raise NotImplementedError, "#{self.class} must implement #extract" end |
#extract_entities(text) ⇒ Array<Hash>
Subclass and override this method
Extracts entities from text
51 52 53 |
# File 'lib/fact_db/extractors/base.rb', line 51 def extract_entities(text) raise NotImplementedError, "#{self.class} must implement #extract_entities" end |
#extraction_method ⇒ String
Returns the extraction method name derived from class name
58 59 60 |
# File 'lib/fact_db/extractors/base.rb', line 58 def extraction_method self.class.name.split("::").last.sub("Extractor", "").underscore end |