Class: FactDb::Extractors::ManualExtractor
- Defined in:
- lib/fact_db/extractors/manual_extractor.rb
Overview
Manual fact extractor for API-driven fact creation
Passes through user-provided text as a single fact without any automated extraction. Used when the user provides fact text and metadata directly via the API.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#create_entity(name:, type:, aliases: [], attributes: {}) ⇒ Hash
Creates an entity hash.
-
#create_fact(text:, valid_at:, invalid_at: nil, mentions: [], confidence: 1.0, metadata: {}) ⇒ Hash
Creates a single fact with full control over all attributes.
-
#extract(text, context = {}) ⇒ Array<Hash>
Extracts a single fact from the provided text.
-
#extract_entities(text) ⇒ Array
Returns empty array since manual extraction expects entities to be provided.
Methods inherited from Base
available_types, #extraction_method, for, #initialize
Constructor Details
This class inherits a constructor from FactDb::Extractors::Base
Instance Method Details
#create_entity(name:, type:, aliases: [], attributes: {}) ⇒ Hash
Creates an entity hash
Convenience method for building entity data manually.
83 84 85 86 87 88 89 90 |
# File 'lib/fact_db/extractors/manual_extractor.rb', line 83 def create_entity(name:, type:, aliases: [], attributes: {}) build_entity( name: name, type: type, aliases: aliases, attributes: attributes ) end |
#create_fact(text:, valid_at:, invalid_at: nil, mentions: [], confidence: 1.0, metadata: {}) ⇒ Hash
Creates a single fact with full control over all attributes
Convenience method that wraps #extract with named parameters.
64 65 66 67 68 69 70 71 72 |
# File 'lib/fact_db/extractors/manual_extractor.rb', line 64 def create_fact(text:, valid_at:, invalid_at: nil, mentions: [], confidence: 1.0, metadata: {}) extract(text, { valid_at: valid_at, invalid_at: invalid_at, mentions: mentions, confidence: confidence, metadata: }).first end |
#extract(text, context = {}) ⇒ Array<Hash>
Extracts a single fact from the provided text
Returns the text as-is without parsing. All metadata comes from context.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fact_db/extractors/manual_extractor.rb', line 28 def extract(text, context = {}) return [] if text.nil? || text.strip.empty? valid_at = context[:valid_at] || context[:captured_at] || Time.current [ build_fact( text: text, valid_at: valid_at, invalid_at: context[:invalid_at], mentions: context[:mentions] || [], confidence: context[:confidence] || 1.0, metadata: context[:metadata] || {} ) ] end |
#extract_entities(text) ⇒ Array
Returns empty array since manual extraction expects entities to be provided
49 50 51 |
# File 'lib/fact_db/extractors/manual_extractor.rb', line 49 def extract_entities(text) [] end |