Class: BplEnrich::Authorities

Inherits:
Object
  • Object
show all
Defined in:
lib/bpl_enrich/authorities.rb

Class Method Summary collapse

Class Method Details

.parse_language(language_value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bpl_enrich/authorities.rb', line 4

def self.parse_language(language_value)
  return_hash = {}
  authority_check = Qa::Authorities::Loc.subauthority_for('iso639-2')
  authority_result = authority_check.search(URI.escape(language_value))

  if authority_result.present?
    authority_result = authority_result.select{|hash| hash['label'].downcase == language_value.downcase || hash['id'].split('/').last.downcase == language_value.downcase }
    if  authority_result.present?
      return_hash[:uri] = authority_result.first["id"].gsub('info:lc', 'http://id.loc.gov')
      return_hash[:label] = authority_result.first["label"]
    end
  end

  return return_hash
end

.parse_name_for_role(name) ⇒ Object



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
73
74
75
76
77
# File 'lib/bpl_enrich/authorities.rb', line 36

def self.parse_name_for_role(name)
  return_hash = {:name=>name}

  #Make sure we have at least three distinct parts of 2-letter+ words. Avoid something like: Steven C. Painter or Painter, Steven C.
  #Possible Issue: Full name of Steven Carlos Painter ?
  potential_role_check = name.to_ascii.match(/[\(\"\',]*\w\w+[\),\"\'\:]* [\w\.,\d\-\"]*[\w\d][\w\d][\w\.,\d\-\"]* [\(\"\',]*\w\w+[\),\"\']*$/) || name.split(/[ ]+/).length >= 4

  if potential_role_check.present?
    authority_check = Qa::Authorities::Loc.subauthority_for('relators')

    #Check the last value of the name string...
    role_value = name.to_ascii.match(/(?<=[\(\"\', ])\w+(?=[\),\"\']*$)/).to_s
    authority_result = authority_check.search(URI.escape(role_value))
    if authority_result.present?

      authority_result = authority_result.select{|hash| hash['label'].downcase == role_value.downcase}
      if  authority_result.present?
        #Remove the word and any other characters around it. $ means the end of the line.
        #
        return_hash[:name] = name.sub(/[\(\"\', ]*\w+[\),\"\']*$/, '').gsub(/^[ ]*:/, '').strip
        return_hash[:uri] = authority_result.first["id"].gsub('info:lc', 'http://id.loc.gov')
        return_hash[:label] = authority_result.first["label"]
      end
    end

    #Check the last value of the name string...
    role_value = name.to_ascii.match(/\w+(?=[\),\"\']*)/).to_s
    authority_result = authority_check.search(URI.escape(role_value))
    if authority_result.present? && return_hash[:uri].blank?

      authority_result = authority_result.select{|hash| hash['label'].downcase == role_value.downcase}
      if  authority_result.present?
        #Remove the word and any other characters around it. $ means the end of the line.
        return_hash[:name] = name.sub(/[\(\"\', ]*\w+[ \),\"\']*/, '').gsub(/^[ ]*\:/, '').strip
        return_hash[:uri] = authority_result.first["id"].gsub('info:lc', 'http://id.loc.gov')
        return_hash[:label] = authority_result.first["label"]
      end
    end
  end

  return return_hash
end

.parse_role(role_value) ⇒ Object

TODO: Research why authority_result = authority_check.search(URI.escape(‘ctb’), ‘relators’) doesn’t work.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bpl_enrich/authorities.rb', line 21

def self.parse_role(role_value)
  return_hash = {}
  authority_check = Qa::Authorities::Loc.subauthority_for('relators')
  authority_result = authority_check.search(URI.escape(role_value))
  if authority_result.present?
    authority_result = authority_result.select{|hash| hash['label'].downcase == role_value.downcase }
    if  authority_result.present?
      return_hash[:uri] = authority_result.first["id"].gsub('info:lc', 'http://id.loc.gov')
      return_hash[:label] = authority_result.first["label"]
    end
  end

  return return_hash
end