Module: Legion::Extensions::Synapse::Runners::Crystallize

Includes:
Helpers::Lex
Included in:
Actor::Crystallize, Client
Defined in:
lib/legion/extensions/synapse/runners/crystallize.rb

Constant Summary collapse

EMERGENCE_THRESHOLD =
20

Instance Method Summary collapse

Instance Method Details

#crystallize(signal_pairs: [], threshold: EMERGENCE_THRESHOLD) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/legion/extensions/synapse/runners/crystallize.rb', line 13

def crystallize(signal_pairs: [], threshold: EMERGENCE_THRESHOLD)
  Data::Model.define_synapse_model
  created = []

  signal_pairs.each do |pair|
    next if pair[:count] < threshold
    next if synapse_exists?(pair[:source_function_id], pair[:target_function_id])

    synapse = Data::Model::Synapse.create(
      source_function_id: pair[:source_function_id],
      target_function_id: pair[:target_function_id],
      origin:             'emergent',
      confidence:         Helpers::Confidence.starting_score(:emergent),
      status:             'observing'
    )
    created << { id: synapse.id, source: pair[:source_function_id], target: pair[:target_function_id] }
  end

  { success: true, created: created, count: created.size }
end