briard 2.4.1 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +72 -0
- data/.github/workflows/rubocop.yml +50 -0
- data/.rubocop.yml +144 -620
- data/.rubocop_todo.yml +76 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +43 -6
- data/Rakefile +1 -1
- data/{bolognese.gemspec → briard.gemspec} +46 -38
- data/lib/briard/array.rb +2 -2
- data/lib/briard/author_utils.rb +79 -71
- data/lib/briard/cli.rb +12 -13
- data/lib/briard/crossref_utils.rb +73 -61
- data/lib/briard/datacite_utils.rb +132 -106
- data/lib/briard/doi_utils.rb +10 -10
- data/lib/briard/metadata.rb +96 -106
- data/lib/briard/metadata_utils.rb +87 -78
- data/lib/briard/readers/bibtex_reader.rb +65 -65
- data/lib/briard/readers/cff_reader.rb +88 -70
- data/lib/briard/readers/citeproc_reader.rb +90 -84
- data/lib/briard/readers/codemeta_reader.rb +68 -50
- data/lib/briard/readers/crosscite_reader.rb +2 -2
- data/lib/briard/readers/crossref_reader.rb +249 -210
- data/lib/briard/readers/datacite_json_reader.rb +3 -3
- data/lib/briard/readers/datacite_reader.rb +225 -189
- data/lib/briard/readers/npm_reader.rb +49 -42
- data/lib/briard/readers/ris_reader.rb +82 -80
- data/lib/briard/readers/schema_org_reader.rb +182 -159
- data/lib/briard/string.rb +1 -1
- data/lib/briard/utils.rb +4 -4
- data/lib/briard/version.rb +3 -1
- data/lib/briard/whitelist_scrubber.rb +11 -4
- data/lib/briard/writers/bibtex_writer.rb +14 -8
- data/lib/briard/writers/cff_writer.rb +33 -26
- data/lib/briard/writers/codemeta_writer.rb +19 -15
- data/lib/briard/writers/csv_writer.rb +6 -4
- data/lib/briard/writers/datacite_json_writer.rb +8 -2
- data/lib/briard/writers/jats_writer.rb +33 -28
- data/lib/briard/writers/rdf_xml_writer.rb +1 -1
- data/lib/briard/writers/ris_writer.rb +30 -18
- data/lib/briard/writers/turtle_writer.rb +1 -1
- data/lib/briard.rb +6 -6
- data/rubocop.sarif +0 -0
- data/spec/array_spec.rb +5 -5
- data/spec/author_utils_spec.rb +151 -132
- data/spec/datacite_utils_spec.rb +135 -83
- data/spec/doi_utils_spec.rb +168 -164
- data/spec/find_from_format_spec.rb +69 -69
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/onlies_keep_specific_tags.yml +65 -0
- data/spec/fixtures/vcr_cassettes/Briard_Metadata/sanitize/removes_a_tags.yml +65 -0
- data/spec/metadata_spec.rb +91 -90
- data/spec/readers/bibtex_reader_spec.rb +43 -38
- data/spec/readers/cff_reader_spec.rb +165 -153
- data/spec/readers/citeproc_reader_spec.rb +45 -40
- data/spec/readers/codemeta_reader_spec.rb +128 -115
- data/spec/readers/crosscite_reader_spec.rb +34 -24
- data/spec/readers/crossref_reader_spec.rb +1098 -939
- data/spec/readers/datacite_json_reader_spec.rb +53 -40
- data/spec/readers/datacite_reader_spec.rb +1541 -1337
- data/spec/readers/npm_reader_spec.rb +48 -43
- data/spec/readers/ris_reader_spec.rb +53 -47
- data/spec/readers/schema_org_reader_spec.rb +329 -267
- data/spec/spec_helper.rb +6 -5
- data/spec/utils_spec.rb +371 -347
- data/spec/writers/bibtex_writer_spec.rb +143 -143
- data/spec/writers/cff_writer_spec.rb +96 -90
- data/spec/writers/citation_writer_spec.rb +34 -33
- data/spec/writers/citeproc_writer_spec.rb +226 -224
- data/spec/writers/codemeta_writer_spec.rb +18 -16
- data/spec/writers/crosscite_writer_spec.rb +91 -73
- data/spec/writers/crossref_writer_spec.rb +99 -91
- data/spec/writers/csv_writer_spec.rb +70 -70
- data/spec/writers/datacite_json_writer_spec.rb +78 -68
- data/spec/writers/datacite_writer_spec.rb +417 -322
- data/spec/writers/jats_writer_spec.rb +177 -161
- data/spec/writers/rdf_xml_writer_spec.rb +68 -63
- data/spec/writers/ris_writer_spec.rb +162 -162
- data/spec/writers/turtle_writer_spec.rb +47 -47
- metadata +250 -160
- data/.github/workflows/release.yml +0 -47
@@ -3,85 +3,103 @@
|
|
3
3
|
module Briard
|
4
4
|
module Readers
|
5
5
|
module CodemetaReader
|
6
|
-
def get_codemeta(id: nil, **
|
7
|
-
return {
|
6
|
+
def get_codemeta(id: nil, **_options)
|
7
|
+
return { 'string' => nil, 'state' => 'not_found' } unless id.present?
|
8
|
+
|
8
9
|
id = normalize_id(id)
|
9
|
-
response = Maremma.get(github_as_codemeta_url(id), accept:
|
10
|
-
string = response.body.fetch(
|
10
|
+
response = Maremma.get(github_as_codemeta_url(id), accept: 'json', raw: true)
|
11
|
+
string = response.body.fetch('data', nil)
|
11
12
|
|
12
|
-
{
|
13
|
+
{ 'string' => string }
|
13
14
|
end
|
14
15
|
|
15
16
|
def read_codemeta(string: nil, **options)
|
16
17
|
if string.present?
|
17
18
|
errors = jsonlint(string)
|
18
|
-
return {
|
19
|
+
return { 'errors' => errors } if errors.present?
|
19
20
|
end
|
20
21
|
|
21
|
-
read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
|
22
|
+
read_options = ActiveSupport::HashWithIndifferentAccess.new(options.except(:doi, :id, :url,
|
23
|
+
:sandbox, :validate, :ra))
|
22
24
|
|
23
25
|
meta = string.present? ? Maremma.from_json(string) : {}
|
24
26
|
|
25
|
-
identifiers = Array.wrap(meta.fetch(
|
27
|
+
identifiers = Array.wrap(meta.fetch('identifier', nil)).map do |r|
|
26
28
|
r = normalize_id(r) if r.is_a?(String)
|
27
|
-
if r.is_a?(String) &&
|
28
|
-
|
29
|
+
if r.is_a?(String) && URI(r) != 'doi.org'
|
30
|
+
{ 'identifierType' => 'URL', 'identifier' => r }
|
29
31
|
elsif r.is_a?(Hash)
|
30
|
-
{
|
32
|
+
{ 'identifierType' => get_identifier_type(r['propertyID']), 'identifier' => r['value'] }
|
31
33
|
end
|
32
34
|
end.compact.uniq
|
33
35
|
|
34
|
-
id = normalize_id(options[:doi] || meta.fetch(
|
36
|
+
id = normalize_id(options[:doi] || meta.fetch('@id', nil) || meta.fetch('identifier', nil))
|
35
37
|
|
36
|
-
has_agents = meta.fetch(
|
37
|
-
authors = has_agents.nil? ? meta.fetch(
|
38
|
+
has_agents = meta.fetch('agents', nil)
|
39
|
+
authors = has_agents.nil? ? meta.fetch('authors', nil) : has_agents
|
38
40
|
creators = get_authors(from_schema_org_creators(Array.wrap(authors)))
|
39
41
|
|
40
|
-
contributors = get_authors(from_schema_org_contributors(Array.wrap(meta.fetch(
|
42
|
+
contributors = get_authors(from_schema_org_contributors(Array.wrap(meta.fetch('editor',
|
43
|
+
nil))))
|
41
44
|
dates = []
|
42
|
-
dates << {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
dates << { 'date' => meta.fetch('datePublished'), 'dateType' => 'Issued' } if meta.fetch(
|
46
|
+
'datePublished', nil
|
47
|
+
).present?
|
48
|
+
dates << { 'date' => meta.fetch('dateCreated'), 'dateType' => 'Created' } if meta.fetch(
|
49
|
+
'dateCreated', nil
|
50
|
+
).present?
|
51
|
+
dates << { 'date' => meta.fetch('dateModified'), 'dateType' => 'Updated' } if meta.fetch(
|
52
|
+
'dateModified', nil
|
53
|
+
).present?
|
54
|
+
publication_year = meta.fetch('datePublished')[0..3] if meta.fetch('datePublished',
|
55
|
+
nil).present?
|
56
|
+
publisher = meta.fetch('publisher', nil)
|
57
|
+
state = meta.present? || read_options.present? ? 'findable' : 'not_found'
|
58
|
+
schema_org = meta.fetch('@type', nil)
|
49
59
|
types = {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
60
|
+
'resourceTypeGeneral' => Briard::Utils::SO_TO_DC_TRANSLATIONS[schema_org],
|
61
|
+
'resourceType' => meta.fetch('additionalType', nil),
|
62
|
+
'schemaOrg' => schema_org,
|
63
|
+
'citeproc' => Briard::Utils::SO_TO_CP_TRANSLATIONS[schema_org] || 'article-journal',
|
64
|
+
'bibtex' => Briard::Utils::SO_TO_BIB_TRANSLATIONS[schema_org] || 'misc',
|
65
|
+
'ris' => Briard::Utils::SO_TO_RIS_TRANSLATIONS[schema_org] || 'GEN'
|
56
66
|
}.compact
|
57
|
-
subjects = Array.wrap(meta.fetch(
|
67
|
+
subjects = Array.wrap(meta.fetch('tags', nil)).reduce([]) do |sum, subject|
|
58
68
|
sum += name_to_fos(subject)
|
59
69
|
|
60
70
|
sum
|
61
71
|
end
|
62
72
|
|
63
|
-
has_title = meta.fetch(
|
64
|
-
titles = has_title.nil?
|
65
|
-
|
73
|
+
has_title = meta.fetch('title', nil)
|
74
|
+
titles = if has_title.nil?
|
75
|
+
[{ 'title' => meta.fetch('name', nil) }]
|
76
|
+
else
|
77
|
+
[{ 'title' => has_title }]
|
78
|
+
end
|
79
|
+
rights_list = if meta.fetch('licenseId', nil).present?
|
80
|
+
[hsh_to_spdx('rightsIdentifier' => meta.fetch('licenseId'))]
|
81
|
+
end
|
66
82
|
|
67
|
-
{
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
#{}"is_part_of" => is_part_of,
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
{ 'id' => id,
|
84
|
+
'types' => types,
|
85
|
+
'identifiers' => identifiers,
|
86
|
+
'doi' => doi_from_url(id),
|
87
|
+
'url' => normalize_id(meta.fetch('codeRepository', nil)),
|
88
|
+
'titles' => titles,
|
89
|
+
'creators' => creators,
|
90
|
+
'contributors' => contributors,
|
91
|
+
'publisher' => publisher,
|
92
|
+
# {}"is_part_of" => is_part_of,
|
93
|
+
'dates' => dates,
|
94
|
+
'publication_year' => publication_year,
|
95
|
+
'descriptions' => if meta.fetch('description', nil).present?
|
96
|
+
[{ 'description' => sanitize(meta.fetch('description')),
|
97
|
+
'descriptionType' => 'Abstract' }]
|
98
|
+
end,
|
99
|
+
'rights_list' => rights_list,
|
100
|
+
'version_info' => meta.fetch('version', nil),
|
101
|
+
'subjects' => subjects,
|
102
|
+
'state' => state }.merge(read_options)
|
85
103
|
end
|
86
104
|
|
87
105
|
# def related_identifiers(relation_type)
|
@@ -3,9 +3,9 @@
|
|
3
3
|
module Briard
|
4
4
|
module Readers
|
5
5
|
module CrossciteReader
|
6
|
-
def read_crosscite(string: nil, **
|
6
|
+
def read_crosscite(string: nil, **_options)
|
7
7
|
errors = jsonlint(string)
|
8
|
-
return {
|
8
|
+
return { 'errors' => errors } if errors.present?
|
9
9
|
|
10
10
|
string.present? ? Maremma.from_json(string) : {}
|
11
11
|
end
|