research_metadata_announcement 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/research_metadata_announcement.rb +1 -0
- data/lib/research_metadata_announcement/transformer/base.rb +162 -3
- data/lib/research_metadata_announcement/transformer/dataset.rb +2 -195
- data/lib/research_metadata_announcement/transformer/publication.rb +29 -0
- data/lib/research_metadata_announcement/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2474614693454017d76644d6a463da347253fa8c
|
4
|
+
data.tar.gz: 7fe0aba78ef40f5bc3db8c2b5a2f406ec2db7ab5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 247bdcac312ab4ef37ede3db3f83bccb05fa00424ddcb92cca51d51fb09cd1b7fb46ed987c81e153822ca1ed3161f60732dcb79280fbfd5fdc32e29362af5a31
|
7
|
+
data.tar.gz: ff3e0ab75eeb45c2cb744476f0cc5953c723d116a1cbd68dee4ecc690eee3a9d371927d01ac9627ae9f929848a4acdc560a7dc281155e95ae9e434c9f30164c1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,7 @@ require 'puree'
|
|
2
2
|
|
3
3
|
require 'research_metadata_announcement/transformer/base'
|
4
4
|
require 'research_metadata_announcement/transformer/dataset'
|
5
|
+
require 'research_metadata_announcement/transformer/publication'
|
5
6
|
require 'research_metadata_announcement/version'
|
6
7
|
|
7
8
|
# Metadata extraction from the Pure Research Information System and
|
@@ -26,12 +26,67 @@ module ResearchMetadataAnnouncement
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
# Title followed by uri format
|
30
|
+
#
|
31
|
+
# @param max_length [Fixnum]
|
32
|
+
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
33
|
+
def title_uri(max_length: nil)
|
34
|
+
title_formats format: :title_uri_format,
|
35
|
+
max_length: max_length
|
36
|
+
end
|
37
|
+
|
38
|
+
# Uri followed by title format
|
39
|
+
#
|
40
|
+
# @see #title_uri
|
41
|
+
def uri_title(max_length: nil)
|
42
|
+
title_formats format: :uri_title_format,
|
43
|
+
max_length: max_length
|
44
|
+
end
|
45
|
+
|
46
|
+
# Keywords followed by uri format
|
47
|
+
#
|
48
|
+
# @param max_length [Fixnum] Maximum length of announcement.
|
49
|
+
# @param max_descriptors [Fixnum] Maximum number of descriptors (common name for keywords, tags, hashtags).
|
50
|
+
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
51
|
+
def keywords_uri(max_length: nil, max_descriptors: 2)
|
52
|
+
descriptors_formats format: :keywords_uri_format,
|
53
|
+
max_length: max_length,
|
54
|
+
max_descriptors: max_descriptors
|
55
|
+
end
|
56
|
+
|
57
|
+
# Uri followed by keywords format
|
58
|
+
#
|
59
|
+
# @see #keywords_uri
|
60
|
+
def uri_keywords(max_length: nil, max_descriptors: 2)
|
61
|
+
descriptors_formats format: :uri_keywords_format,
|
62
|
+
max_length: max_length,
|
63
|
+
max_descriptors: max_descriptors
|
64
|
+
end
|
65
|
+
|
66
|
+
# Hashtags followed by uri format
|
67
|
+
#
|
68
|
+
# @see #keywords_uri
|
69
|
+
def hashtags_uri(max_length: nil, max_descriptors: 2)
|
70
|
+
descriptors_formats format: :hashtags_uri_format,
|
71
|
+
max_length: max_length,
|
72
|
+
max_descriptors: max_descriptors
|
73
|
+
end
|
74
|
+
|
75
|
+
# Uri followed by hashtags format
|
76
|
+
#
|
77
|
+
# @see #keywords_uri
|
78
|
+
def uri_hashtags(max_length: nil, max_descriptors: 2)
|
79
|
+
descriptors_formats format: :uri_hashtags_format,
|
80
|
+
max_length: max_length,
|
81
|
+
max_descriptors: max_descriptors
|
82
|
+
end
|
83
|
+
|
29
84
|
private
|
30
85
|
|
31
86
|
def append_sentence(str, str_to_append)
|
32
|
-
if str_to_append && str_to_append.
|
87
|
+
if str_to_append && !str_to_append.empty?
|
33
88
|
if str
|
34
|
-
if str.
|
89
|
+
if !str.empty?
|
35
90
|
"#{str}. #{str_to_append}."
|
36
91
|
else
|
37
92
|
"#{str_to_append}."
|
@@ -43,13 +98,117 @@ module ResearchMetadataAnnouncement
|
|
43
98
|
end
|
44
99
|
|
45
100
|
def strip_uri_scheme(uri)
|
46
|
-
uri.sub
|
101
|
+
uri.sub %r{^.+//}, ''
|
47
102
|
end
|
48
103
|
|
49
104
|
def length_constrained?(max_length)
|
50
105
|
max_length && max_length > 0
|
51
106
|
end
|
52
107
|
|
108
|
+
def title_formats(format:, max_length:)
|
109
|
+
return nil unless @resource
|
110
|
+
uri = prepare_uri
|
111
|
+
return nil unless uri
|
112
|
+
title = @resource.title
|
113
|
+
build_title_formats(format: format,
|
114
|
+
uri: uri,
|
115
|
+
title: title,
|
116
|
+
max_length: max_length)
|
117
|
+
end
|
118
|
+
|
119
|
+
def descriptors_formats(format:, max_length:, max_descriptors:)
|
120
|
+
return nil unless @resource
|
121
|
+
uri = prepare_uri
|
122
|
+
return nil unless uri
|
123
|
+
keywords = @resource.keywords
|
124
|
+
return nil if keywords.empty?
|
125
|
+
build_descriptors_formats(format: format,
|
126
|
+
keywords: keywords,
|
127
|
+
uri: uri,
|
128
|
+
max_length: max_length,
|
129
|
+
max_descriptors: max_descriptors)
|
130
|
+
end
|
131
|
+
|
132
|
+
def validate_string_length(str, max_length)
|
133
|
+
if length_constrained? max_length
|
134
|
+
str if str.size <= max_length
|
135
|
+
else
|
136
|
+
str
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def build_descriptors_formats(format:, keywords:, uri:, max_length:, max_descriptors:)
|
141
|
+
case format
|
142
|
+
when :keywords_uri_format
|
143
|
+
str = append_sentence(build_keywords(keywords, max_descriptors), uri)
|
144
|
+
when :uri_keywords_format
|
145
|
+
str = append_sentence(uri, build_keywords(keywords, max_descriptors))
|
146
|
+
when :hashtags_uri_format
|
147
|
+
str = append_sentence(build_hashtags(keywords, max_descriptors), uri)
|
148
|
+
when :uri_hashtags_format
|
149
|
+
str = append_sentence(uri, build_hashtags(keywords, max_descriptors))
|
150
|
+
end
|
151
|
+
validate_string_length str, max_length
|
152
|
+
end
|
153
|
+
|
154
|
+
def build_title_format(format:, title:, uri:)
|
155
|
+
case format
|
156
|
+
when :title_uri_format
|
157
|
+
append_sentence title, uri
|
158
|
+
when :uri_title_format
|
159
|
+
append_sentence uri, title
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def build_title_format_truncated(format:, title:, uri:, available_chars:)
|
164
|
+
truncated_title = title[0..available_chars-3].strip + '...'
|
165
|
+
case format
|
166
|
+
when :title_uri_format
|
167
|
+
"#{truncated_title} #{uri}."
|
168
|
+
when :uri_title_format
|
169
|
+
"#{uri}. #{truncated_title}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def build_title_formats(format:, title:, uri:, max_length:)
|
174
|
+
if length_constrained? max_length
|
175
|
+
available_chars = max_length - (uri.size + 3)
|
176
|
+
available_chars = 0 if available_chars < 0
|
177
|
+
if title.size <= available_chars
|
178
|
+
return build_title_format(format: format,
|
179
|
+
title: title,
|
180
|
+
uri: uri)
|
181
|
+
end
|
182
|
+
if available_chars - 3 > 0
|
183
|
+
return build_title_format_truncated(format: format,
|
184
|
+
title: title,
|
185
|
+
uri: uri,
|
186
|
+
available_chars: available_chars)
|
187
|
+
end
|
188
|
+
else
|
189
|
+
build_title_format(format: format,
|
190
|
+
title: title,
|
191
|
+
uri: uri)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def build_keywords(keywords, max)
|
196
|
+
keywords[0..max - 1].join ', '
|
197
|
+
end
|
198
|
+
|
199
|
+
def build_hashtags(keywords, max)
|
200
|
+
a = keywords[0..max - 1].map(&:downcase)
|
201
|
+
a = a.map { |i| i.gsub(/[^a-zA-Z0-9]/, '') }
|
202
|
+
a = a.map { |i| i.gsub(/\s+/, '') }
|
203
|
+
a = a.map { |i| "##{i}" }
|
204
|
+
a.join ' '
|
205
|
+
end
|
206
|
+
|
207
|
+
def make_extractor(resource_type)
|
208
|
+
resource_class = "Puree::Extractor::#{resource_type.capitalize}"
|
209
|
+
@resource_extractor = Object.const_get(resource_class).new @config
|
210
|
+
end
|
211
|
+
|
53
212
|
end
|
54
213
|
end
|
55
214
|
|
@@ -13,206 +13,13 @@ module ResearchMetadataAnnouncement
|
|
13
13
|
# @option config [String] :password The password of the Pure host account.
|
14
14
|
def initialize(config)
|
15
15
|
super
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
# Keywords followed by uri format
|
20
|
-
#
|
21
|
-
# @param max_length [Fixnum] Maximum length of announcement.
|
22
|
-
# @param max_descriptors [Fixnum] Maximum number of descriptors (common name for keywords, tags, hashtags).
|
23
|
-
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
24
|
-
def keywords_uri(max_length: nil, max_descriptors: 2)
|
25
|
-
return nil if !@resource
|
26
|
-
keywords = @resource.keywords
|
27
|
-
uri = prepare_uri
|
28
|
-
if uri
|
29
|
-
return build_keywords_uri(keywords: keywords,
|
30
|
-
uri: uri,
|
31
|
-
max_length: max_length,
|
32
|
-
max_descriptors: max_descriptors)
|
33
|
-
end
|
34
|
-
nil
|
35
|
-
end
|
36
|
-
|
37
|
-
# Uri followed by keywords format
|
38
|
-
#
|
39
|
-
# @see #keywords_uri
|
40
|
-
def uri_keywords(max_length: nil, max_descriptors: 2)
|
41
|
-
return nil if !@resource
|
42
|
-
keywords = @resource.keywords
|
43
|
-
uri = prepare_uri
|
44
|
-
if uri
|
45
|
-
return build_uri_keywords(keywords: keywords,
|
46
|
-
uri: uri,
|
47
|
-
max_length: max_length,
|
48
|
-
max_descriptors: max_descriptors)
|
49
|
-
end
|
50
|
-
nil
|
51
|
-
end
|
52
|
-
|
53
|
-
# Uri followed by hashtags format
|
54
|
-
#
|
55
|
-
# @see #keywords_uri
|
56
|
-
def uri_hashtags(max_length: nil, max_descriptors: 2)
|
57
|
-
return nil if !@resource
|
58
|
-
keywords = @resource.keywords
|
59
|
-
uri = prepare_uri
|
60
|
-
if uri
|
61
|
-
return build_uri_hashtags(keywords: keywords,
|
62
|
-
uri: uri,
|
63
|
-
max_length: max_length,
|
64
|
-
max_descriptors: max_descriptors)
|
65
|
-
end
|
66
|
-
nil
|
67
|
-
end
|
68
|
-
|
69
|
-
# Hashtags followed by uri format
|
70
|
-
#
|
71
|
-
# @see #keywords_uri
|
72
|
-
def hashtags_uri(max_length: nil, max_descriptors: 2)
|
73
|
-
return nil if !@resource
|
74
|
-
keywords = @resource.keywords
|
75
|
-
uri = prepare_uri
|
76
|
-
if uri
|
77
|
-
return build_hashtags_uri(keywords: keywords,
|
78
|
-
uri: uri,
|
79
|
-
max_length: max_length,
|
80
|
-
max_descriptors: max_descriptors)
|
81
|
-
end
|
82
|
-
nil
|
83
|
-
end
|
84
|
-
|
85
|
-
# Title followed by uri format
|
86
|
-
#
|
87
|
-
# @param max_length [Fixnum]
|
88
|
-
# @return [String, nil] Announcement returned if the metadata is available and the announcement length does not exceed the max_length argument.
|
89
|
-
def title_uri(max_length: nil)
|
90
|
-
return nil if !@resource
|
91
|
-
title = @resource.title
|
92
|
-
uri = prepare_uri
|
93
|
-
if uri
|
94
|
-
return build_title_uri(uri: uri, title: title, max_length: max_length)
|
95
|
-
end
|
96
|
-
nil
|
97
|
-
end
|
98
|
-
|
99
|
-
# Uri followed by title format
|
100
|
-
#
|
101
|
-
# @see #title_uri
|
102
|
-
def uri_title(max_length: nil)
|
103
|
-
return nil if !@resource
|
104
|
-
title = @resource.title
|
105
|
-
uri = prepare_uri
|
106
|
-
if uri
|
107
|
-
return build_uri_title(uri: uri, title: title, max_length: max_length)
|
108
|
-
end
|
109
|
-
nil
|
16
|
+
make_extractor :dataset
|
110
17
|
end
|
111
18
|
|
112
19
|
private
|
113
20
|
|
114
21
|
def prepare_uri
|
115
|
-
if @resource && @resource.doi
|
116
|
-
return strip_uri_scheme @resource.doi
|
117
|
-
end
|
118
|
-
nil
|
119
|
-
end
|
120
|
-
|
121
|
-
def build_keywords_uri(keywords:, uri:, max_length:, max_descriptors:)
|
122
|
-
if !keywords.empty?
|
123
|
-
str = append_sentence(build_keywords(keywords, max_descriptors), uri)
|
124
|
-
if length_constrained? max_length
|
125
|
-
return str if str.size <= max_length
|
126
|
-
else
|
127
|
-
return str
|
128
|
-
end
|
129
|
-
end
|
130
|
-
nil
|
131
|
-
end
|
132
|
-
|
133
|
-
def build_uri_keywords(keywords:, uri:, max_length:, max_descriptors:)
|
134
|
-
if !keywords.empty?
|
135
|
-
str = append_sentence(uri, build_keywords(keywords, max_descriptors))
|
136
|
-
if length_constrained? max_length
|
137
|
-
return str if str.size <= max_length
|
138
|
-
else
|
139
|
-
return str
|
140
|
-
end
|
141
|
-
end
|
142
|
-
nil
|
143
|
-
end
|
144
|
-
|
145
|
-
def build_uri_hashtags(keywords:, uri:, max_length:, max_descriptors:)
|
146
|
-
if !keywords.empty?
|
147
|
-
str = append_sentence(uri, build_hashtags(keywords, max_descriptors))
|
148
|
-
if length_constrained? max_length
|
149
|
-
return str if str.size <= max_length
|
150
|
-
else
|
151
|
-
return str
|
152
|
-
end
|
153
|
-
end
|
154
|
-
nil
|
155
|
-
end
|
156
|
-
|
157
|
-
def build_hashtags_uri(keywords:, uri:, max_length:, max_descriptors:)
|
158
|
-
if !keywords.empty?
|
159
|
-
str = append_sentence(build_hashtags(keywords, max_descriptors), uri)
|
160
|
-
if length_constrained? max_length
|
161
|
-
return str if str.size <= max_length
|
162
|
-
else
|
163
|
-
return str
|
164
|
-
end
|
165
|
-
end
|
166
|
-
nil
|
167
|
-
end
|
168
|
-
|
169
|
-
def build_title_uri(title:, uri:, max_length:)
|
170
|
-
if length_constrained? max_length
|
171
|
-
available_chars = max_length - (uri.size + 3)
|
172
|
-
available_chars = 0 if available_chars < 0
|
173
|
-
if title.size <= available_chars
|
174
|
-
return append_sentence title, uri
|
175
|
-
end
|
176
|
-
if available_chars-3 > 0
|
177
|
-
truncated_title = title[0..available_chars-3].strip + '...'
|
178
|
-
return "#{truncated_title} #{uri}."
|
179
|
-
end
|
180
|
-
else
|
181
|
-
return append_sentence title, uri
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
def build_uri_title(uri:, title:, max_length:)
|
186
|
-
if length_constrained? max_length
|
187
|
-
available_chars = max_length - (uri.size + 3)
|
188
|
-
available_chars = 0 if available_chars < 0
|
189
|
-
if title.size <= available_chars
|
190
|
-
return append_sentence uri, title
|
191
|
-
end
|
192
|
-
if available_chars-3 > 0
|
193
|
-
truncated_title = title[0..available_chars-3].strip + '...'
|
194
|
-
return "#{uri}. #{truncated_title}"
|
195
|
-
end
|
196
|
-
else
|
197
|
-
return append_sentence uri, title
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def build_keywords(keywords, max)
|
202
|
-
return keywords[0..max-1].join ', ' if keywords
|
203
|
-
nil
|
204
|
-
end
|
205
|
-
|
206
|
-
def build_hashtags(keywords, max)
|
207
|
-
a = keywords[0..max-1].map { |i| i.downcase }
|
208
|
-
a = a.map { |i| i.gsub(/[^a-zA-Z0-9]/,'') }
|
209
|
-
a = a.map { |i| i.gsub(/\s+/, '') }
|
210
|
-
a = a.map { |i| "##{i}" }
|
211
|
-
if a.size > 0
|
212
|
-
return a.join ' '
|
213
|
-
else
|
214
|
-
return nil
|
215
|
-
end
|
22
|
+
strip_uri_scheme @resource.doi if @resource && @resource.doi
|
216
23
|
end
|
217
24
|
|
218
25
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ResearchMetadataAnnouncement
|
2
|
+
|
3
|
+
module Transformer
|
4
|
+
|
5
|
+
# Extracts publication metadata from the Pure Research Information System and
|
6
|
+
# converts it into an announcement
|
7
|
+
#
|
8
|
+
class Publication < ResearchMetadataAnnouncement::Transformer::Base
|
9
|
+
|
10
|
+
# @param config [Hash]
|
11
|
+
# @option config [String] :url The URL of the Pure host.
|
12
|
+
# @option config [String] :username The username of the Pure host account.
|
13
|
+
# @option config [String] :password The password of the Pure host account.
|
14
|
+
def initialize(config)
|
15
|
+
super
|
16
|
+
make_extractor :publication
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def prepare_uri
|
22
|
+
strip_uri_scheme @resource.dois[0] if @resource && @resource.dois[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: research_metadata_announcement
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Albin-Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puree
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/research_metadata_announcement.rb
|
54
54
|
- lib/research_metadata_announcement/transformer/base.rb
|
55
55
|
- lib/research_metadata_announcement/transformer/dataset.rb
|
56
|
+
- lib/research_metadata_announcement/transformer/publication.rb
|
56
57
|
- lib/research_metadata_announcement/transformer/transformer.rb
|
57
58
|
- lib/research_metadata_announcement/version.rb
|
58
59
|
- research_metadata_announcement.gemspec
|