Class: Linkage::Runner
- Inherits:
-
Object
- Object
- Linkage::Runner
- Defined in:
- lib/linkage/runner.rb
Overview
Use this class to run a configuration created by Dataset#link_with.
During a record linkage, one or more Comparators generate scores. Each score is recorded by a ScoreRecorder, which uses a ScoreSet to actually save the score. After the scoring is complete, a Matcher combines the scores to create matches. Each match is recorded by a MatchRecorder, which uses a MatchSet to actually save the match information.
So to save scores and matches, we need both a ScoreSet and a MatchSet. To make this easier, a ResultSet can be used to configure both ScoreSets and MatchSets.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(config) ⇒ Runner
constructor
A new instance of Runner.
- #match_records ⇒ Object
- #score_records ⇒ Object
Constructor Details
#initialize(config) ⇒ Runner
Returns a new instance of Runner.
18 19 20 |
# File 'lib/linkage/runner.rb', line 18 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/linkage/runner.rb', line 14 def config @config end |
Instance Method Details
#execute ⇒ Object
22 23 24 25 |
# File 'lib/linkage/runner.rb', line 22 def execute score_records match_records end |
#match_records ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/linkage/runner.rb', line 74 def match_records matcher = config.matcher match_recorder = config.match_recorder(matcher) match_recorder.start matcher.run match_recorder.stop end |
#score_records ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/linkage/runner.rb', line 27 def score_records score_recorder = config.score_recorder score_recorder.start dataset_1 = config.dataset_1 dataset_2 = config.dataset_2 simple_comparators = [] config.comparators.each do |comparator| if comparator.type == :simple simple_comparators << comparator else if dataset_2 comparator.score_datasets(dataset_1, dataset_2) else comparator.score_dataset(dataset_1) end end end # Handle simple comparators unless simple_comparators.empty? if dataset_2 # Two datasets dataset_1.each do |record_1| dataset_2.each do |record_2| simple_comparators.each do |comparator| comparator.score_and_notify(record_1, record_2) end end end else # One dataset # NOTE: very naive implementation records = dataset_1.all 0.upto(records.length - 2) do |i| record_1 = records[i] (i + 1).upto(records.length - 1) do |j| record_2 = records[j] simple_comparators.each do |comparator| comparator.score_and_notify(record_1, record_2) end end end end end score_recorder.stop end |