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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/briard/readers/codemeta_reader.rb', line 16
def read_codemeta(string: nil, **options)
if string.present?
errors = jsonlint(string)
return { 'errors' => errors } if errors.present?
end
read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
:sandbox, :validate, :ra))
meta = string.present? ? Maremma.from_json(string) : {}
identifiers = Array.wrap(meta.fetch('identifier', nil)).map do |r|
r = normalize_id(r) if r.is_a?(String)
if r.is_a?(String) && URI(r) != 'doi.org'
{ 'identifierType' => 'URL', 'identifier' => r }
elsif r.is_a?(Hash)
{ 'identifierType' => get_identifier_type(r['propertyID']), 'identifier' => r['value'] }
end
end.compact.uniq
id = normalize_id(options[:doi] || meta.fetch('@id', nil) || meta.fetch('identifier', nil))
has_agents = meta.fetch('agents', nil)
authors = has_agents.nil? ? meta.fetch('authors', nil) : has_agents
creators = get_authors(from_schema_org_creators(Array.wrap(authors)))
contributors = get_authors(from_schema_org_contributors(Array.wrap(meta.fetch('editor',
nil))))
dates = []
dates << { 'date' => meta.fetch('datePublished'), 'dateType' => 'Issued' } if meta.fetch(
'datePublished', nil
).present?
dates << { 'date' => meta.fetch('dateCreated'), 'dateType' => 'Created' } if meta.fetch(
'dateCreated', nil
).present?
dates << { 'date' => meta.fetch('dateModified'), 'dateType' => 'Updated' } if meta.fetch(
'dateModified', nil
).present?
publication_year = meta.fetch('datePublished')[0..3] if meta.fetch('datePublished',
nil).present?
publisher = meta.fetch('publisher', nil)
state = meta.present? || read_options.present? ? 'findable' : 'not_found'
schema_org = meta.fetch('@type', nil)
types = {
'resourceTypeGeneral' => Briard::Utils::SO_TO_DC_TRANSLATIONS[schema_org],
'resourceType' => meta.fetch('additionalType', nil),
'schemaOrg' => schema_org,
'citeproc' => Briard::Utils::SO_TO_CP_TRANSLATIONS[schema_org] || 'article-journal',
'bibtex' => Briard::Utils::SO_TO_BIB_TRANSLATIONS[schema_org] || 'misc',
'ris' => Briard::Utils::SO_TO_RIS_TRANSLATIONS[schema_org] || 'GEN'
}.compact
subjects = Array.wrap(meta.fetch('tags', nil)).reduce([]) do |sum, subject|
sum += name_to_fos(subject)
sum
end
has_title = meta.fetch('title', nil)
titles = if has_title.nil?
[{ 'title' => meta.fetch('name', nil) }]
else
[{ 'title' => has_title }]
end
rights_list = if meta.fetch('licenseId', nil).present?
[hsh_to_spdx('rightsIdentifier' => meta.fetch('licenseId'))]
end
{ 'id' => id,
'types' => types,
'identifiers' => identifiers,
'doi' => doi_from_url(id),
'url' => normalize_id(meta.fetch('codeRepository', nil)),
'titles' => titles,
'creators' => creators,
'contributors' => contributors,
'publisher' => publisher,
'dates' => dates,
'publication_year' => publication_year,
'descriptions' => if meta.fetch('description', nil).present?
[{ 'description' => sanitize(meta.fetch('description')),
'descriptionType' => 'Abstract' }]
end,
'rights_list' => rights_list,
'version_info' => meta.fetch('version', nil),
'subjects' => subjects,
'state' => state }.merge(read_options)
end
|