Class: DwcAgent::Similarity

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc_agent/similarity.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimilarity

Returns a new instance of Similarity.



11
12
# File 'lib/dwc_agent/similarity.rb', line 11

def initialize
end

Class Method Details

.instanceObject



6
7
8
# File 'lib/dwc_agent/similarity.rb', line 6

def instance
  Thread.current[:dwc_agent_similarity] ||= new
end

Instance Method Details

#similarity_score(given1, given2) ⇒ Float

Produces a similarity score of two given names Logic inspired by R.D.M. Page, orcid.org/0000-0002-7101-9767 At linen-baseball.glitch.me/

Parameters:

  • given1 (String)

    one given name

  • given2 (String)

    a second given name

Returns:

  • (Float)

    the similarity score



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dwc_agent/similarity.rb', line 21

def similarity_score(given1, given2)
  given1.gsub!(/\.\s+/,".")
  g1_arr = given1.split(/[\.\s]/)
  given2.gsub!(/\.\s+/,".")
  g2_arr = given2.split(/[\.\s]/)
  largest = [g1_arr,g2_arr].max
  smallest = [g1_arr,g2_arr].min

  score = 0
  largest.each_with_index do |val,index|
    if smallest[index]
      if val[0] == smallest[index][0]
        score += 1
      else
        return 0
      end
      if val.length > 1 && smallest[index].length > 1 && !val.include?(smallest[index])
        return 0
      end
    else
      score += 0.1
    end
  end

  score
end