Class: Linkage::MatchSet Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/linkage/match_set.rb

Overview

This class is abstract.

A MatchSet is responsible for keeping track of matches. After the scoring process, a Matcher uses scores from a ScoreSet to calculate which record pairs match. Those pairs are then recorded by a MatchRecorder to a MatchSet.

MatchSet is the superclass of implementations for different formats. Currently there are two formats for storing matches:

See the documentation for match set you're interested in for more information.

If you want to implement a custom MatchSet, create a class that inherits MatchSet and defines at least #add_match. You can then register that class via MatchSet.register.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.klass_for(name) ⇒ Class? Also known as: []

Return a registered MatchSet subclass or nil if it doesn't exist.

Parameters:

  • name (String)

    of registered match set

Returns:

  • (Class, nil)


42
43
44
# File 'lib/linkage/match_set.rb', line 42

def klass_for(name)
  @match_sets ? @match_sets[name] : nil
end

.register(name, klass) ⇒ Object

Register a new match set. Subclasses must define at least #add_match, otherwise an ArgumentError will be raised.

Parameters:

  • name (String)

    Match set name used in klass_for

  • klass (Class)

    MatchSet subclass



28
29
30
31
32
33
34
35
36
# File 'lib/linkage/match_set.rb', line 28

def register(name, klass)
  methods = klass.instance_methods(false)
  unless methods.include?(:add_match)
    raise ArgumentError, "class must define #add_match"
  end

  @match_sets ||= {}
  @match_sets[name] = klass
end

Instance Method Details

#add_match(id_1, id_2, score) ⇒ Object

This method is abstract.

Add a match to the MatchSet. Subclasses must redefine this.

Parameters:

  • id_1 (Object)

    record id from first dataset

  • id_2 (Object)

    record id from second dataset

  • value (Fixnum, Float)

    match value

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/linkage/match_set.rb', line 60

def add_match(id_1, id_2, score)
  raise NotImplementedError
end

#closeObject

This is called by Linkage::MatchRecorder#stop, after all matches have been added. Subclasses can redefine this to perform any teardown needed.



66
67
# File 'lib/linkage/match_set.rb', line 66

def close
end

#open_for_writingObject

This is called by Linkage::MatchRecorder#start, before any matches are added via #add_match. Subclasses can redefine this to perform any setup needed for saving matches.



51
52
# File 'lib/linkage/match_set.rb', line 51

def open_for_writing
end