Module: Bolognese::AuthorUtils
- Included in:
- MetadataUtils
- Defined in:
- lib/bolognese/author_utils.rb
Constant Summary collapse
- IDENTIFIER_SCHEME_URIS =
{ "ORCID" => "https://orcid.org/" }
Instance Method Summary collapse
- #authors_as_string(authors) ⇒ Object
- #cleanup_author(author) ⇒ Object
- #get_affiliations(affiliations) ⇒ Object
-
#get_authors(authors) ⇒ Object
parse array of author strings into CSL format.
- #get_one_author(author) ⇒ Object
- #is_personal_name?(author) ⇒ Boolean
-
#name_exists?(name) ⇒ Boolean
recognize given name if we have loaded ::NameDetector data, e.g.
Instance Method Details
#authors_as_string(authors) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/bolognese/author_utils.rb', line 87 def () Array.wrap().map do |a| if a["familyName"].present? [a["familyName"], a["givenName"]].join(", ") elsif a["type"] == "Person" a["name"] elsif a["name"].present? "{" + a["name"] + "}" end end.join(" and ").presence end |
#cleanup_author(author) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/bolognese/author_utils.rb', line 57 def () return nil unless .present? # titleize strings # remove non-standard space characters .gsub(/[[:space:]]/, ' ') end |
#get_affiliations(affiliations) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/bolognese/author_utils.rb', line 99 def get_affiliations(affiliations) Array.wrap(affiliations).map do |a| affiliation_identifier = nil if a.is_a?(String) name = a.squish affiliation_identifier_scheme = nil scheme_uri = nil else scheme_uri = a["schemeURI"] if a["affiliationIdentifier"].present? affiliation_identifier = a["affiliationIdentifier"] if a["schemeURI"].present? schemeURI = a["schemeURI"].end_with?("/") ? a["schemeURI"] : a["schemeURI"] + "/" end affiliation_identifier = !affiliation_identifier.to_s.start_with?("https://") && schemeURI.present? ? normalize_id(schemeURI + affiliation_identifier) : normalize_id(affiliation_identifier) # The normalize_id(affiliation_identifier) method currently discards affiliation identifiers that don't start with a URL, # for example: affiliation_identifier = "05bp8ka05". # To address this issue, we are introducing the following change to handle such affiliation identifiers. # when `normalize_id` method could not normalize, it returns nil, hence we have following condition if affiliation_identifier.nil? if a["affiliationIdentifierScheme"] == "ROR" affiliation_identifier = normalize_ror(a["affiliationIdentifier"]) else affiliation_identifier = a["affiliationIdentifier"] end end end name = a["__content__"].to_s.squish.presence affiliation_identifier_scheme = a["affiliationIdentifierScheme"] end { "name" => name, "affiliationIdentifier" => affiliation_identifier, "affiliationIdentifierScheme" => affiliation_identifier_scheme, "schemeUri" => scheme_uri }.compact end.presence end |
#get_authors(authors) ⇒ Object
parse array of author strings into CSL format
83 84 85 |
# File 'lib/bolognese/author_utils.rb', line 83 def () Array.wrap().map { || () }.compact end |
#get_one_author(author) ⇒ Object
12 13 14 15 16 17 18 19 20 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 47 48 49 50 51 52 53 54 55 |
# File 'lib/bolognese/author_utils.rb', line 12 def () # author is a string = { "creatorName" => } if .is_a?(String) # malformed XML return nil if .fetch("creatorName", nil).is_a?(Array) name = parse_attributes(.fetch("creatorName", nil)) || parse_attributes(.fetch("contributorName", nil)) given_name = parse_attributes(.fetch("givenName", nil)) family_name = parse_attributes(.fetch("familyName", nil)) name = (name) contributor_type = parse_attributes(.fetch("contributorType", nil)) name_type = parse_attributes(.fetch("creatorName", nil), content: "nameType", first: true) || parse_attributes(.fetch("contributorName", nil), content: "nameType", first: true) name_identifiers = Array.wrap(.fetch("nameIdentifier", nil)).map do |ni| name_identifier = ni["__content__"].strip if ni["__content__"].present? if ni["nameIdentifierScheme"] == "ORCID" { "nameIdentifier" => normalize_orcid(name_identifier), "schemeUri" => "https://orcid.org", "nameIdentifierScheme" => "ORCID" }.compact elsif ni["nameIdentifierScheme"] == "ROR" { "nameIdentifier" => normalize_ror(name_identifier), "schemeUri" => "https://ror.org", "nameIdentifierScheme" => "ROR" }.compact else { "nameIdentifier" => name_identifier, "schemeUri" => ni.fetch("schemeURI", nil), "nameIdentifierScheme" => ni["nameIdentifierScheme"] }.compact end end.presence { "nameType" => name_type, "name" => name, "givenName" => given_name, "familyName" => family_name, "nameIdentifiers" => name_identifiers, "affiliation" => get_affiliations(.fetch("affiliation", nil)), "contributorType" => contributor_type }.compact end |
#is_personal_name?(author) ⇒ Boolean
65 66 67 68 69 70 71 72 73 |
# File 'lib/bolognese/author_utils.rb', line 65 def is_personal_name?() return false if .fetch("nameType", nil) == "Organizational" return true if Array.wrap(.fetch("nameIdentifiers", nil)).find { |a| a["nameIdentifierScheme"] == "ORCID" }.present? || .fetch("familyName", "").present? || (.fetch("name", "").include?(",") && .fetch("name", "").exclude?(";")) || name_exists?(.fetch("name", "").split(" ").first) false end |
#name_exists?(name) ⇒ Boolean
recognize given name if we have loaded ::NameDetector data, e.g. in a Rails initializer
76 77 78 79 80 |
# File 'lib/bolognese/author_utils.rb', line 76 def name_exists?(name) return false unless name_detector.present? name_detector.name_exists?(name) end |