Class: FactDb::Pipeline::ResolutionPipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/fact_db/pipeline/resolution_pipeline.rb

Overview

Pipeline for resolving entities and facts using SimpleFlow Supports parallel resolution of multiple items

Examples:

Resolve entities in parallel

pipeline = ResolutionPipeline.new(config)
results = pipeline.resolve_entities(["John Smith", "Jane Doe", "Acme Corp"])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = FactDb.config) ⇒ ResolutionPipeline

Returns a new instance of ResolutionPipeline.



17
18
19
20
21
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 17

def initialize(config = FactDb.config)
  @config = config
  @entity_resolver = Resolution::EntityResolver.new(config)
  @fact_resolver = Resolution::FactResolver.new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



15
16
17
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15

def config
  @config
end

#entity_resolverObject (readonly)

Returns the value of attribute entity_resolver.



15
16
17
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15

def entity_resolver
  @entity_resolver
end

#fact_resolverObject (readonly)

Returns the value of attribute fact_resolver.



15
16
17
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 15

def fact_resolver
  @fact_resolver
end

Instance Method Details

#detect_conflicts(entity_ids) ⇒ Array<Hash>

Find and resolve conflicts for multiple entities in parallel

Parameters:

  • entity_ids (Array<Integer>)

    Entity IDs to check for conflicts

Returns:

  • (Array<Hash>)

    Conflict detection results



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 49

def detect_conflicts(entity_ids)
  pipeline = build_conflict_detection_pipeline(entity_ids)
  initial_result = SimpleFlow::Result.new(entity_ids: entity_ids, conflicts: {})

  final_result = pipeline.call(initial_result)

  entity_ids.map do |entity_id|
    conflicts = final_result.value[:conflicts][entity_id]
    {
      entity_id: entity_id,
      conflicts: conflicts || [],
      conflict_count: conflicts&.size || 0
    }
  end
end

#resolve_entities(names, kind: nil) ⇒ Array<Hash>

Resolve multiple entity names in parallel

Parameters:

  • names (Array<String>)

    Entity names to resolve

  • kind (Symbol, nil) (defaults to: nil)

    Entity kind filter

Returns:

  • (Array<Hash>)

    Resolution results



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fact_db/pipeline/resolution_pipeline.rb', line 28

def resolve_entities(names, kind: nil)
  pipeline = build_entity_resolution_pipeline(names, kind)
  initial_result = SimpleFlow::Result.new(names: names, resolved: {})

  final_result = pipeline.call(initial_result)

  names.map do |name|
    resolution = final_result.value[:resolved][name]
    {
      name: name,
      entity: resolution&.dig(:entity),
      status: resolution&.dig(:status) || :failed,
      error: resolution&.dig(:error)
    }
  end
end